Solved

Serial write timeout?

Posted on 2001-08-13
6
836 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now