串行口能发送数据,但读取不到

tothehell tothehell 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
能给下位机发送命令,但读取不到数据
用串口调试助手也如此

代码如下:


Private Sub Command1_Click()

Dim sts As String

If MSComm1.PortOpen = False Then MSComm1.PortOpen = True 'open the line

Call CMD_SEND("WRSTA") 'OK!下位机可以启动
Call STS_RD(sts) '读不进来数据, STS=""

If sts = "OK" Then Text1.Text = "Start Measurement"

End Sub
Private Sub CMD_SEND(send_cmd As String)

Dim d$

d$ = send_cmd + Chr$(13)
MSComm1.Output = d$

End Sub
Private Sub STS_RD(ByRef status As String)

Dim a$, b$, d$
Dim L As Integer

Do
DoEvents
'Text1.Text = Text1.Text + "before input"
a$ = MSComm1.Input
'Text1.Text = Text1.Text + "after input"
b$ = Right(a$, 1)
d$ = d$ + a$
Loop Until (b$ = Chr$(13)) '陷入死循环

L = Len(d$)
status = Mid$(d$, 1, L - 1)

End Sub
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
tothehell
控件 1,453 成员 41,351 内容