(这可能是论坛发错了,所以我在 GitHub 上发起了一个问题:https ://github.com/pyvisa/pyvisa/issues/254 )
我尝试通过在 python 中使用 GPIB 来控制 Keithley 仪器。基本上通信是有效的,但是当从仪器读取时,字符经常被破坏。例如:
rm = visa.ResourceManager()
inst = rm.open_resource('GPIB0::5::INSTR')
inst.write_termination = '\n'
inst.ask('*IDN?')
给
'[EYTXLUY0I^STRUMUNTS0I^C>,]OTE\\ 2306,1178362,B16 /B02 \n'
National Instruments VISA 测试面板中的相同看起来是这样的:
3: Write Operation (*IDN?\n)
Return Count: 6 bytes
4: Read Operation
Return Count: 57 bytes
KEITHLEY INSTRUMENTS INC.,MODEL 2306,1178362,B16 /B02 .
当我签入 NI I/O Trace 时,这两个调用看起来很相似:
NI测试面板:
3. viWrite (GPIB0::5::INSTR (0x01FBD908), "*IDN?.", 6, 6)
Process ID: 0x000013E0 Thread ID: 0x00001390
Start Time: 12:57:52.691 Call Duration 00:00:00.022
Status: 0 (VI_SUCCESS)
4. viRead (GPIB0::5::INSTR (0x01FBD908), "KEITHLEY INSTRUMENTS ...", 1024, 57)
Process ID: 0x000013E0 Thread ID: 0x00001390
Start Time: 12:57:52.892 Call Duration 00:00:00.028
Status: 0 (VI_SUCCESS)
Python:
5. viWrite (GPIB0::5::INSTR (0x02B67068), "*IDN?.", 6, 6)
Process ID: 0x0000017C Thread ID: 0x000007AC
Start Time: 10:27:22.794 Call Duration 00:00:00.013
Status: 0 (VI_SUCCESS)
6. viRead (GPIB0::5::INSTR (0x02B67068), "[EYTXLUY0I^STRUMUNTS0...", 20480, 57)
Process ID: 0x0000017C Thread ID: 0x000007AC
Start Time: 10:27:22.808 Call Duration 00:00:00.020
Status: 0 (VI_SUCCESS)
有人有想法吗?
py -m visa info
Machine Details:
Platform ID: Windows-7-6.1.7601-SP1
Processor: x86 Family 6 Model 42 Stepping 7, GenuineIntel
Python:
Implementation: CPython
Executable: C:\Users\vos\AppData\Local\Programs\Python\Python36-32\python.exe
Version: 3.6.0
Compiler: MSC v.1900 32 bit (Intel)
Bits: 32bit
Build: Dec 23 2016 07:18:10 (#v3.6.0:41df79263a11)
Unicode: UCS4
PyVISA Version: 1.8
Backends:
ni:
Version: 1.8 (bundled with PyVISA)
#1: C:\Windows\system32\visa32.dll:
found by: auto
bitness: 32
Vendor: National Instruments
Impl. Version: 15728640
Spec. Version: 5243904
#2: C:\Windows\system32\visa32.dll:
found by: auto
bitness: 32
Vendor: National Instruments
Impl. Version: 15728640
Spec. Version: 5243904
python中的其他命令:
>>> inst.ask(':FETC?')
'+4.99963273E+00\n'
似乎是正确的,但这不是:
>>> inst.ask(':FETC:ARR?')
';4>99964076E;00,;4>99963733E;00,;4>99963424E;00,;4>99962772E;00,+4.99962361E+00\n'
从 NI VISA 交互控制中进行比较:
1: Write Operation (:FETC?)
Return Count: 6 bytes
2: Read Operation
Return Count: 16 bytes
+4.99963273E+00\n
3: Write Operation (:FETC:ARR?)
Return Count: 10 bytes
4: Read Operation
Return Count: 80 bytes
+4.99964076E+00,+4.99963733E+00,+4.99963424E+00,+4.99962772E+00,
+4.99962361E+00\n