我想通過RS232toUSB將它連接到我的Linux PC(CentOS 6.9)並使用pyvisa在python(版本2.7.13)中編寫代碼來從外部控制我的吉時利6485皮安計:在pyvisa中爲串行端口指定write_ascii_values的值
#! /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這樣被退回:閱讀,時間戳,狀態和之後的錯誤信息amm.write(「* RST」):-113未定義的頭文件。所以我認爲這些消息並沒有正確傳輸。
我知道通過RS-232接口,只允許ASCII格式。但是當我使用write_ascii_values(文本,值)跟隨pyvisa instruction中的示例並將其分配給列表時,我只從設備-100命令錯誤中收到錯誤消息。
有人可以請告訴我如何正確設置write_ascii_values中的變量,或者我做錯了什麼?我的串行設備設置是否錯誤?有時當我執行2次時,出現錯誤「VI_ERROR_ASRL_FRAMING(-1073807253):在傳輸過程中發生成幀錯誤。」太。我只是不知道該怎麼做。
謝謝!
問候, 羅蘭