facebook

Display the Data from RS232 Com1 port in the console in Hex

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #322883 Reply

    arunsny
    Member

    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

    Attachments:
    You must be logged in to view attached files.
    #322933 Reply

    support-joy
    Member

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Display the Data from RS232 Com1 port in the console in Hex

You must be logged in to post in the forum log in