问题是这样的:我在使用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 (终止字符),这是导致无法链接问题的一个原因。可以参考以下文档,内有详细说明。
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) \\使能终止符