|
Private Sub ComMS_Click()
If ComMS.Caption = "打开串口" Then
ComMS.Caption = "关闭串口"
MSComm1.CommPort = Mid(Combo1.Text, 4)
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
Else
MsgBox "串口已经打开!"
Exit Sub
End If
Else
ComMS.Caption = "打开串口"
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End If
'If MSComm1.PortOpen = True Then
' Me.Caption = "串口已经打开!"
'End If
End Sub
Private Sub ComTXA_Click()
'发送文本文件类
'清空接收缓冲区
MSComm1.InBufferCount = 0
'发送数据帧
MSComm1.Output = TextTXA.Text
End Sub
Private Sub ComTXN_Click()
'''''''''''''''''''''''''''发送多字节类
'定义变量
Dim i As Byte
Dim TXSum As Integer
Dim TXBuff(0 To 8) As Byte
Dim StrTX_Temp As String
Dim StrData As String
'
TXSum = 0
For i = 0 To 7
TXBuff(i) = Val("&H" & UCase(TextN(i))
TXSum = TXSum + TXBuff(i)
Next i
TXBuff(8) = TXSum Mod 256
'清空接收缓冲区
MSComm1.InBufferCount = 0
'发送数据帧
MSComm1.Output = TXBuff
End Sub
|
|