求大神帮解决,这个VB写的上位机程序,看不懂求解释
时间:10-02
整理:3721RD
点击:
- Dim rxn As Boolean
- Private Sub Command1_Click()
- On Error Resume Next
- Dim s As Integer
- s = Val(Text1)
- If s > 255 Then s = 255
- If s < 1 Then s = 1
- MSC1.CommPort = s
- MSC1.PortOpen = True
- If MSC1.PortOpen = True Then
- Command1.Enabled = False
- Command2.Enabled = True
- Else
- Command1.Enabled = True
- Command2.Enabled = False
- End If
- End Sub
- Private Sub Command2_Click()
- On Error Resume Next
- MSC1.PortOpen = False
- If MSC1.PortOpen = True Then
- Command1.Enabled = False
- Command2.Enabled = True
- Else
- Command1.Enabled = True
- Command2.Enabled = False
- End If
- End Sub
- Private Sub Command3_Click(Index As Integer)
- Dim tbuf(0) As Byte
- tbuf(0) = 1 * 16 + Index
- MSC1.Output = tbuf()
- End Sub
- Private Sub Command4_Click(Index As Integer)
- Dim tbuf(0) As Byte
- tbuf(0) = 0 * 16 + Index
- MSC1.Output = tbuf()
- End Sub
- Private Sub MSC1_OnComm()
- On Error Resume Next
- Dim ss() As Byte
- Dim i As Integer
- Dim j As Integer
- Dim k As Integer
- Dim ssr As String
- If MSC1.CommEvent = comEvReceive Then
- ss = MSC1.Input
- For i = 0 To UBound(ss)
- If ss(i) = &H55 Then
- rxn = True
- Else
- If rxn = True Then
- j = (ss(i) Mod 16)
- k = (ss(i) \ 16)
- If k < 8 Then
- ss = ""
- If j = 0 Then
- ssr = "储藏箱" & k & "关闭,空闲"
- ElseIf j = 1 Then
- ssr = "储藏箱" & k & "打开,存放"
- ElseIf j = 2 Then
- ssr = "储藏箱" & k & "关闭,使用中"
- ElseIf j = 3 Then
- ssr = "储藏箱" & k & "打开,取走"
- End If
- List1.AddItem ssr
- Else
- k = k - 8
- If k < 4 Then
- ss = ""
- If j = 0 Then
- ssr = "储藏箱" & k & "关闭,空闲"
- ElseIf j = 1 Then
- ssr = "储藏箱" & k & "打开,存放"
- ElseIf j = 2 Then
- ssr = "储藏箱" & k & "关闭,使用中"
- ElseIf j = 3 Then
- ssr = "储藏箱" & k & "打开,取走"
- End If
- Label1(k).Caption = ssr
- End If
- End If
- End If
- rxn = False
- End If
- Next i
- End If
- End Sub