发表于:2004/3/25 17:05:00
#0楼
以下是我的VB串口通讯实验程序,运行后按COMMAND1可发送指定得字符串,在另一台PC机上用串口精灵3.0可以收到,但用串口精灵3.0发送字符此程序却收不到,好象没用产生OnComm事件。OnComm事件驱动得串口接收程序是这么写吗?请诸位高手指教。谢谢!谢谢!!谢谢!!!
Private Sub Form_Load()
MSComm1.CommPort = 1
If MSComm1.PortOpen = False Then
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
End If
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub Command1_Click()
MSComm1.Output = "This is a good book!" & vbCr
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Dim Buffer As String
MSComm1.InputLen = 0
''接收字符数据
If Option1.Value = True Then
MSComm1.InputMode = comInputModeBinary
Buffer = MSComm1.Input
End If
''接收二进制数据
If Option2.Value = True Then
MSComm1.InputMode = comInputModeText
Buffer = MSComm1.Input
End If
Text1.Text = Buffer
Case Else
End Select
End Sub
联系方法:
e-mail: appal888@sina.com
QQ: 327962896
Private Sub Form_Load()
MSComm1.CommPort = 1
If MSComm1.PortOpen = False Then
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
End If
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub Command1_Click()
MSComm1.Output = "This is a good book!" & vbCr
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Dim Buffer As String
MSComm1.InputLen = 0
''接收字符数据
If Option1.Value = True Then
MSComm1.InputMode = comInputModeBinary
Buffer = MSComm1.Input
End If
''接收二进制数据
If Option2.Value = True Then
MSComm1.InputMode = comInputModeText
Buffer = MSComm1.Input
End If
Text1.Text = Buffer
Case Else
End Select
End Sub
联系方法:
e-mail: appal888@sina.com
QQ: 327962896
[此贴子已经被作者于2004-3-25 17:06:34编辑过]
在家靠父母,出外靠朋友,网上就靠各位大虾啦!