I had also faced this issue (0x0D converted to 0x0A on Linux system). On executing below commands the issue was resolved.
stty -F /dev/ttyUSB0 -onlcr
stty -F /dev/ttyUSB0 -icrnl
There is one more similar issue being encountered everytime. If the data stream contains 0x09, then 0x09 is being read more than the actual presence count.
Actual data stream:
data[0] = 0x04
data[1] = 0x80
data[2] = 0x09
data[3] = 0x01
data[4] = 0x72
data[5] = 0x13
data[6] = 0x22
Output data stream (incorrectly read):
data[0] = 0x04
data[1] = 0x80
data[2] = 0x09
data[3] = 0x09 //Incorrect data
data[4] = 0x01
data[5] = 0x72
data[6] = 0x13
data[7] = 0x22 //This data is discarded from the main data stream.
This happens only when 0x09 data is present in the data stream. 0x09 is the ASCII code of horizontal tab character.
Need experts comments for this issue. Looks like incorrectly set port attributes. Please correct me if I am wrong.
Thank you,
Pankaj
------------------------------------------------------------------------------------
Quote:
Originally Posted by esi-eric
Greetings Osvaldo!
tnew.c_iflag &= ~INLCR; /* do not translate 0x0A to 0x0D
I have inserted the above line into the serial port initialization code and it still fails! I have the
reverse problem whereas a 0x0D is translated into a 0x0A! Not a 0x0A into a 0x0D...the 0x0D is
correct and the 0x0A is incorrect!
Thank you very much! and p.s. I am still at work debugging this thing!!!!!
Where can I get a list of these control bytes like "INLCR" for my reference?
Thank you very much once again!
Eric.
------------------------------------------------------------------------------------
I have inserted the following line into the code and it works!!!!
tnew.c_iflag &= ~ICRNL; /* do not translate 0x0D to 0x0A */
Do I still need your code as well to not translate 0x0A to 0x0D????
Thank you very much once again!!!!! I think we finally got this working!!!!!
Eric.
|