LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Using open(... to process binary data over ttyS0 (https://www.linuxquestions.org/questions/linux-software-2/using-open-to-process-binary-data-over-ttys0-633489/)

neutron001 04-06-2008 02:23 PM

Using open(... to process binary data over ttyS0
 
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;

fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);

...setup async handler and serial settings..

Now.. in my signal handler
Code:

int raw_rx_data;
char in_bufer[128];

//read two bytes
read(fd, in_buffer, 2);

//convert to 16 bit integer
raw_rx_data = (in_buffer[0] << 8) | in_buffer[1];

1. Now do you think the issue is the way I'm converting the string to integer? (Note: I don't want to just mask the bits for other reasons).
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!

I realized I posted this in the wrong area.. will repost in non *nix programming. Sorry!

Wim Sturkenboom 04-07-2008 11:45 PM

Just to give it a reply:

same question in programming section


All times are GMT -5. The time now is 01:39 AM.