Rodos wrote:
> Here is my problem. There are three things the program does, writes out
> to a serial port. Reads and writes to the parallel port, and
> communicates with a database. The thing is that the serial and database
> stuff might block or timeout for periods of time (say 1 to 10 seconds).
> However I need to constantly poll the serial port for data.
Thanks for the replies everyone. There is some great info there.
Books:
Conrad suggested APUE. I have always wanted this book but never really
needed it, not being a C programmer. Now I am sort of becoming one, I
went and purchased it. Dave mentioned Stroustrup. I have his books from
when I was doing C++ at uni, I thought they were great and devoured
them. Richard also recomended "Unix Network Programming" and when I was
at Hotline I grabbed Volume 2 as it had a lot on process communication
stuff, might come in handy. He also recommended "Programming POSIX
Threads" which I also got, it seams great giving the portion I have read
so far. Anyone want to suggest I bug a fast car? I am ready! <grin>
Solutions:
Conrad and Raster recommended select()/poll(). Now in reading APUE these
work on file handles. The thing is that only one of the things which may
cause delays is a file handle.
For the parallel port I need to poll it every n ticks. Thats because it
has a crude input device attached to it and if a contact is closed the
only way I know is to read the data lines off the port. As soon as the
contact is released the action is lost (its not latched) so I have to
read it often to get a good response time for the user.
The other delay is the ODBC calls which go off to the SQL server. Who
knows how long MSSQL will take to respond!
Given these three things I don't think select()/poll() are going to
work.
Dave went with threads. To me this seams like the logical way to go. I
can have a worker to continually poll the parallel port and buffer up a
queue of button presses. Another worker can handle doing the serial
output. Either the main thread or another worker can do the database IO.
Having read a bit of the thread book it does not seam to daunting
(especially to were I was when I started, I have come a way to get this
far).
So the next 24 hours will be taken hacking some thread code together to
see if I can prove that its going to work. I will let you know my
success or failure and there might be the occasional scream for help.
Rodos (loving coding on Linux)
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text