How about this
Option Explicit
Private m_strInitCode As String
Private m_strAckCode As String
Private m_strOnCode As String
Private m_strOffCode As String
Private m_strBuffer As String
'-----------------------------------------------------------------------------------------------------------------------
Private Sub cmdAcknowledge_Click()
FlushBuffer
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
MSComm1.Output = m_strAckCode
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub cmdFlush_Click()
FlushBuffer
lstResponse.Clear
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub cmdInitialize_Click()
FlushBuffer
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
MSComm1.Output = m_strInitCode
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub cmdOff_Click()
FlushBuffer
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
MSComm1.Output = m_strOffCode
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub cmdOn_Click()
FlushBuffer
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
MSComm1.Output = m_strOnCode
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "4800,N,8,1"
MSComm1.RThreshold = 1
m_strInitCode = Chr$(&H4) & Chr$(&H66)
m_strAckCode = Chr$(&H0)
m_strOnCode = Chr$(&H6) & Chr$(&H62)
m_strOffCode = Chr$(&H6) & Chr$(&H63)
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen Then MSComm1.PortOpen = False
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
m_strBuffer = m_strBuffer & MSComm1.Input
End Select
lstResponse.AddItem m_strBuffer
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Private Sub FlushBuffer()
m_strBuffer = vbNullString
End Sub
'-----------------------------------------------------------------------------------------------------------------------
Note there are 5 Command Buttons(cmdInitialize, cmdAcknowledge, cmdOn, cmdOff, and cmdFlush) and a ListBox(lstResponse). Each button will send the corresponding code and the list box will display the response.
If you choose to battle wits with the witless be prepared to lose.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)