Prepared tests with one device

- added functions for status print
- renamed Testing1.py to example2.py
- prepared test master script
This commit is contained in:
Martin Zietz
2020-12-05 15:16:29 +01:00
parent 0b15116fd9
commit 3686891a6d
4 changed files with 89 additions and 5 deletions
+55
View File
@@ -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)
+25 -4
View File
@@ -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:
View File
+9 -1
View File
@@ -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: