1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Private Sub CommandButton1_Click()
On Error Resume Next 'Error handler
If MSComm1.PortOpen = False Then 'check if the serial port is open
MSComm1.PortOpen = True 'check if the serial port is open
End If
If Err Then MsgBox Error$, 48 'Display error in message box
'Set all outputs to High (serial relay card commands)
MSComm1.Output = "A" + "H" + "0" + Chr$(13)
End Sub
Private Sub CommandButton2_Click()
On Error Resume Next 'Error handler
If MSComm1.PortOpen = False Then 'if the serial port is closed
MSComm1.PortOpen = True 'open the serial port
End If
If Err Then MsgBox Error$, 48 'Display error in message box
'Set all relays outputs to low (serial relay card commands)
MSComm1.Output = "A" + "L" + "0" + Chr$(13)
End Sub
Private Sub UserForm_Terminate()
On Error Resume Next 'Error handler
If MSComm1.PortOpen = True Then 'check if the serial port is open
MSComm1.PortOpen = False 'close the serial port
End If
If Err Then MsgBox Error$, 48 'Display error in message box
End Sub |
Partager