我的单机串口通信程序哪里有问题啊?
最近老师布置了到网络作业题,让我们用VB编写一个单机串口通信的程序,硬件上就拿一根串口线让发端和收端短接就可以了。我用mscomm控件编写了个程序,运行始终不出来!请高手帮忙指教下!谢谢
FORM1中有两个窗口,一个发(txtTran),一个收(txtRece)
程序如下:
Option Explicit
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdTran_Click()
MSComm1.CommPort = 1
If MSComm1.PortOpen = False Then
MSComm1.Settings = "9600,n,8,1" '9600波特率,无校验,8位数据位,1位停止位
MSComm1.PortOpen = True '打开串口
End If
MSComm1.OutBufferCount = 0 '清空发送缓冲区
MSComm1.InBufferCount = 0 '滑空接收缓冲区
MSComm1.Output = txtTran.Text & vbCr
txtTran.Text = ""
End Sub
Private Sub MScommEvent()
Select Case MSComm1.CommEvent
Case comEvReceive
Dim Buffer As Variant
' MSComm1.InputLen = 0
'接收二进制数据
MSComm1.InputMode = comInputModeBinary
Buffer = MSComm1.Input
'接收字符数据
MSComm1.InputMode = comInputModeText
Buffer = MSComml.Input
txtRec.SetFocus
txtRec.Text = Buffer
txtRec.Text = 123
Case Else
End Select