RS232c VB6 帮助

发布于 2024-10-03 22:41:30 字数 611 浏览 5 评论 0原文

大家好,我正在尝试使用 VB6 comm32 通过 RS232 命令打开 A/V 接收器。要打开它,它说要使用:

 Command code   Parameter code  CR    Code set example
 PW           ON              <CR>  PWON<CR>

这是我当前正在使用的 VB6 代码,但似乎不起作用...

MSComm.CommPort = 2
MSComm.Settings = "9600,n,8,1"
MSComm.PortOpen = True

If Not MSComm.PortOpen Then
    MsgBox "not opened"
Else
    MSComm.Output = "PWON" & Chr(13)

    Do While MSComm.InBufferCount > 0
         Text1.Text = Text1.Text & MSComm.Input
    Loop
End If

接收器永远不会打开。我可能做错了什么?我检查了一下以确保 com 端口是 2,确实如此。

大卫

Hey all, i am trying to turn on a A/V Reciever with a RS232 command using the VB6 comm32. To turn it on it says to use:

 Command code   Parameter code  CR    Code set example
 PW           ON              <CR>  PWON<CR>

And this is my VB6 code i am currently using that doesnt seem to work...

MSComm.CommPort = 2
MSComm.Settings = "9600,n,8,1"
MSComm.PortOpen = True

If Not MSComm.PortOpen Then
    MsgBox "not opened"
Else
    MSComm.Output = "PWON" & Chr(13)

    Do While MSComm.InBufferCount > 0
         Text1.Text = Text1.Text & MSComm.Input
    Loop
End If

The reciever never turns on. What could i be doing incorrectly? I checked to make sure the com port was 2 and it is.

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2024-10-10 22:41:30

您只是发送字符 而不是真正的回车符(ASCII 代码 13)。串行外设的文档通常将控制字符的名称放在括号中(请参阅维基百科以获取控制字符列表)。您需要该行:

MSComm.Output = "PWON" & Chr(13)

似乎还应该更改随后从串行端口读取数据的代码,因为如果数据尚未到达串行端口的缓冲区,则它将不会读取任何内容。查看 Microsoft 的示例如何做到这一点。一旦找到输入中的特定子字符串、读取了一定数量的字节(Len 函数)等,您可以决定停止读取。

You are just sending the characters <CR> rather than a real carriage return (ASCII code 13). Documentation for serial peripherals often puts the names of control characters in brackets (see Wikipedia for a list of them). You need the line:

MSComm.Output = "PWON" & Chr(13)

It also seems that the code that follows to read data from the serial port should be changed because if the data has not arrived in the serial port's buffer yet, it will read nothing. Take a look at Microsoft's example for how to do so. You could decide to stop reading once a particular substring in the input has been found, once a certain number of bytes have been read (Len function), etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文