Re: How to handle timeouts with MsComm?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

In general, the port is closed by Windows when the device is unplugged (this
is done by the driver that creates the Virtual Serial port). Thus, you
should get an error if you attempt to send data on the closed port. If you
do not get an error, I suspect that you need to check with your USB device
manufacturer to see if there is an update to the driver.

I normally DO NOT suggest that you open and close the port often. However,
there are situations where this is necessary, and you may have encountered
one. What I do is to create a Watchdog timer (use the Timer control), and
call the timer routine fairly often. In the timer,

On Error Resume Next
With MSComm1
If .PortOpen = True Then
.PortOpen = False
.PortOpen = True
If .PortOpen = False Then
MsgBox "Watchdog could not open port. Check hardware."
End If
Else
If YouKnowThePortShouldBeOpen Then
.PortOpen = True
If .PortOpen = False Then
MsgBox "Watchdog could not open port. Check hardware."
End If
End If
End With

***
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.


.


Quantcast