LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-14-2006, 03:52 PM   #1
kad_79
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Rep: Reputation: 0
When to read from the serial port?


Hi all.

I am stuck porting a windows app to linux. In windows we have a waitforcommevent which keeps looking for RXCHAR event and I can use that condition to do a read on the serial port.

A similar approach in linux would be to use SIGIO interrupt and set a signal handler function to alter a global variable based on which I do a read port.

Is there a cleaner approach than this? The reason being that, I have blocked SIGIO when I am doing a "read", but while doing that I also do a IOCTL for FIONREAD, to get the number of chars in the comport. Probably this generates a SIGIO(which as told before I am blocking, till I complete "read". ), and I am getting wront character counts and my program crashes.

Well, you might say I could have blocked SIGIO after IOCTL and before 'read', but read is inside a big function and I don't want SIGIO happening when this function is going on.

Could any of you signal experts tell me what is the best approach to know that a character has arrived to be read in the serial port. I am requesting an approach very similar to what we have in windows.

Thanks
KD
 
Old 06-15-2006, 10:37 AM   #2
grumpf
Member
 
Registered: Dec 2005
Distribution: just replace windows with linux
Posts: 38

Rep: Reputation: 15
the question is 'what is your aim ?'.
there is a seriel-programming-howto explaining all stuff. what to use depends on your exact problem. seriell devices are special since they are deeply connected with terminal servers.
but this can be an advantage if you know what you want.
 
Old 06-15-2006, 02:05 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 33
This is one of the very best serial port programming guides for Linux:
http://www.easysw.com/~mike/serial/
 
Old 06-15-2006, 02:39 PM   #4
kad_79
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
grumpf:

I have clearly explained the aim. Not sure how elaborate can I get. But probably it was confusing. In any case, I meddled around a little and resolved he issue. IOCTL for FIONREAD does not raise SIGIO. I was stuck somewhere else. so no issues.

jim mcnamara:

thanks. but i used the guide earlier and its very very limited. serial comm is much much much more than what he has explained in simple terms. but for starters yes, there is nothing better than this guide. but it fails misreably in the "read" department.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to read a signal from the CTS pin of a serial port juan_de_margo Linux - Hardware 0 02-24-2005 03:36 AM
Problem with Non-blocking serial port read ZX_SA Programming 0 01-18-2005 08:50 AM
Serial Port read in shell script tjt Linux - Newbie 1 08-12-2004 09:18 AM
Serial port Read Write SeanatIL Programming 2 07-14-2004 03:42 PM
Why can't I read in data from the serial port using a bash script? tjt Linux - Newbie 1 06-17-2004 12:21 AM


All times are GMT -5. The time now is 06:09 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration