import pyvisa
import time
import csv
import os
os.add_dll_directory('C:\\Program Files\\Keysight\\IO Libraries Suite\\bin')
# Connect to PLZ205W
rm = pyvisa.ResourceManager()
plz = rm.open_resource("USB0::0x0B3E::0x1042::XF001985::0::INSTR")
# Optional: identify the device
print("Connected to:", plz.query("*IDN?").strip())
# Open a CSV file to store the log
with open("plz205w_log.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Timestamp", "Voltage (V)", "Current (A)"]) # Header
print("Logging started... Press Ctrl+C to stop.")
try:
while True:
voltage = float(plz.query("MEAS:VOLT?"))
current = float(plz.query("MEAS:CURR?"))
timestamp = time.time()
writer.writerow([timestamp, voltage, current])
print(f"{timestamp:.2f}: {voltage:.3f} V, {current:.3f} A")
time.sleep(0.5) # Log every 0.5 seconds
except KeyboardInterrupt:
print("Logging stopped by user.")
# Close the VISA connection
plz.close()