在程序运行时手动断开连接后尝试重新连接到USB设备,基本上启动程序时出现“点击”事件,现在我要问的是,是否有一些代码检查断开连接后是否重新连接。
Try
'code executing here, then the device is disconnected while this code is running
If oflag = False Then 'oflag is false by default
SerialPort1.PortName = ("Com" & COMnum) 'Assigns the serial port name
SerialPort1.Open()
End If
'extra code after this
Catch ex As IOException
MsgBox("BLAH")
oflag = True 'this used
Exit Sub
End Try