4 See documentation for brainstem here: 5 https://acroname.com/reference/python/index.html 11 if __name__ ==
'__main__':
12 import os, sys, getopt
14 ourname = os.path.basename( sys.argv[0] )
15 print(
'Syntax: acroname [options]' )
16 print(
' Control the acroname USB hub' )
18 print(
' --recycle Recycle all ports' )
21 opts,args = getopt.getopt( sys.argv[1:],
'',
22 longopts = [
'help',
'recycle' ])
23 except getopt.GetoptError
as err:
33 except ModuleNotFoundError:
34 log.w(
'No acroname library is available!' )
44 super().
__init__( self, message
or 'no Acroname module found' )
49 Return all Acroname module specs in a list. Raise NoneFoundError if one is not found! 52 log.d(
'discovering Acroname modules ...' )
56 specs = brainstem.discover.findAllModules( brainstem.link.Spec.USB )
69 Connect to the hub. Raises RuntimeError on failure 74 hub = brainstem.stem.USBHub3p()
82 result = hub.connectFromSpec( spec )
83 if result != brainstem.result.Result.NO_ERROR:
84 raise RuntimeError(
"failed to connect to acroname (result={})".format( result ))
86 log.d(
'connected to', spec )
106 :return: a list of all ports currently occupied (and enabled) 109 for port
in range(8):
111 occupied_ports.append( port )
112 return occupied_ports
120 if port < 0
or port > 7:
121 raise ValueError(
"port number must be [0-7]" )
124 status = hub.usb.getPortState( port )
126 if status.value == 0:
128 if status.value == 11:
129 return "Disconnected" 130 if status.value > 100:
132 return "Unknown Error ({})".format( status.value )
135 def enable_ports( ports = None, disable_other_ports = False, sleep_on_change = 0 ):
137 Set enable state to provided ports 138 :param ports: List of port numbers; if not provided, enable all ports 139 :param disable_other_ports: if True, the ports not in the list will be disabled 140 :param sleep_on_change: Number of seconds to sleep if any change is made 141 :return: True if no errors found, False otherwise 146 for port
in range(0, 8):
148 if ports
is None or port
in ports:
150 action_result = hub.usb.setPortEnable( port )
151 if action_result != brainstem.result.Result.NO_ERROR:
156 elif disable_other_ports:
158 action_result = hub.usb.setPortDisable( port )
159 if action_result != brainstem.result.Result.NO_ERROR:
164 if changed
and sleep_on_change:
166 time.sleep( sleep_on_change )
173 :param ports: List of port numbers 174 :return: True if no errors found, False otherwise 180 action_result = hub.usb.setPortDisable( port )
181 if action_result != brainstem.result.Result.NO_ERROR:
189 Disable and enable a port 190 :param timeout: how long to wait before re-enabling 191 :return: True if everything OK, False otherwise 199 time.sleep( timeout )
208 Set USB ports to USB2 216 for port
in portlist:
217 hub.usb.setSuperSpeedDataEnable( port )
218 hub.usb.setHiSpeedDataEnable( port )
219 hub.usb.setSuperSpeedDataDisable( port )
224 Set USB ports to support USB3 232 for port
in portlist:
233 hub.usb.setSuperSpeedDataEnable( port )
234 hub.usb.setHiSpeedDataEnable( port )
235 hub.usb.setHiSpeedDataDisable( port )
241 if port < 0
or port > 7:
242 raise ValueError(
"port number can be only within 0 and 7 (inclusive)")
245 micro_volt = hub.usb.getPortVoltage( port )
246 micro_curr = hub.usb.getPortCurrent( port )
247 volt = float(micro_volt.value) / 10.0 ** 6
248 amps = float(micro_curr.value) / 10.0 ** 6
255 Based on last two USB location index, provide the port number 257 acroname_port_usb_map = {(4, 4): 0,
266 return acroname_port_usb_map[(first_usb_index, second_usb_index)]
269 if __name__ ==
'__main__':
271 if opt
in (
'--recycle'):
def is_port_enabled(port)
def enable_ports(ports=None, disable_other_ports=False, sleep_on_change=0)
uvc_xu_option< int > super
def set_ports_usb3(portlist=None, timeout=100e-3)
def __init__(self, message=None)
def set_ports_usb2(portlist=None, timeout=100e-3)
def get_port_from_usb(first_usb_index, second_usb_index)
static std::string print(const transformation &tf)
def recycle_ports(portlist=None, timeout=2)