使用python脚本读取直流电源2280s-32-6仪器的buffer记录。
效果图:
前提:
1、配置2280s 配置网口使能。
2、电脑安装ni-visa pyvisa 使用此驱动。
def msg_func(self):
while True:
msg = self.msg_func_hd.get()
main_app_wdbg.info('rec msg:{}'.format(msg))
if msg[0] == MSG_ID_STOP:
return
elif msg[0] == MSG_ID_GET_POWER_2280_BUFFER://读取buffer请求
try:
self.power_2280s_handle = pyvisa.ResourceManager().open_resource(msg[1])
data1 = self.power_2280s_handle.query(msg[2])
file_name = './%s.csv'%(get_time1_str())
self.ui.lineEdit_14.setText(file_name)
head_list = ['时间','电流(A)','电压(V)']
with open(file_name,'w',newline='')as f:
f_csv = csv.writer(f)
f_csv.writerow(head_list)
temp = get_list(data1)
if temp != None:
f_csv.writerows(temp)
self.power_2280s_handle.close()
except Exception as e:
printf_except_info(e)
elif msg[0] == MSG_ID_GET_POWER_2280_BUFFER_CLEAR or \
msg[0] == MSG_ID_GET_POWER_2280_TRIGGER_SET or\
msg[0] == MSG_ID_GET_POWER_2280_TRIGGER or\
msg[0] == MSG_ID_GET_POWER_2280_OUT_CTRL:
try:
self.power_2280s_handle = pyvisa.ResourceManager().open_resource(msg[1])
data1 = self.power_2280s_handle.write(msg[2])
self.power_2280s_handle.close()
except Exception as e:
printf_except_info(e)
清除buffer操作:
self.msg_func_hd.put((MSG_ID_GET_POWER_2280_BUFFER_CLEAR, self.ui.comboBox_17.currentText(),':TRAC1:CLE;'))
获取buf指令:
self.msg_func_hd.put((MSG_ID_GET_POWER_2280_BUFFER, self.ui.comboBox_17.currentText(),':TRAC1:DATA? \"READ,SOUR,TST,MODE\";'))
控制buf输出功能:
def slot_power_out_ctrl(self):
try:
if self.ui.comboBox_17.currentText() == '刷新' or self.ui.comboBox_17.currentText() == '':
self.alarm('警告','未选择设备')
return
msg = ':OUTP:STAT %s,CH1'%(self.ui.comboBox_21.currentText())
self.msg_func_hd.put((MSG_ID_GET_POWER_2280_OUT_CTRL, self.ui.comboBox_17.currentText(), msg))
except Exception as e:
printf_except_info(e)
个人微信: wzdhh991
邮箱: wzd991@126.com
个人比较懒,CSDN更新缓慢,有相关问题可发邮箱或个人微信交流!