import time
import pyvisa
import serial
import ArduinoCtrl
# arduino 引脚连接
#测试步数
TestStep=64
# 打开串口
Arduino=serial.Serial('COM14', 9600,timeout=1)
# 延时3s初始化串口时间
time.sleep(3)
rm = pyvisa.ResourceManager()
# 打印设备列表
print(rm.list_resources())
# 打开电源
E_Source=rm.open_resource('R')
# 打开THD2015万用表
Thd2015=rm.open_resource('GPIB0::4::INSTR')
#查询设备信息
print(Thd2015.query("*IDN?"))
while TestStep>0:
#给ARDUINO 发送数字,以\n作为结尾
ArduinoCtrl.send_commend(Arduino,str(TestStep)+'\n')
time.sleep(2)
# 延时2s后测量直流电压
print(Thd2015.query("MEAS:VOLT:DC?"))
# 测量电源电流
E_Source_Current = E_Source.query("MEASure:CURRent? P25V")
print("Esource-Current:"+str(E_Source_Current)+"\r\n")
TestStep-=1
#测试延时2S
time.sleep(1)
#关闭串口
Arduino.close()
#arduinoctrl.py文件
def send_commend(dev,commend=''):
dev.write(commend.encode('utf-8'))
return read_back(dev)
#串口通讯,获取返回信息。
def read_back(dev):
temp=dev.readline()
# temp=dev.read(400)
# 打印返回值
print(temp)
return temp.decode('utf-8')
# 发送数据
目的就是,上位机给arduino 发送一个数字,然后arduino 根据这个数字改变io的状态,改变完io状态后,再去回读输出结果
从而达到真值表扫描的目的。
实物图如上