Dear forum users,
I'm looking for some way to signal that the serial port has been lost (for example by unplugging the USB-SERIAL converter). The recommended function IsSerialPort() does not return an error (zero value) if the port was previously opened correctly (I tested it in Windows). So how can I determine that something happened while the program is running?
Best regards
Lost serial port error
Re: Lost serial port error
I know "zilch" about USB/Serial ports. So...
What about a window timer that checks the status of the port (GetSerialPortStatus())?
What about a window timer that checks the status of the port (GetSerialPortStatus())?
Re: Lost serial port error
HwyStar,
thanks for your answer.
I am not using any port input line other than RxD, so GetSerialPortStatus() always returns 0 for all lines (RI, DCD, DSR and CTS), but...
Serial port initialized with parameter #PB_SerialPort_NoHandshake after calling the GetSerialPortStatus() function with the parameter #PB_SerialPort_XonCharacter or #PB_SerialPort_XoffCharacter returns 17 or 19. And if I disconnect USB plug this character codes becames 0!
Maybe that's a good way? I have to check if it will be repeatable for different converters.
Thank you!
thanks for your answer.
I am not using any port input line other than RxD, so GetSerialPortStatus() always returns 0 for all lines (RI, DCD, DSR and CTS), but...
Serial port initialized with parameter #PB_SerialPort_NoHandshake after calling the GetSerialPortStatus() function with the parameter #PB_SerialPort_XonCharacter or #PB_SerialPort_XoffCharacter returns 17 or 19. And if I disconnect USB plug this character codes becames 0!
Maybe that's a good way? I have to check if it will be repeatable for different converters.
Thank you!
Re: Lost serial port error
I can't say I helped. But, timers do come in really handy!
Re: Lost serial port error
In my application serial ports are read periodically in separate threads, which is equivalent to using a timers.
Re: Lost serial port error
Here is a windows-only possibility:
Code: Select all
Procedure CallBack_NewDevice(WindowID, Message, wParam, lParam)
Protected Result, a$
Protected *db.DEV_BROADCAST_HDR
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_DEVICECHANGE
If wParam = #DBT_DEVICEARRIVAL
*db = lParam
If *db\dbch_devicetype = #DBT_DEVTYP_PORT
a$ = PeekS(*db + SizeOf(DEV_BROADCAST_HDR))
Debug "New Port Connected: " + a$
EndIf
ElseIf wParam = #DBT_DEVICEREMOVECOMPLETE
*db = lParam
If *db\dbch_devicetype = #DBT_DEVTYP_PORT
a$ = PeekS(*db + SizeOf(DEV_BROADCAST_HDR))
Debug "Port Disconnected: " + a$
EndIf
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
OpenWindow(0, 0, 0, 300, 200, "Test Ports", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowCallback(@CallBack_NewDevice(), 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}
Re: Lost serial port error
HeXOR,
impressive knowledge.
Thank you.
impressive knowledge.
Thank you.