[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Serial write timeout?

Posted on 2001-08-13
6
Medium Priority
?
885 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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