C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-12-2009, 11:58 AM   #16
Registered User
 
Join Date: Jun 2009
Posts: 34
Quote:
Originally Posted by itCbitC View Post
Curious if you made it non-blocking by setting a timeout in the struct timeval member??
I didn't have to do this because the machine is being queried via the serial port constantly. So, I just passed NULL as the last argument to select(). From what I can tell, this effectively throttles the reads off the serial port based on the speed that the remote machine is sending queries. And since it's running in its own thread, this doesn't tie up the main thread, which is constantly checking variables updated from the serial port reader thread (via a loop) and performing the main program functions.
synthetix is offline   Reply With Quote
Old 07-13-2009, 11:51 PM   #17
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Quote:
Originally Posted by synthetix View Post
I didn't have to do this because the machine is being queried via the serial port constantly. So, I just passed NULL as the last argument to select(). From what I can tell, this effectively throttles the reads off the serial port based on the speed that the remote machine is sending queries. And since it's running in its own thread, this doesn't tie up the main thread, which is constantly checking variables updated from the serial port reader thread (via a loop) and performing the main program functions.
Reason to have a timeout is to prevent the select from blocking otherwise it'll just sit there and wait for input exactly like the call below:
Code:
fcntl(fd_serialport, F_SETFL, 0);
Is your application doing anything else besides reading from that serial port? Are there many ports to read from?
The power of select() is in its ability to poll each file descriptor in turn, waiting for an event or else timing out.
itCbitC is offline   Reply With Quote
Old 07-14-2009, 08:17 AM   #18
Registered User
 
Join Date: Jun 2009
Posts: 34
Quote:
Originally Posted by itCbitC View Post
Is your application doing anything else besides reading from that serial port? Are there many ports to read from?
The power of select() is in its ability to poll each file descriptor in turn, waiting for an event or else timing out.
Yeah, it's taking that input and using it to decide what action to take elsewhere in the program. That's why I put it in its own thread. And I don't have a timeout set because the serial port is being read at a constant rate. If there's no serial input, there's nothing the program can do anyway. And if it does happen to hang up, it won't cause the entire program to stop because it's a separate thread. Although now that I think about it, I may just assign a timeout to it anyway "just in case." Seems like it would be a good coding practice, if nothing else.

I did make a variant of this program that does absolutely nothing but send and receive serial port commands. Now, with this one I had to assign a timeout value to select() because the flow of data was not constant. It was a program I wrote to check for proper operation of the first program (this time server side instead of client side). Once commands are sent, the client only responds once, hence complete lockup (blocking) unless you timeout select().
synthetix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending data over UDP from serial port forumguy Linux Programming 0 04-25-2009 02:10 PM
can someone help me with these errors please code included geekrockergal C Programming 7 02-10-2009 02:20 PM
Problem with string and serial port collinm C Programming 2 03-23-2005 10:19 AM
Serial Communications in C ExDigit Windows Programming 7 01-09-2002 10:52 AM
Need help or info about serial port communication Unregistered Linux Programming 1 01-08-2002 01:48 PM


All times are GMT -6. The time now is 08:43 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22