我想通过 RS232toUSB 将我的 Keithley 6485 皮安表连接到我的 Linux PC(CentOS 6.9)并使用 pyvisa 在 python(2.7.13 版)中编写代码,从而从外部控制我的 Keithley 6485 Picoammeter:
#! /usr/local/bin/python2.7
import sys
import visa
from visa import constants
rm = visa.ResourceManager('/usr/local/vxipnp/linux/lib64/libvisa.so')
#open serial connection and set baud to 9600, 8 data bits, CR termination, one stop bit, none parity, no flow control
amm = rm.open_resource('ASRL2::INSTR', baud_rate = 9600, data_bits = 8, write_termination= '\r', read_termination = '\r')
constants.VI_ASRL_STOP_ONE
constants.VI_ASRL_PAR_NONE
constants.VI_ASRL_FLOW_NONE
amm.write("*RST") # Return 6485 to RST default
amm.write("SYS:ERR:ALL?") # Return error message
amm.write("TRIG:DEL 0") # Set trigger delay to zero seconds
amm.write("TRIG:COUNT 2500") # Set trigger count to 2500
amm.write("SENS:CURR:RANG:AUTO OFF") # Turn auto range off
amm.write("SENS:CURR:NPLC .01") # Set integration rate to NPLC 0.01
amm.write("SENS:CURR:RANG 2e-7") # Use 200 nA range
amm.write("SYST:ZCH OFF") # Turn zero check off
amm.write("SYST:AZER:STAT OFF") # Turn auto zero off
amm.write("DISP:ENAB OFF") # Turn Display off
amm.write("*CLS") # Clear status model
amm.write("TRAC:POIN 2500") # Set buffer size to 2500
amm.write("TRAC:CLE") # Clear buffer
amm.write("TRAC:FEED:CONT NEXT") # Set storage control to start on next reading
amm.write("STAT:MEAS:ENAB 512") # Enable buffer full measurement event
amm.write("*SRE 1") # Enable SRQ on buffer full measurement event
amm.write("*OPC?") # operation complete query (synchronize completion of commands)
amm.write("INIT") # start taking and storing readings wait for GPIB SRQ line to go true
amm.write("DISP:ENAB ON") # Turn display on
print(amm.query_ascii_values("TRAC:DATA?")) # Request data from buffer
当我运行这个脚本时的问题我只是得到“1”作为打印输出,虽然它应该像这样以 ASCII 格式返回:Reading, Timestamp, Status and the error message after amm.write("*RST"): -113未定义的标头。所以我认为消息并没有正确传输。
我知道通过 RS-232 接口,只允许使用 ASCII 格式。但是当我按照pyvisa 指令中的示例使用 write_ascii_values(text, values) 并为其分配一个列表时,我只收到来自设备 -100 命令错误的错误消息。
有人可以告诉我如何正确设置 write_ascii_values 中的变量或我做错了什么吗?我对串行设备的设置是否错误?有时当我执行 2 次时,我会收到错误“VI_ERROR_ASRL_FRAMING (-1073807253): A framing error occurred during transfer ”。也。我只是不知道该怎么办。
谢谢!
问候, 罗兰