大虾们帮我看看这个串口通讯程序,我不用虚拟串口也能发送成功
'串口初始化Private Sub Form_Load()
MSComm1.CommPort = 2 '设置通信端口号为COM2
MSComm1.Settings = "9600,n,8,1" '设置串口参数 9600波特率,无校验,8位数据位,1位停止位
MSComm1.InputMode = 0 '接收文本型数据
End Sub
Private Sub Command1_Click()
MSComm1.Output = TextSend.Text '发送TextSend的内容
End Sub
Private Sub Command6_Click()
Timer1.Enabled = True '运行计时器控件
End Sub
'定时自动从输入缓冲区发送字符
Private Sub Timer1_Timer()
MSComm1.Output = TextSend.Text '发送文本2的内容
End Sub
Private Sub Command2_Click()
TextReceive.Text = "" '清空接收区
End Sub
Private Sub Command3_Click()
TextSend.Text = "" '清空发送区
End Sub
Private Sub Command4_Click()
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True '打开串口
End Sub
'在OnComm 事件中接收数据
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent '返回最近的通讯事件或错误
Case comEvReceive ' 收到 RThreshold # of
Dim hk As Variant
hk = MSComm1.Input
TextReceive.Text = TextReceive.Text & hk
End Select
End Sub
'关闭通信端口,停止程序运行
Private Sub Cmdquit_Click()
MSComm1.PortOpen = False
End
End Sub
不知道是虚拟串口的问题还是程序的问题,麻烦各位了! --------------------编程问答-------------------- 看看这个:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command5_Click()
If msccomm1.PortOpen Then MSComm1.PortOpen = False
Unload Me
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 2 '设置通信端口号为COM2
MSComm1.Settings = "9600,n,8,1" '设置串口参数 9600波特率,无校验,8位数据位,1位停止位
MSComm1.InputMode = 0 '接收文本型数据
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
End Sub
Private Sub Command1_Click()
MSComm1.Output = TextSend.Text '发送TextSend的内容
End Sub
Private Sub Command6_Click()
Timer1.Enabled = True '运行计时器控件
End Sub
'定时自动从输入缓冲区发送字符
Private Sub Timer1_Timer()
MSComm1.Output = TextSend.Text '发送文本2的内容
End Sub
Private Sub Command2_Click()
TextReceive.Text = "" '清空接收区
End Sub
Private Sub Command3_Click()
TextSend.Text = "" '清空发送区
End Sub
Private Sub Command4_Click()
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True '打开串口
End Sub
'在OnComm 事件中接收数据
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent '返回最近的通讯事件或错误
Case comEvReceive ' 收到 RThreshold # of
Sleep 20
Dim hk As Variant
Do
hk = MSComm1.Input
TextReceive.Text = TextReceive.Text & hk
Loop Until MSComm1.InBufferCount > 0
End Select
End Sub
补充:VB , 网络编程