LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
  Search this Thread
Old 05-01-2009, 12:35 PM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 622

Rep: Reputation: 42
Comms port code locks if no device return


Hi all,
A while ago I did some code to talk to comms ports. It appeared to work fine, except I discovered that my receive functions locks up if no data is being sent from an rs232 device?

Basically I use open,read and write function. The problem is the read function which hangs if no data is being sent. So I can't even error.

I set up the port with an open (and all the rest of the baud rate stuff)
Code:
(*comlist)->id = open((*comlist)->portname, O_RDWR | O_NOCTTY | O_NDELAY);
I've also tried adding a non block but this has no effect
Code:
(*comlist)->id = open((*comlist)->portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
I read with
Code:
read(port->id, readletter, 1)
This just hangs on read unless I connect a device which is sending data.
Is there a way to make read return if nothing is there? I thought I would get a -1 returned but this does not appear to be the case. Thanks
 
Old 05-01-2009, 10:39 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Try doing the read() only if select() tells you that data is available.
 
Old 05-02-2009, 08:23 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 622

Original Poster
Rep: Reputation: 42
Thanks found it you need to set F_SETFT with fcntl function
 
  


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
mount return code muradcsc Linux - Newbie 4 12-13-2007 04:05 AM
return code or errno? micropanther Programming 2 10-29-2007 10:23 AM
SCSI error: return code = 0x10000 on USB Mass Storage device gringer Linux - Hardware 4 05-14-2007 07:43 AM
request_region(...) return code BrooklynOutlier Programming 0 03-07-2006 10:22 PM
dd return code barefootdoctor Linux - General 2 10-13-2005 01:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration