我写的程序,MSCOMM控件。 带数据格式的。帮我修改以下,谢谢,
下面是原代码:
Private Sub CommonConnect_Click()
'打开串口
Select Case ListCOM.ListIndex
Case 0
MSComm1.CommPort = 1
Case 1
MSComm1.CommPort = 2
Case 2
MSComm1.CommPort = 3
Case 3
MSComm1.CommPort = 4
End Select
If MSComm1.PortOpen = False Then
Select Case ListBate.ListIndex
Case 0
MSComm1.Settings = "1200,e,8,1"
Case 1
MSComm1.Settings = "2400,e,8,1"
Case 2
MSComm1.Settings = "4800,e,8,1"
Case 3
MSComm1.Settings = "9600,e,8,1"
End Select
MSComm1.PortOpen = True '打开串口
Else
MsgBox "串口已经打开"
End If
MSComm1.OutBufferCount = 0
'清空发送缓冲区
MSComm1.InBufferCount = 0
'{---清空接收缓冲区
CommonConnect.Visible = False
CloseCOM.Visible = True
End Sub
Private Sub CloseCOM_Click()
MSComm1.PortOpen = False
CommonConnect.Visible = True
CloseCOM.Visible = False
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
'接收二进制数据
Dim Buffer As Variant
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeBinary
Buffer = MSComm1.Input
Case Else
End Select
End Sub
Private Sub Form_Load()
YFSkin1.SkinInit Me
End Sub
Private Sub NextNo_Click()
Dim dblTmp As Double
Dim I As Integer
If NextNo.Caption = "下一表号" Then
If Trim(MeterNO.Text) = "" Then
dblTmp = 0#
Else
dblTmp = CDbl(MeterNO.Text)
End If
If dblTmp = 999999999998# Then
MeterNO.Text = "000000000000"
Else
MeterNO.Text = Right("000000000000" & CStr(dblTmp + 1), 12)
End If
Else
NextNo.Caption = "下一表号"
End If
' strMeterAddr = MeterNO.Text
End Sub
Private Sub ReadData_Click()
Dim I As Integer, J As Integer, K As Integer, L As Integer, M As Integer, Dummy As Integer
Dim strTmp As String
Dim boolMeterNoChg As Boolean
Dim ArrayRoom() As Byte
ReDim ArrayRoom(7)
ArrayRoom(0) = &H68 '侦起始符
ArrayRoom(1) = MeterNO.Text '设备号码
ArrayRoom(2) = &H68 '侦起始符
ArrayRoom(3) = Control '控制码
ArrayRoom(4) = Length '数据长度
ArrayRoom(5) = Data '数据
ArrayRoom(6) = E '偶校验,应该怎么写啊??
ArrayRoom(7) = &H16 '结束符
If MSComm1.PortOpen = False Then
MsgBox "串口没有打开,请先打开串口!"
Exit Sub
Else
If Check1(0).Value = True Then
ArrayRoom(3) = &H1
ArrayRoom(4) = &H2
ArrayRoom(5) = &H9010
MSComm1.Output = ArrayRoom
End If
Text1(0).Text = Buffer '接收的数据反映在控件当中
End If
End Sub