Page 1 of 1
Serial Port Timeout Detection
Posted: Mon Oct 05, 2009 9:27 pm
by kh1234567890
How do you detect that a timeout had occurred using the in-built PB 4.32 serial port functions ?
There are no obvious clues in the documentation.

Re: Serial Port Timeout Detection
Posted: Tue Oct 06, 2009 4:42 am
by Rook Zimbabwe
You have to keep checking to see if it is active.
Interesting username?
Re: Serial Port Timeout Detection
Posted: Wed Oct 07, 2009 9:24 am
by John Puccio
Hi KH 1 thru 0,
Serial ports don't exactly time out, they are closed just like a file. Basically the host program says "if I do not see activity for X amount of time then close the port" that's how you get a timeout. What you need to do is look at the DCD line (Data Carrier Detect) if it is low then you have no carrier (no connection) and thus your timeout.
Hope that helps.
JP
Re: Serial Port Timeout Detection
Posted: Wed Oct 07, 2009 11:45 am
by kh1234567890
Thanks for the replies.
So when the serial port 'times out' after an interval set by SerialPortTimeouts it just closes and disappears ?
I was hoping for something more useful - I suppose it is back to the kludge of using the API timer to periodically check if any characters have appeared in the serial buffer.
In this application I have a simple three wire serial connection with no handshaking lines, connected to an unpredictable data acquisition front end sending data whenever it feels like it.
It is all coming back, why I gave up on PB about four years ago
kh1234567890 (because people kept using kh1, kh2 etc.)
Re: Serial Port Timeout Detection
Posted: Wed Oct 07, 2009 3:38 pm
by dhouston
Create a separate thread for your serial port receive procedure.
Code: Select all
If IsSerialPort(ComID):ComThread=CreateThread(@ComEventRcv(),0):EndIf
Code: Select all
Procedure ComEventRcv(*nada) ;serial input thread
Protected ComRcv.s,char.s=" ",buffer.b,n
Repeat
If IsSerialPort(ComID)
While AvailableSerialPortInput(ComID)
n=ReadSerialPortData(ComID,@buffer,1)
Select buffer ;Asc(char)
Case 10,13,32 To 126:ComRcv+Chr(buffer)
EndSelect
If Right(ComRcv,2)=#CRLF$
If CmdMode
cmd=Left(ComRcv,Len(ComRcv)-2)
Else
UpdateIO(Left(ComRcv,Len(ComRcv)-2))
EndIf
ComRcv=""
EndIf
Wend
EndIf
ForEver
EndProcedure
Re: Serial Port Timeout Detection
Posted: Wed Oct 07, 2009 4:09 pm
by kh1234567890
Neat !
Thanks, I'll try that.
[Edit]
Works fine, just needed a short delay in the Repeat loop to stop the thread hoarding the processor.
Thanks again.
kh
Re: Serial Port Timeout Detection
Posted: Thu Oct 08, 2009 7:31 pm
by John Puccio
kh1234567890 wrote:Thanks for the replies.
So when the serial port 'times out' after an interval set by SerialPortTimeouts it just closes and disappears ?
I was hoping for something more useful - I suppose it is back to the kludge of using the API timer to periodically check if any characters have appeared in the serial buffer.
In this application I have a simple three wire serial connection with no handshaking lines, connected to an unpredictable data acquisition front end sending data whenever it feels like it.
It is all coming back, why I gave up on PB about four years ago
kh1234567890 (because people kept using kh1, kh2 etc.)
EDIT:
KH
I'm glad you found a workable solution. Just to clarify, It's not a PB issue. It's a com port issue. Looking over my old docs, in a 3 wire no handshake situation there is no carier signal so DCD doesn't even apply.
JP