使用VB通过串口与设备通信时出现问题 [英] Problem communicating to equipment via serial port using VB

查看:75
本文介绍了使用VB通过串口与设备通信时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用串行端口在Visual Basic(VB)中与设备(SRS的SR780)进行通信。我可以发送(写)但无法阅读。但是,我可以使用超级终端进行写入和读取而没有任何问题。



使用相同的VB代码和相同的计算机,我能够与另一台仪器通信(QCM200 ,来自同一家公司)通过串口。超级终端也适用于此仪器。我无法弄清楚会出现什么问题。



我使用的是Windows 7,64位。 Visual Studio社区版2013. .Net 4.6。



任何帮助表示赞赏。



最好的问候< br $>
S. Ramanathan



我尝试过:



我正在使用readline并且收到超时错误。增加重量时间没有帮助



我尝试使用readto(vbLf),然后用vbCr替换vbLF,然后用vbCrLf替换它们都没有帮助。

I am trying to communicate with an equipment (SR780 from SRS) using serial port, in Visual basic (VB). I can send (write) but am not able to read. However, I can write and read using hyperterminal without any problem.

Using the same VB code, and the same computer, I am able to communicate with another instrument (QCM200, from the same company) via serial port. Hyperterminal also works fine with this instrument. I am not able to figure out what can go wrong.

I am using Windows 7, 64 bit. Visual Studio community edition 2013. .Net 4.6.

Any help is appreciated.

Best Regards
S. Ramanathan

What I have tried:

I am using readline and am getting a timeout error. Increasing the weight time doesn't help

I tried using readto(vbLf),then replaced vbLF with vbCr, then with vbCrLf and none of them help.

推荐答案

因为它是一种乐器,我认为你想发送一个SCPI命令,然后在短时间内阅读回复。



要使SerialPort.ReadLine正常工作,响应必须包含一个终止字符,该终止字符等于属性SerialPort.NewLine设置的终止字符(默认为换行符)。

请阅读文档并检查仪器正在使用什么终止特性。



或者可能是仪器期望作为处理命令的特定终止字符。

同样的事情,请阅读通信。

如果仪器接受发送的命令,您还可以通过发送仪器上可见的命令进行检查,例如关闭显示器或类似的东西。 br />


在处理串口通信时,有一个名为PortMon的好工具。

PortMon将监控串口上发生的所有事情,在这种情况下非常有用。

这是一个免费工具,你可以在这里下载:适用于Windows的Portmon [ ^ ]



使用PortMon,您可以比较使用HyperTerminal(它可以工作)与您自己的应用程序时发送的数据(并且它不起作用)。
As it is an instrument I presume you want to send a SCPI command and then read the response within a short time.

For SerialPort.ReadLine to work, the response must contain a termination character equal to the one set by the property SerialPort.NewLine (default is Line Feed).
So read the documentation and check what termination character the instrument is using.

Or it could be that the instrument is expecting as specific termination character to process a command.
Same thing, read the communication.
If the instrument accepts the command sent, you can also check by sending a command that is visibly detectable on the instrument, such as turning off the display or something similar.

When dealing with serial port communication, there is a nice tool called PortMon.
PortMon will monitor everything that is happening on the serial port and is very useful in this kind of situations.
It is a free tool and you can download it here: Portmon for Windows[^]

Using PortMon you can compare what data is sent when you are using HyperTerminal (and it works) with your own application (and it doesn't work).


这篇关于使用VB通过串口与设备通信时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆