Initial commit
This commit is contained in:
commit
cfe805a5e7
|
@ -0,0 +1,142 @@
|
||||||
|
# Title: Python bindings for direct USB programming of the Mini-Circuits USB-SP4T-63
|
||||||
|
# Author: George 'Joj' Travers
|
||||||
|
#
|
||||||
|
# Reference: https://www.minicircuits.com/softwaredownload/Prog_Manual-Solid_State_Switch.pdf
|
||||||
|
|
||||||
|
def get_device_model(dev):
|
||||||
|
# Returns the Mini-Circuits part number of the connected switch
|
||||||
|
# command 40
|
||||||
|
name = ""
|
||||||
|
command = [40]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 40 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
|
||||||
|
for i in range(1, len(ret_arr)) :
|
||||||
|
if ret_arr[i] == 0 :
|
||||||
|
break
|
||||||
|
name += chr(ret_arr[i])
|
||||||
|
return name
|
||||||
|
|
||||||
|
def get_device_serial(dev):
|
||||||
|
# Returns the serial number of the connected switch
|
||||||
|
# command 41
|
||||||
|
serial = ""
|
||||||
|
command = [41]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 0x29 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
|
||||||
|
for i in range(1, len(ret_arr)) :
|
||||||
|
if ret_arr[i] == 0 :
|
||||||
|
break
|
||||||
|
serial += chr(ret_arr[i])
|
||||||
|
return serial
|
||||||
|
|
||||||
|
def set_sp4t_state(dev, port):
|
||||||
|
# Sets the state of the SP4T switch
|
||||||
|
# command 1-4
|
||||||
|
command = [port]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != port :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return port
|
||||||
|
|
||||||
|
def get_sp4t_state(dev):
|
||||||
|
# Returns the state of the SP4T switch
|
||||||
|
# command 15
|
||||||
|
command = [15]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 15 :
|
||||||
|
return f"Error: Invalid response: {ret_arr[0]}"
|
||||||
|
return ret_arr[1]
|
||||||
|
|
||||||
|
def get_firmware(dev):
|
||||||
|
# Returns the internal firmware version of the switch box
|
||||||
|
# command 99
|
||||||
|
command = [99]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 99 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return chr(ret_arr[5]) + chr(ret_arr[6])
|
||||||
|
|
||||||
|
def set_num_switching_steps(dev, steps):
|
||||||
|
# Sets the number of steps to be configured for the pre-defined switching sequence
|
||||||
|
# command 204_0
|
||||||
|
command = [204,0,steps]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 204 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return f"{steps} steps set"
|
||||||
|
|
||||||
|
def get_num_switching_steps(dev):
|
||||||
|
# Returns the number of steps in the switching sequence
|
||||||
|
# command 205_0
|
||||||
|
command = [205,0]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 205 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return f"Number of steps: {ret_arr[1]}"
|
||||||
|
|
||||||
|
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
|
||||||
|
# command 204_1
|
||||||
|
command = [204,1]
|
||||||
|
|
||||||
|
dev.write(0x01,command)
|
||||||
|
ret_arr = dev.read(0x81,64)
|
||||||
|
|
||||||
|
if ret_arr[0] != 205 :
|
||||||
|
return "Error: Invalid response"
|
||||||
|
return f"Number of steps: {ret_arr[1]}"
|
||||||
|
|
||||||
|
|
||||||
|
def get_switching_step(dev):
|
||||||
|
return
|
||||||
|
|
||||||
|
def set_switching_direction(dev):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def get_switching_direction(dev):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def set_num_switching_cycles():
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def get_num_switching_cycles():
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def set_switching_mode():
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def get_switching_mode():
|
||||||
|
return
|
||||||
|
|
||||||
|
def start_stop_switching_mode():
|
||||||
|
return
|
Loading…
Reference in New Issue