Finished adding commands
This commit is contained in:
parent
971ded8b1f
commit
1eab463c48
|
@ -0,0 +1,16 @@
|
||||||
|
# errata
|
||||||
|
|
||||||
|
* In the function 'get_switching_step()', the documentation of the relevant command (Get Step 205_1 on p54) states that the returned array is 6 bytes long in the format
|
||||||
|
* [0] = '205'
|
||||||
|
* [1] = step_index
|
||||||
|
* [2] = swtich_state
|
||||||
|
* [3] = dwell_0
|
||||||
|
* [4] = dwell_1
|
||||||
|
* [5] = dwell_units
|
||||||
|
* This arrangement is incorrect, at least for firmware version 'A3' which is all I have access to. The actual returned array is as follows:
|
||||||
|
* [0] = '205'
|
||||||
|
* [2] = swtich_state
|
||||||
|
* [3] = dwell_0
|
||||||
|
* [4] = dwell_1
|
||||||
|
* [5] = dwell_units
|
||||||
|
* This means that from the returned array alone the relevant step cannot be determined
|
121
SP4T.py
121
SP4T.py
|
@ -2,6 +2,9 @@
|
||||||
# Author: George 'Joj' Travers
|
# Author: George 'Joj' Travers
|
||||||
#
|
#
|
||||||
# Reference: https://www.minicircuits.com/softwaredownload/Prog_Manual-Solid_State_Switch.pdf
|
# Reference: https://www.minicircuits.com/softwaredownload/Prog_Manual-Solid_State_Switch.pdf
|
||||||
|
#
|
||||||
|
# command data is sent and recieved in decimal for some reason, don't ask why idk
|
||||||
|
# ex: command 205_1 refers to the first two bytes sent in the 64-byte transmit array
|
||||||
|
|
||||||
def get_device_model(dev):
|
def get_device_model(dev):
|
||||||
# Returns the Mini-Circuits part number of the connected switch
|
# Returns the Mini-Circuits part number of the connected switch
|
||||||
|
@ -102,41 +105,123 @@ def get_num_switching_steps(dev):
|
||||||
def set_switching_step(dev, step_index, switch_state, dwell_0, dwell_1, dwell_units):
|
def set_switching_step(dev, step_index, switch_state, dwell_0, dwell_1, dwell_units):
|
||||||
# Configures the state and dwell time of a single step within the pre-defined switching sequence
|
# Configures the state and dwell time of a single step within the pre-defined switching sequence
|
||||||
# command 204_1
|
# command 204_1
|
||||||
command = [204,1]
|
command = [204,1,step_index,switch_state,dwell_0,dwell_1,dwell_units]
|
||||||
|
|
||||||
dev.write(0x01,command)
|
dev.write(0x01,command)
|
||||||
ret_arr = dev.read(0x81,64)
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return "Switching step configured"
|
||||||
|
|
||||||
|
def get_switching_step(dev, step_index):
|
||||||
|
# Returns the state and dwell time of a single step within the pre-defined switching sequence
|
||||||
|
# command 205_1
|
||||||
|
command = [205,1,step_index]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
if ret_arr[0] != 205 :
|
if ret_arr[0] != 205 :
|
||||||
return "Error: Invalid response"
|
return "Error: Invalid response"
|
||||||
return f"Number of steps: {ret_arr[1]}"
|
return ret_arr[:5]
|
||||||
|
|
||||||
|
def set_switching_direction(dev, direction):
|
||||||
|
# Sets the direction in which the sequence of switch states which will be executed
|
||||||
|
# command 204_2
|
||||||
|
command = [204,2,direction]
|
||||||
|
|
||||||
def get_switching_step(dev):
|
dev.write(0x01,command)
|
||||||
return
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
def set_switching_direction(dev):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return "Switching direction configured"
|
||||||
|
|
||||||
def get_switching_direction(dev):
|
def get_switching_direction(dev):
|
||||||
return
|
# Returns the direction in which the sequence of switch states will be executed
|
||||||
|
# command 205_2
|
||||||
|
command = [205,2]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 205 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
|
||||||
|
if ret_arr[1] == 0 :
|
||||||
|
return "Forward"
|
||||||
|
elif ret_arr[1] == 1 :
|
||||||
|
return "Reverse"
|
||||||
|
elif ret_arr[1] == 2 :
|
||||||
|
return "Bi_Directional"
|
||||||
|
else :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
|
||||||
|
def set_num_switching_cycles(dev, cycles_0, cycles_1):
|
||||||
|
# Sets the number of times that the complete switching sequence will be executed
|
||||||
|
# This setting will beignored if the switch sequence has been configured to execute in continuous mode
|
||||||
|
# command 204_4
|
||||||
|
command = [204,4,cycles_0,cycles_1]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return "Switching cycles configured"
|
||||||
|
|
||||||
|
|
||||||
def set_num_switching_cycles():
|
def get_num_switching_cycles(dev):
|
||||||
return
|
# Returns the number of times that the complete switching sequence will be executed
|
||||||
|
# This setting will be ignored if the switch sequence has been configured to execute in continuous mode
|
||||||
|
# command 205_4
|
||||||
|
command = [205,4]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
def get_num_switching_cycles():
|
if ret_arr[0] != 205 :
|
||||||
return
|
return "Error: Invalid response"
|
||||||
|
return ret_arr[:3]
|
||||||
|
|
||||||
|
def set_switching_mode(dev, mode):
|
||||||
|
# Configures whether the switch sequence will be executed continuously or for a pre-defined number of cycles
|
||||||
|
# With continuous mode enabled, the sequence will repeat from the time the sequence is enabled by the user until the time it is disabled by the user; the setting for number of cycles will be ignored
|
||||||
|
# With continuous mode disabled the sequence will repeat according to the setting for number of cycle
|
||||||
|
# command 204_3
|
||||||
|
command = [204,3, mode]
|
||||||
|
|
||||||
def set_switching_mode():
|
dev.write(0x01,command)
|
||||||
return
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return "Switching mode set"
|
||||||
|
|
||||||
def get_switching_mode():
|
def get_switching_mode(dev):
|
||||||
return
|
# Indicates whether or not the switching sequence is configured to operate in continuous mode
|
||||||
|
# With continuous mode enabled, the sequence will repeat from the time the sequence is enabled by the user until the time it is disabled by the user; the setting for number of cycles will be ignored
|
||||||
|
# With continuous mode disabled the sequence will repeat according to the setting for number of cycles.
|
||||||
|
# command 205_3
|
||||||
|
command = [205,3]
|
||||||
|
|
||||||
def start_stop_switching_mode():
|
dev.write(0x01,command)
|
||||||
return
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 205 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return f"Continuous mode: {ret_arr[1]}"
|
||||||
|
|
||||||
|
def start_stop_switching_mode(dev, mode):
|
||||||
|
# Starts or stops the pre-defined switching sequence
|
||||||
|
# The sequence will not operate unless all required parameters have been configured correctly
|
||||||
|
# command 204_5
|
||||||
|
command = [204,5,mode]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return "Switching sequence set"
|
|
@ -0,0 +1,47 @@
|
||||||
|
import usb.core, usb.util
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# import bindings from directory above example folder
|
||||||
|
sys.path.append('../')
|
||||||
|
from SP4T import *
|
||||||
|
|
||||||
|
# connect to USB device
|
||||||
|
dev = usb.core.find(idVendor=0x20ce, idProduct=0x0022)
|
||||||
|
|
||||||
|
if dev is None:
|
||||||
|
print("sad")
|
||||||
|
raise ValueError('Device not found')
|
||||||
|
|
||||||
|
|
||||||
|
for configuration in dev:
|
||||||
|
for interface in configuration:
|
||||||
|
ifnum = interface.bInterfaceNumber
|
||||||
|
if not dev.is_kernel_driver_active(ifnum):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
dev.detach_kernel_driver(ifnum)
|
||||||
|
except {usb.core.USBError, e}:
|
||||||
|
pass
|
||||||
|
|
||||||
|
#set device config
|
||||||
|
dev.set_configuration()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# testing bindings
|
||||||
|
print(get_device_model(dev))
|
||||||
|
|
||||||
|
print(get_device_serial(dev))
|
||||||
|
|
||||||
|
print(get_sp4t_state(dev))
|
||||||
|
print(set_sp4t_state(dev, 4))
|
||||||
|
|
||||||
|
print(get_sp4t_state(dev))
|
||||||
|
print(get_firmware(dev))
|
||||||
|
|
||||||
|
print(get_num_switching_steps(dev))
|
||||||
|
print(set_num_switching_steps(dev, 10))
|
||||||
|
print(get_num_switching_steps(dev))
|
||||||
|
print(set_switching_step(dev, 1, 3, 0, 5, 0))
|
||||||
|
print(get_switching_step(dev, 1)) # returns step 1 switch settings
|
||||||
|
print(get_switching_direction(dev))
|
Loading…
Reference in New Issue