请教VB高手一个串口的问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 04:28:39
我用串口线把我电脑上的串口1和2连接起来,串口1向2发数据,可怎么也发不出去,换了几根串口线,折腾了一天,还是不行,请高手帮我看看我的程序。
Private Sub cmdsent_Click()
Dim strsent As String
strsent = Trim(txtsent.Text)
If (strsent = "") Then
MsgBox "发送数据不能为空!", vbOKOnly, "提示"
txtsent.SetFocus
Else
comsent.Output = strsent
End If
End Sub

Private Sub comreceive_OnComm()
Select Case comreceive.CommEvent
Case comEvReceive
comreceive.InputMode = comInputModeText 'ASCII接收
txtreceive.Text = comreceive.Input
MsgBox "收到!"
End Select
End Sub

Private Sub Form_Load()
txtreceive = ""
comsent.CommPort = 1
comsent.PortOpen = True
comreceive.CommPort = 2
comreceive.PortOpen = True
comreceive.RThreshold = 1
'其余属性均默认设置
End Sub

从你的代码看未见明显错误.
请检查2个串口的连接线及接法:
2个串口间
2-3
3-2
5-5
连接
各自串口
4-6
7-8
短接

如果接线正确,你可用串口调试软件来测试.

再问个问题,你机器有几个串口,现在机器就1个串口,应该是将RS232口的2-3脚连接就可.