LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-06-2008, 03:23 PM   #1
neutron001
LQ Newbie
 
Registered: Mar 2008
Posts: 19

Rep: Reputation: 0
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!

Last edited by neutron001; 04-06-2008 at 03:43 PM.
 
Old 04-08-2008, 12:45 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Just to give it a reply:

same question in programming section
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing data from a 'foreign' database with mysql, or tools to pre-process data. linker3000 Linux - Software 1 08-14-2007 09:36 PM
Sending data to a process along an already open stream. navaburo Linux - Networking 1 03-18-2007 07:51 PM
Installation process via ttyS0 steve4586 Debian 4 12-17-2006 05:55 AM
Garbage data when communicating between ttyS0 and Hyperterm tjt Linux - Newbie 1 06-15-2004 09:50 PM
data transfer bet RH8.0 pc to & fro device thru /dev/ttyS0 shivanitha Linux - Newbie 0 10-30-2003 08:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration