RS232c VB6 帮助
大家好,我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是发送字符
而不是真正的回车符(ASCII 代码 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: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.