There are no obvious clues in the documentation.
Serial Port Timeout Detection
- kh1234567890
- New User

- Posts: 3
- Joined: Sat Jan 15, 2005 4:44 pm
- Location: Inside your head
Serial Port Timeout Detection
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.
There are no obvious clues in the documentation.
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Serial Port Timeout Detection
You have to keep checking to see if it is active.
Interesting username?
Interesting username?
- John Puccio
- User

- Posts: 26
- Joined: Fri Jun 12, 2009 6:56 am
- Location: My Keyboard
Re: Serial Port Timeout Detection
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
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
- kh1234567890
- New User

- Posts: 3
- Joined: Sat Jan 15, 2005 4:44 pm
- Location: Inside your head
Re: Serial Port Timeout Detection
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.)
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
Create a separate thread for your serial port receive procedure.
Code: Select all
If IsSerialPort(ComID):ComThread=CreateThread(@ComEventRcv(),0):EndIfCode: 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- kh1234567890
- New User

- Posts: 3
- Joined: Sat Jan 15, 2005 4:44 pm
- Location: Inside your head
Re: Serial Port Timeout Detection
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
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
- John Puccio
- User

- Posts: 26
- Joined: Fri Jun 12, 2009 6:56 am
- Location: My Keyboard
Re: Serial Port Timeout Detection
EDIT: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.)
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

