α
2 Simple Application Controllers
The Command String 7
7 - 46
3. Open the Code Window in VB and insert the following codelines.
Option Explicit
Private timecnt As Integer
Private optidx As Integer
Private cmdstr() As Byte
Private cmdlen As Integer
Private resplen As Integer
Private Sub Form_Load()
txtTxText.Text = ""
txtRxText.Text = ""
Call StopTimer
Timer1.Interval = 100
End Sub
Private Sub optCmd_Click(Index As Integer)
optidx = Index
Call SetCommand
Call ShowTxData
End Sub
Private Sub cmdTransmit_Click()
Dim lenrxdata As Integer
Dim rxdata() As Byte
cmdTransmit.Enabled = False
If PortOpen = True Then
Call SendCmnd
lenrxdata = resplen
Call RecResponse(rxdata, lenrxdata)
Call ShowRxData(rxdata, lenrxdata)
End If
cmdTransmit.Enabled = True
End Sub
Private Sub cmdReset_Click() '"Reset"Button is clicked.
Call ShowTxData
txtRxText.Text = ""
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
cmdTransmit.Enabled = True
End Sub
Private Sub SetCommand()
Select Case optidx
Case 0 '"Communication Line Check".
cmdstr = ChrB(&H2) + ChrB(&H3) + ChrB(&H40) _
+ ChrB(&H0) + ChrB(&H5)
cmdlen = 5
resplen = 5