When I`m sending bytes to receiver (using java), some of received byte values chaotically changing to 0x3F. (0x0 all the time changing to 0x3F)
java src:
serialPort = new SerialPort(portName);
serialPort.openPort();
serialPort.setParams(
SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE
);
serialPort.writeBytes(new byte[]{0,3,(byte)240,1,(byte)242});
When I`m using arduino for data trasmission, everything works fine.
Arduino src:
byte b[5]={0,3,240,1,242};
void setup() { Serial.begin(9600);}
void loop() {
for(int i=0;i<5;i++){
Serial.write(b[i]);
delay(5);
}
delay(1000);
}
When I'm sending data from java to arduino, all bytes also looks fine.
When I'm sending data to receiver with VB or C# also - everything is fine.
When I'm sending data byte-by-byte with Thread.sleep(5) - no success.
What I`m doing wrong?
I`m using rxtx || jssc.
Current workaround - send data to receiver throught arduino. But its slow and wierd.
UPD:
After monitoring port activity: Success packet has couple WAIT_ON_MASK functions (up,down) Then in one function IRP_MJ_READ got all packet with proper bytes.
When I`m trying to send data with my java code, there is a lot SERIAL_GET_COMMSTATUS (up/down) functions, then IRP_MJ_READ with first 3 bytes converted to 0x3F, then again WAIT_ON_MASK & COMMSTATUS, and then remaing data byte-by-byte.
P.s. Receiver is an old car bc.
0x3F
is?
in ASCII. This often indicates a character encoding problem, but since you're dealing with binary data it shouldn't be an issue. It may still be related somehow. – Kayaman0x3F
(i.e. ASCII?
) I have a hard time believing it to be just a coincidence. – KayamanThread.sleep()
? Why are you deliberately wasting time, especially when it causes a bug? – user207421