Private Sub clear_receivetext_Click()
receivetext.Text = ""
End Sub
Private Sub clear_sendtext_Click()
sendtext.Text = ""
End Sub
Private Sub close_Click()
MSComm1.PortOpen = False '关闭串口
Label3 = "当前状态:关闭"
End Sub
Private Sub Form_Load()
Label3 = "当前状态:关闭"
End Sub
Private Sub open_Click()
MSComm1.CommPort = 4 '使用串行端口4
MSComm1.Set
tings = "9600,N,8,1" '设置波特率等
MSComm1.InputLen = 0 '清空从接收缓存器中读到的字符
MSComm1.PortOpen = True '打开端口
Label3 = "当前状态:打开"
End Sub
Private Sub send_Click()
On Error Resume Next '简单的错误处理
If MSComm1.PortOpen = False Then
MsgBox "串口已关闭"
End If
MSComm1.Output = sendtext.Text '将发送窗体内的文字送到
单片机
For i = 0 To Len(sendtext.Text)
Sleep 100 '等待30毫秒,避免波特率出现的乱码
MSComm1.Output = Mid(sendtext.Text, i, 1)
Next i
MSComm1.InputMode = comInputModeText '设置接受模式是文本接受,还是二进制接受
End Sub
Private Sub shakehand_Click()
On Error Resume Next '简单的错误处理
If MSComm1.PortOpen = False Then
MsgBox "串口已关闭"
End If
MSComm1.Output = Chr(0) '用EF代表发起握手
MSComm1.InputMode = comInputModeText '设置接受模式是文本接受,还是二进制接受
receivetext = receivetext + vbCrLf + "正在等待握手成功信息" '显示等待握手成功信息
Sleep 800 '等待800毫秒
If MSComm1.Input = Chr(1) Then
receivetext = receivetext + MSComm1.Input + vbCrLf + "握手成功"
Else: receivetext = receivetext + MSComm1.Input + vbCrLf + "握手失败" '用EE代表握手成功
End Sub
一周热门 更多>