[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Serial write timeout?

Posted on 2001-08-13
6
Medium Priority
?
893 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

830 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