Priv ate Su b btnSend_Click(Index As Integer) Select Case Index Case 0 '03 命令测试 ' MsgBox (cmbSlId(0).Tex t) Label9.Caption = CommandQu ery 03(cmbSlId(0).Tex t, Val(cmbRegAdd(0).Tex t) - 1, cmbDataTy pe(0).Tex t) lblSlav eStatu s(0).Caption = "读从机,等待!" Case 1 '16 命令测试 If Not IsNu meric(tx tWriteData.Tex t) Then MsgBox ("请输入数据!") tx tSend(1).Tex t = "" tx tSend(1).SetFocu s Ex it Su b End If tx tSend(1).Tex t = CommandQu ery 16(cmbSlId(1).Tex t, Val(cmbRegAdd(1).Tex t), cmbDataTy pe(1).Tex t, tx tWriteData.Tex t) lblSlav eStatu s(1).Caption = "写从机,等待响应" tx tReceiv e(1).Tex t = "" Case 2 '08 命令测试 If Not IsNu meric(tx tDignoseAsk.Tex t) Then MsgBox ("请输入数据!") tx tSend(2).Tex t = "" tx tDignoseAsk.Tex t = "" tx tDignoseAsk.SetFocu s Ex it Su b End If tx tSend(2).Tex t = CommandQu ery 08(cmbSlId(2).Tex t, cmbDataTy pe(2).Tex t, tx tDignoseAsk.Tex t) lblSlav eStatu s(2).Caption = "诊断从机,等待响应" tx tReceiv e(2).Tex t = "" tx tDignoseBack.Tex t = "" Case Else End Select End Su b Priv ate Su b Command1_Click() On Error Resu me Nex t SetPort With MSComm1 If .PortOpen = Tru e Then .PortOpen = False Command1.Caption = "打开串口" Shape1.FillColor = &HFF& Label11.Caption = "串口已关闭" Label6.Caption = "串口状态:关闭" Else Command1.Caption = "关闭串口" .PortOpen = Tru e Label6.Caption = "串口状态:打开" Shape1.FillColor = &HC000& Label11.Caption = "串口已打开" If Err.Nu mber <> 0 Then Label11.Caption = "串口已使用" Err.Clear End If End If End With 'MsgBox (MSComm1.PortOpen) End Su b Priv ate Su b SetPort() Dim cu rPortOpen As Boolean Dim intCommPort As Integer Dim strCheckBit As String Dim strSettings As String Dim i As Integer Select Case Combo1.Tex t Case "COM1" intCommPort...