gpt4 book ai didi

python - 在 pyvisa 中为串行端口的 write_ascii_values 分配值

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:30 26 4
gpt4 key购买 nike

我想从外部控制我的 Keithley 6485 皮安表,方法是通过 RS232toUSB 将它连接到我的 Linux PC (CentOS 6.9) 并使用 pyvisa 在 python(2.7.13 版)中编写代码:

#! /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 和 amm.write("*RST") 之后的错误消息: -113 未定义的 header 。所以我认为消息并没有正确传输。

我知道在 RS-232 接口(interface)上,只允许 ASCII 格式。但是当我按照 pyvisa instruction 中的示例进行操作时使用 write_ascii_values(text, values) 并为其分配一个列表,我只从设备收到一条错误消息 -100 命令错误。

有人可以告诉我如何正确设置 write_ascii_values 中的变量或者我做错了什么吗?我对串行设备的设置是否错误?有时,当我执行 2 次时,我会收到错误消息“VI_ERROR_ASRL_FRAMING (-1073807253):传输期间出现帧错误。”也。我只是不知道该怎么办。

谢谢!

问候,罗兰

最佳答案

SCPI 有几个协议(protocol)规则。希望我能指导您完成“查询”规则。

如果您向仪器查询,则必须读取缓冲区中的结果:

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

一旦您发送了“SYS:ERR:ALL?”仪器期待您读取结果。将其从写入命令转换为查询,否则以下命令将出错并且无法按预期执行:

amm.write("*RST")                               # Return 6485 to RST default 
print(amm.query_ascii_values("SYS:ERR:ALL?")) # Return error message
amm.write("TRIG:DEL 0") # Set trigger delay to zero seconds

操作完成命令也是如此:

print(amm.query_ascii_values("*OPC?"))          # operation complete query (synchronize completion of commands)

*OPC?上一个命令完成时将返回“1”。

关于python - 在 pyvisa 中为串行端口的 write_ascii_values 分配值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com