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?