From 3686891a6dd43687855df9eb52710df94dd48a45 Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Sat, 5 Dec 2020 15:16:29 +0100 Subject: [PATCH] Prepared tests with one device - added functions for status print - renamed Testing1.py to example2.py - prepared test master script --- One_Unit_Test.py | 55 ++++++++++++++++++++++++++++++++++++++ cage_func.py | 29 +++++++++++++++++--- Testing1.py => example2.py | 0 pyps2000b/PS2000B.py | 10 ++++++- 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 One_Unit_Test.py rename Testing1.py => example2.py (100%) diff --git a/One_Unit_Test.py b/One_Unit_Test.py new file mode 100644 index 0000000..e6a1c6d --- /dev/null +++ b/One_Unit_Test.py @@ -0,0 +1,55 @@ +# import platform +import time as t +import numpy as np +import globals as g +import cage_func as func +from pyps2000b import PS2000B + +# User Inputs/Configuration---------------------------------- +Test1 = 0 +Test2 = 0 +Test3 = 0 +Test4 = 0 + +# Constants: +g.Coil_const = np.array([38.6, 38.45, 37.9])*1e-9 # Coil constants [x,y,z] in T/A +g.ambientField = np.array([80])*1e-6 # ambient magnetic field in measurement area, to be cancelled out + +# COM-Ports for power supply units: +xPort = "COM7" # placeholder +g.xDevice = PS2000B.PS2000B(xPort) + +func.print_status(g.xDevice) +t.sleep(3) + +g.xDevice.enable_all() +func.print_status(g.xDevice) +t.sleep(3) + +if Test1 == 1: + g.xDevice.voltage1 = 5 + t.sleep(1) + func.print_status(g.xDevice) + t.sleep(5) + func.set_to_zero(g.xDevice) + +if Test2 == 1: + g.xDevice.current1 = 0.2 + t.sleep(1) + func.print_status(g.xDevice) + t.sleep(5) + func.set_to_zero(g.xDevice) + +if Test4 == 1: + func.set_axis_current(g.xDevice, 0.2) + t.sleep(1) + func.print_status(g.xDevice) + t.sleep(10) + func.set_to_zero(g.xDevice) + t.sleep(1) + +func.print_status(g.xDevice) + +g.xDevice.disable_all() + +func.print_status(g.xDevice) diff --git a/cage_func.py b/cage_func.py index 2c0b9f9..7231700 100644 --- a/cage_func.py +++ b/cage_func.py @@ -22,6 +22,27 @@ def deactivate_all(): # disables remote control and output on all PSUs and chan g.zDevice.disable_all() +def print_status(device): + print("Channel 1: %s, %0.2f V, %0.2f A" % (device.get_device_status_information(0), device.voltage1, device.current1)) + print("Channel 2: %s, %0.2f V, %0.2f A" % (device.get_device_status_information(1), device.voltage1, device.current1)) + + +def print_status_3(): + print("X-Axis:") + print_status(g.xDevice) + print("Y-Axis:") + print_status(g.yDevice) + print("Z-Axis:") + print_status(g.zDevice) + + +def set_to_zero(device): + device.voltage1 = 0 + device.current1 = 0 + device.current2 = 0 + device.current2 = 0 + + def set_field_simple(vector): # forms magnetic field as specified by vector, w/o cancelling ambient field i_vec = vector/g.Coil_const set_current_vec(i_vec) @@ -34,12 +55,12 @@ def set_field(vector): # forms magnetic field as specified by vector, corrected def set_current_vec(i_vec): # sets needed currents on each axis for given vector - set_current(g.xDevice, i_vec[0]) - set_current(g.yDevice, i_vec[1]) - set_current(g.zDevice, i_vec[2]) + set_axis_current(g.xDevice, i_vec[0]) + set_axis_current(g.yDevice, i_vec[1]) + set_axis_current(g.zDevice, i_vec[2]) -def set_current(device, value): # sets current with correct polarity on one axis +def set_axis_current(device, value): # sets current with correct polarity on one axis # ToDo: Check behaviour with only current or only voltage set # ToDo: Check behaviour when trying to set too high currents if value > 0: diff --git a/Testing1.py b/example2.py similarity index 100% rename from Testing1.py rename to example2.py diff --git a/pyps2000b/PS2000B.py b/pyps2000b/PS2000B.py index 60e4463..1df26fe 100644 --- a/pyps2000b/PS2000B.py +++ b/pyps2000b/PS2000B.py @@ -195,7 +195,15 @@ class DeviceStatusInformation: self.actual_current_percent = float(as_word(raw_data[4:6])) / 256 def __str__(self): - return "Remote control active: %s, Output active: %s" % (self.remote_control_active, self.output_active) + if self.remote_control_active == 1: + remote = "active" + else: + remote = "inactive" + if self.output_active == 1: + output = "active" + else: + output = "inactive" + return "Remote control %s, Output %s" % (remote, output) class PS2000B: