Serial programming - binary data using open() and read()
Hello everyone!
I am using the old "open" function to access the serial port to try and read some incoming data. The problem is when I receive beyond the standard ascii characters, 0x80 and above, when I do a read I get 0xffff(msb)(lsb). I'm assuming that these f's are getting tacked on because I'm doing a read - and it's expecting ascii chars. How do I get around this? It goes something like this... Code:
int fd; Code:
int raw_rx_data; 2. Is there a way to use the open function with a binary flag (searched and couldn't find one)? 3. Is there a way to use the fopen function with the serial port? I don't think fopen supports the noctty / ndelay flags. Thanks! |
Yes, it's sign extension. int8 0xff == int32 0xffffff == -1 ; uint8 0xff == (u)int32 0x000000ff == 127.
Ha det. Beeneken. |
Hmmm... I don't quite understand.
If my shifting operation works for ascii values, why does it not work for non-ascii values? Could you please explain the correct way to perform this operation? Sorry, I'm still new to this bit stuff. Is simple bit shifting not enough? |
Why not raw_rx_data = *(uint16_t*) in_buffer;? Bit operators automatically promote to int when using C. Also, you might have your bytes backwards: maybe byte 1 should have been shifted? I guess it depends on the system and how you wrote the data in the first place.
ta0kira |
Non-ascii values have the high bit set, so they are negative numbers. I think declaring in_buffer as unsigned char would work.
|
Note, also, that the serial driver may trap certain character sequences (eg XON/XOFF), depending upon how you have configured the serial port. The Serial Programming Guide forPOSIX Operating Systems, and the Serial Programming Howto both provide a good bit of information on the subject.
--- rod. |
All times are GMT -5. The time now is 03:57 PM. |