Pyvisa RAW SOCKET 连接时Read Timeout 问题的解决

问题是这样的:我在使用R&S的HMP4040 DC power source, 使用R&S的RsvisaTester 或者NI MAX 都发现只能执行Write 无法执行 Read或者说执行Read的时候会出现Timeout的问题。

首先,HMP4040的LAN 只能通过RAW SOCKET的方式连接。而不能通过VXI-11或者Hi-SLIP。而RAW SOCKET的连接必须要定义termination character (终止字符),这是导致无法链接问题的一个原因。可以参考以下文档,内有详细说明。

https://cdn.rohde-schwarz.com.cn/pws/dl_downloads/dl_application/application_notes/1sl374/1SL374_0e.pdf

All VISA resource types corresponding to the 488.2 protocol do not need a termination character. The reason is that this protocol has its own way to deal with the end of a message text. This covers the following resource types:

- GPIB Instr

- TCPIP Instr

- USB Instr

- VXI Instr

Only when using e.g. these resource types you have to specify the termination character separately:

- TCPIP Socket (which we use in this example)

- Serial Instr

- USB Raw

VXI-11 的连接是以::inst0::INSTR 结尾的

Hi-SLIP的连接是以::hislip0::INSTR结尾的 

SOCKET连接是以::端口号::SOCKET结尾的

This is the most popular interface type to control instruments over the network. We decide between VXI-11 and a Hi-SLIP connection. Both protocols support GPIB-Emulation as well as the Message Exchange Protocol and Device Locking. However, there are some differences: While VXI-11 only supports IPv4 Hi SLIP is also able to use an IPv6 connection. Also, only HiSLIP (from 2.0 on) can be used to encrypt messages or for access authentication.

Typical ID strings are:

VXI-11: TCPIP::10.205.0.123::inst0::INSTR

Hi-SLIP: TCPIP::10.205.0.123::hislip0::INSTR


 

This happens because of missing correct termination while receiving. In the last response string we can see, that the answer arrived, but the Test Panel is waiting for 1024 Bytes (after "cnt=") and so it must end in a read operation error message as the number of Bytes is not reached within the timeout frame. If an adequate termination character would have been defined for these operations, it would override these expected number of characters as soon as a valid "end of transmission" character will be received.

解决办法如下:

在open_resource 之后增加两行代码

HMP4040 = rm.open_resource(TCPIP0::10.35.36.12::5025::SOCKET)

HMP4040.set_visa_attribute(visa.constants.VI_ATTR_TERMCHAR,0xa) \\ 定义0xa (\n)为终止符)

HMP4040.set_visa_attribute(visa.constants.VI_ATTR_TERMCHAR_EN,0x1) \\使能终止符

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值