0

WHY BYTE ARRAY RESPONSES IS EMPTY IN LINUX SYSTEM BUT WORK IN WINDOWS?

BYTE ARRAY VARIABLE VALUES ARE ALL 0

I am facing an issue in serial comm communication. I am using Serial USB Convertor of GEARMO USB RS 485/232 Convertor. In window my program works great on com13 port. Same program its not working in linux/raspberry pi wheezy/ubuntu systems! i tries all the solutions from google checked multiple Linux system. I checked multiple readBytes(),readBytes(4),UTF-ENCODING options. i also tries multiple byte conversion functions but all the time i got zero response. Also, I thought driver might be issue in linux for my problem but connection open, sending data, usb led light blinking always works but in return response data always got NULL VALUE AS bytes.

    import jssc.SerialPort;
    import jssc.SerialPortList;
    import jssc.SerialPortEvent;
    import jssc.SerialPortEventListener;
    import jssc.SerialPortException;
    ....
    //    serialPort = new SerialPort("COM13");  // = FOR WINDOWS (work great)
    serialPort = new SerialPort("/dev/ttyUSB0");  = FOR LINUX/UBUNTU/WHEEZY (Byte data is null)
    serialPort.openPort();//Open port
    serialPort.setParams(19200, 8, 1, 2);//Set params
    serialPort.addEventListener(new SerialPortReader());//Add SerialPortEventListener
    
    public void serialEvent(SerialPortEvent event) {
        ... 
        byte buffer[] = serialPort.readBytes();
        System.out.println("Read Buffer "+  buffer);`
        for (int k = 0; k < array.length; k++) {
            System.out.println("Response[" + k + "] = " + "0x" + byteToHex(array[k]));
        ...

System.out.print output:

Read Buffer [B@58c80c 

System.out.println for loop output:

Response[0] = 0x00
Response[1] = 0x00
Response[2] = 0x00
Response[3] = 0x00
Response[4] = 0x00
Response[5] = 0x00
Response[6] = 0x00
Response[7] = 0x00
Response[8] = 0x00

 static public String byteToHex(byte b) {
  // Returns hex String representation of byte b
  char hexDigit[] = {
     '0', '1', '2', '3', '4', '5', '6', '7',
     '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
  };
  char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
  return new String(array);
}

Does anyone seen same problem ever?

Community
  • 1
  • 1
  • It might be a permissions issue. Try running as root, or add your user to the group that owns /dev/ttyUSB0, or change the rights on that folder (will be gone after a reboot). – ChristopheD May 08 '14 at 21:26
  • @christopheD i just add user to /dev/ttyUSB0 then reboot but not worked. I also tested by root but still same output. any other suggestion? – Nasir Sayed May 08 '14 at 21:54
  • Try using `strace` to see what is going on with `open()`, `read()` and other system calls. – Yirkha May 09 '14 at 14:23
  • I spoke with Gearmo Company technical department regarding issue. He suggested me to do some changes two wires as half duplex or full duplex. even i tries changing wires at all possible way but still no response received. I also asked for SERIAL2USB linux driver but technical department said there's no need of driver for linux. – Nasir Sayed May 09 '14 at 22:52

0 Answers0