Timing out a serial connection?
DiverBob
Posts: 1,108
I haven't found any posts with this particular problem...
I have a serial connection as part of my initialization routine where the connection is initialized, 2 characters are transmitted and then I wait for a response. But it is possible that there may not be any response - using the standard .rx command in FullDuplexSerialPlus.spin the program then hangs at this point until I cut the power. Is there a method for timing out the connection if there is no response after a reasonable amount of time so the rest of the app can run?
Thanks
Bob Sweeney
I have a serial connection as part of my initialization routine where the connection is initialized, 2 characters are transmitted and then I wait for a response. But it is possible that there may not be any response - using the standard .rx command in FullDuplexSerialPlus.spin the program then hangs at this point until I cut the power. Is there a method for timing out the connection if there is no response after a reasonable amount of time so the rest of the app can run?
Thanks
Bob Sweeney
Comments
There is an rxtime routine as well that does this for a specific delay, but this blocks the execution cog from doing other things while in the polling loop.
Cheers!
Paul Rowntree
Post Edited (TreeLab) : 2/1/2009 4:25:40 PM GMT
Thanks for the info, I had looked over the rxcheck command but I guess it didn't sink in that it only checks the rx buffer for input. I can put the rxcheck in a 1 or 2 second timing loop and if the buffer is still empty I can push the app into 'test mode' and run fake data instead of waiting forever for serial data!
Thanks again!
Bob Sweeney
take a look into the RxTime-method inside the FullDuplexSerial-object
best regards
Stefan
Bob
That will try for 100ms and if no response returns -1
you should trust a little more in the comments of the code of FullDuplexSerial
stores a snapshot of the systemcounter in variable t
calculates the amount of time that has been gone since the snapshot
and as this time is MORE than the value of "ms" the waiting inside the repeat until-loop ends
here is a democode showing how it works
best regards
Stefan
Maybe I should add a signature like that
"there are two ways of learning programming
1.) a slow one: ask EVERYTHING on the forum three words short
2.) a quick one: try something yourselve - ask the forum 10 sentences long -attaching your code - go adding debugoutput to your code while waiting for the forum-answers
I have been a professional database and applications programmer for well over 20 years, I have studied numerous languages and am proficient in several, but I will be the first to admit that I am not perfect in each language I use. Since spin is only a hobby and I usually am using it when I'm tired in the evenings after a full day of my paid job, sometimes I just don't 'get it' right away. Once I read the posts and checked the serial code I saw what I needed then. Sometimes a little help goes a long way.
So forgive me if I am a little slow sometimes, I think this forum has been a great place to learn no matter what your level of competance. Please have some patience with those who aren't at your level yet.
Bob Sweeney