import pyvisa as visa
import time
import csv
if __name__ == '__main__' :
rm = visa.ResourceManager()
inst = rm.open_resource('')#这里填入自己的设备信息
# 定义CSV文件名称和列名
csv_filename = 'measurement_data_with_timestamp.csv'
fieldnames = ['Timestamp', 'Voltage', 'Current', 'Resistance', 'Power']
# 写入CSV文件头
with open(csv_filename, 'w', newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for count in range(100):
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) # 获取当前时间戳并格式化为字符串
voltage = inst.query(":MEASure:VOLTage:DC?").strip()[:-2]
current = inst.query(":MEASure:CURRent:DC?").strip()[:-2]
resistance = inst.query(":MEASure:RESistance:DC?").strip()[:-2]
power = inst.query(":MEASure:POWer:DC?").strip()[:-2]
print(timestamp,voltage,voltage,resistance,power)
# 将数据和时间戳写入CSV文件
with open(csv_filename, 'a', newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writerow({'Timestamp': timestamp, 'Voltage': voltage, 'Current': current, 'Resistance': resistance,'Power': power})
time.sleep(0.05)
# 关闭仪器和资源管理器
inst.close()
rm.close()
读取电子负载DL3021信息Python代码
于 2024-05-16 14:41:22 首次发布