mscomm控件(接收的字符少于发送的字符)(在线等)

whythinkwhy 2005-10-06 04:37:16
单步调式的时候接收的字符数和发送的字符数是一致的。但是一旦程序运行,
则接收的字符数就少于发送的字符数。有时接收的字符串为空。望高手不吝赐教。
示例:
Private Sub Command1_Click()
Dim str As String
MSComm1.CommPort = 1
If Me.MSComm1.PortOpen = False Then
Me.MSComm1.Settings = "115200,n,8,1"
Me.MSComm1.PortOpen = True
End If
MSComm1.Output = "user=admin password=pass" & vbCr
MSComm1.Output = "get hsb.ini" & vbCr
Me.Text1.Text = Me.MSComm1.Input
End Sub
Me.Text1.Text 本应接受的字符串应该为[Home]
HsbUserID=hsb ProductID= HsbVersion= HsbType=1 NetworkType=0 IP=192.168.20.223 NETMASK=255.255.224.0 GATEWAY=192.168.10.254 DNS1=192.168.10.254 DNS2= BaudRate=
但是程序运行的时候有时候得到的是字符“Rate=”有时候就为空 请问是何原因?
...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
efengxu 2005-10-08
  • 打赏
  • 举报
回复
接收的字符跟发送的字符的多少有什么关系?你只要写好oncomm事件就可以了!
domhuang 2005-10-08
  • 打赏
  • 举报
回复
MSComm1.Output = "user=admin password=pass" & vbCr
中间加点延时
MSComm1.Output = "get hsb.ini" & vbCr 这一句话也可以写在发送完毕的中断中 (要设置好oncomme时间)
weiweiplay 2005-10-08
  • 打赏
  • 举报
回复
或者在 MSComm1_OnComm 事件中写接收数据,我觉得应该是你的响应事件造成后面的来不及接收
weiweiplay 2005-10-08
  • 打赏
  • 举报
回复
MSComm1.Output = "get hsb.ini" & vbCr
'加一个延时看看
DoEvents

Me.Text1.Text = Me.MSComm1.Input
TBNTB 2005-10-06
  • 打赏
  • 举报
回复
幫頂

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧