1

我正在尝试使用 pyvisa 控制 AG34970a 插槽 3 中的 gp-switch 卡。

当我在控制台中输入它时。

dac.write("ROUTe:CLOSe (@301,302,303,304,305,306,307,308)")

开关正常安静运行,控制台输出

(48L, <StatusCode.success: 0))

我的设备名为 dac。

但是当我尝试使用字符串变量时,控制台中的响应是相同的,但仪器会发出哔哔声并且不会关闭开关。设备上的错误代码是错误 103,我认为这意味着分隔符无效,但由于一个有效,我不明白为什么另一个不能。

switch_str = '"ROUTe:CLOSe (@301,302,303,304,305,306,307,308)"'
dac.write(switch_str)

不能将变量与 .write 命令结合使用吗?

我想到了。好吧。当我在将字符串传递给设备之前连接我的字符串时,无论出了什么问题。我最终对写入命令的部分进行了更明确的处理,这些部分将保持不变,并且只传入要关闭的通道列表。我仍然不确定为什么它以前不起作用,但现在可以了。感谢你的帮助。

fields = ['301', '302', '303', '304', '305', '306', '307']

voltage = dac.query_ascii_values('MEAS:VOLT:DC? AUTO,DEF,(@101:107)')
               #convert the resulting voltage values into floats
    flvolts=[float(i) for i in voltage]
               #create a dictionary with the fields and corresponding voltage values
     dictionary=dict(zip(fields, flvolts))
               #evaluate the voltage list to determine the lowest value
     minval = min(flvolts)
               #produce a list of gp-switch channels that need to be closed to get cells balanced
               #targetval was created further up.  initially it is the same as minval but minval can
               #change.  Targetval shouldn’t
     switch_list=({k for (k,v) in dictionary.items() if v >= targetval})
               #begin generating the string to be sent to the device by converting the floats to strings
     str_list=[str(i) for i in switch_list]
               #Set up an empty list
     formatted_str_list=""
               #Format str_list into a string of comma separated numbers.
     for i in str_list:
          formatted_str_list += str(i) + ","     
               #instruct the device to close the channels that need drained
               #because they are higher than the minval
     dac.write("ROUTe:CLOSe (@" + formatted_str_list + "308)")
4

1 回答 1

0

尝试只用单引号或双引号而不是两者都包含字符串。它可能会告诉您 " 不是有效的分隔参数 (: , ;)。

于 2018-10-06T18:37:13.767 回答