MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
arunsny
Post subject: Display the Data from RS232 Com1 port in the console in Hex  PostPosted: Feb 01, 2012 - 12:29 PM
Registered Member
Registered Member


Joined: Jan 17, 2012
Posts: 8

Hallo Friends,


I have a program in which i'm trying to view the data read from the RS232 COM1 port in the console of myeclipse. I have already run the program but it is showing some rubbish values may be in ASCII as shown in the screen shot.

Can any one please help me how i can display the values in Hexadecimal or other readable format. It would be of great help.

i'm pasting my code here

package serial.comm.main;

import java.io.UnsupportedEncodingException;

import jssc.SerialPort;
import jssc.SerialPortException;
import serial.comm.port_reader.SerialPortReader;


public class SerialComm {

static SerialPort serialPort = new SerialPort("COM1");
//private static int byteCount;


/*
* Serial Read Method
*/
public static void read() {
// byte[] aa = null;
byte a = 0x01;
//aa[0]= 0x01;
//aa[1]= 0x00;
byte b[];
byte c=0x00;

try {
serialPort.openPort();//Open port
serialPort.setParams(57600, 8, 1, 0);//Set params
int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;//Prepare mask
serialPort.setEventsMask(mask);//Set mask
serialPort.addEventListener(new SerialPortReader(serialPort));//Add SerialPortEventListener
try {
Thread.sleep(5000);
//serialPort.writeBytes(aa);

b = (serialPort.readBytes(5));

for (int i=0;i < 5;i++){
c = b[i];
/*for (int i=0; i < 5;i++)
{
System.out.println("Byte" + i + " = " + b[i] + 0x30);
}
*/
System.out.println(b[i]);
}

}
catch (InterruptedException e) { }
try {
serialPort.closePort();//Close serial port
}
catch (SerialPortException ex) {
System.out.println(ex);
}
System.out.println("Reading Successful");
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}


/*
* Serial Write Method
*/
public static void write(String toPort) {
try {
serialPort.openPort();//Open serial port
serialPort.setParams(SerialPort.BAUDRATE_57600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(toPort.getBytes());//Write data to port
serialPort.closePort();//Close serial port
System.out.println("Writing Successful");
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}


/*
* Serial dataIn byte to string conversion Method
*/
public static String getString(byte[] b) throws UnsupportedEncodingException {
String result = "";
for (int i=0; i < b.length; i++) {
result += (char)b[i];
}
return result;
}

}

looking forward to hear from you.

Best regards

Arun
 
 View user's profile Send private message  
Reply with quote Back to top
support-joy
Post subject:   PostPosted: Feb 03, 2012 - 11:49 AM
Registered Member
Registered Member


Joined: Feb 03, 2009
Posts: 3442

Arun,

Have you tried to run your application in debug mode? Your issue is related to development. I would recommend you cross-post on relevant forums.

Refer - http://download.cnet.com/RS232-Hex-Com-Tool/3000-2383_4-10064973.html - I am not sure how relevant this tool is to your issue. It does say that you have a choice of non-print character display options. You could research on above lines.

_________________
Joy
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits