Solved

Serial write timeout?

Posted on 2001-08-13
6
846 Views
Last Modified: 2008-02-26
Hi,

I am trying to send data through the serial port. I'm not having any problems with that, but how can I detect when something goes wrong while writing data to it?

Currently I am writing data to it one byte at a time. If, during a large transmission, I disconnect the serial cable, my program just hangs on the write command. Is there any way to set up a timeout period for the write operation?

I am just using the standard write command with a file descriptor.

Cheers,
Dave
0
Comment
Question by:dwagner
6 Comments
 
LVL 5

Expert Comment

by:paulqna
ID: 6383660
I guess this relates to your problem as well...?

http://www.linuxdoc.org/HOWTO/Serial-Programming-HOWTO-3.html

and look for:
while (STOP==FALSE) {     /* loop until we have a terminating condition */
0
 

Author Comment

by:dwagner
ID: 6383825
Hi,

It is a little different in my case because I am writing rather than waiting for input. As far as I can see there is no way to automatically have a timeout value for writing to a resource.

However, I solved my own problem. I now access the serial port in non-blocking mode (using the O_NONBLOCK flag when opening it) instead of a blocking mode.

I then have a little bit of code that tries to write a byte to the resource for a specified period of time. If it fails because the file is busy it will try sending again. It gives up after an unexpected error or the time I want to retry for has been exceeded.

Kind of simple when I thought of it. I should have waited those 5 minutes longer before posting here :)

Thanks for your help though. I'll leave this question open in case anyone has a better solution.


Dave
0
 
LVL 3

Expert Comment

by:mrn060900
ID: 6383834
What about using checksum, after you've sent the data, could you then retrieve it and compare the checksum?

This a just a wild stab in the dark.

Regards Mike
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:dwagner
ID: 6384276
Hi,

That would spot corrupt data but wouldn't help the original problem of having a "write" just hang if transmission was interupted (for example by ripping the serial cable out of the port like I did :).

I'm not too worried if the machine at the other side of the serial cable receives the data OK. It can work that out from a CRC transmitted with the data and then it can decided if it wants to try getting the data again.

CRCs... I still don't fully understand the maths... Good job there is plenty of source code out there that I can use :)

Dave
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9915896
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 9963594
PAQed, with points refunded (100)

modulo
Community Support Moderator
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question