def PowerMeterConfig(): try: dev = finddev(idVendor=0x1313, idProduct=0x8072) dev.reset() print('Initializing PM100... ', end='') instr = usbtmc.Instrument(4883, 32882) global PowerMeter PowerMeter = ThorlabsPM100(inst=instr) try: print(instr.ask("*IDN?")) except usb.core.USBError: print('...Failed! Continuing to program without PM') global PMAbsent PMAbsent = True #Formatting CSV Files for Power Meter if it is present. csvWrite(PMDataFile, ("# PwrM Sample Time", "Power"), "a") csvWrite(PMInterpFile, ("# XMiss Sample Time", "PwrM Sample Time", "Power", "PwrM Interpolation"), "a") except Exception as Exc: print(Exc) print("Not connected to Power Meter.") PMAbsent = True
def reset_camera(): # reset realsense camera dev = finddev(idVendor=0x8086) if dev: dev.reset() print('camera has been reset...') else: sys_exit("Error: No USB devices detected")
def buy(inputs): import serial import time from usb.core import find as finddev dev = finddev(idVendor=0x1a86, idProduct=0x7523) dev.reset() time.sleep(4) ser = serial.Serial(port='/dev/ttyUSB0', baudrate=19200, timeout=5) print("Port " + ser.portstr + "opened:" + str(ser.isOpen())) ###print(inputs) tray_list = { "1": [0xFA, 0xF0, 0xE1, 0x02, 0x01, 0xD4], "2": [0xFA, 0xF0, 0xE1, 0x02, 0x02, 0xD5], "3": [0xFA, 0xF0, 0xE1, 0x02, 0x03, 0xD6], "4": [0xFA, 0xF0, 0xE1, 0x02, 0x04, 0xD7], "5": [0xFA, 0xF0, 0xE1, 0x02, 0x05, 0xD8], "6": [0xFA, 0xF0, 0xE1, 0x02, 0x06, 0xD9], "7": [0xFA, 0xF0, 0xE1, 0x02, 0x07, 0xDA], "8": [0xFA, 0xF0, 0xE1, 0x02, 0x08, 0xDB], "9": [0xFA, 0xF0, 0xE1, 0x02, 0x09, 0xDC], "10": [0xFA, 0xF0, 0xE1, 0x02, 0x00, 0xD3] } x = bytearray(tray_list[str(inputs)]) ser.flushInput() ser.flushOutput() ser.write(x) time.sleep(5) ser.close() time.sleep(1) dev.reset() time.sleep(2) print("pass")
def resetBlinkStick(): return print("resetting BlinkStick") dev = finddev(idVendor=0x20a0, idProduct=0x41e5) if dev is not None: logger.info("Resetting usb port after Blink Stick has been attached.") dev.reset() return True else: return False
def resetUSB(self, force_bus_reset=False): dev = finddev(idVendor=0x0084, idProduct=0x0041) # Reset device only if: # - The USB device is found # - The inverter state is offline # - It was previously exporting power if dev is not None and (self.inverter.runningInfo.pac > 0 or force_bus_reset): self.log.info('USB device port reset') dev.reset() time.sleep(1)
def ZeroPowerMeter(PMWavelength): dev = finddev(idVendor=0x1313, idProduct=0x807b) dev.reset() global instr instr = usbtmc.Instrument(4883, 32891) global PowerMeter PowerMeter = ThorlabsPM100(inst=instr) PowerMeter.sense.correction.wavelength = int(PMWavelength) PowerMeter.sense.correction.collect.zero.initiate() while PowerMeter.sense.correction.collect.zero.state: time.sleep(0.5)
def __init__(self): self.dev = finddev(idVendor=0x18d1, idProduct=0x4ee2) self.dev.reset() self.BANNER = "mobile" # KitKat+ devices require authentication #signer = sign_m2crypto.M2CryptoSigner( # op.expanduser('~/.android/adbkey')) # Connect to the device self.device = adb_commands.AdbCommands() self.device.ConnectDevice(banner=self.BANNER)
def isBlinkStickAttached(): try: dev = finddev(idVendor=ThisSystem.idVendor, idProduct=ThisSystem.idProduct) if dev is not None: #manufacturer = util.get_string(dev,256,1) #deviceDescription = util.get_string(dev,256,2) #deviceSerialNumber = util.get_string(dev,256,3) #print ("Manufacturer : " + manufacturer) #print ("Device Description : " + deviceDescription ) #print ("Device SerialNumber : " + deviceSerialNumber ) startup() logger.info("BlinkStick is attached") return True else: logger.info("BlinkStick is NOT attached.") return False except Exception as e: return False
def main(options): dev = finddev(idVendor=0x1608, idProduct=0x0305) warning = options.warning critical = options.critical port = options.port #try to open and read the serial port try: serialPort = serial.Serial(port, timeout=2) serialPort.write('H\r') serData = '' serData += serialPort.read_until() serialPort.close() except IOError: print("ERROR: Unable to read sensor. Is the port correct?") dev.reset() sys.exit(3) #if it returns nothing exit with unknown if (serData == ''): print("ERROR: Unable to read sensor. Is the port correct?") dev.reset() sys.exit(3) #regex to get the number humidity = int((re.search("[\d]+", serData)).group(0)) exitcode = 3 #set the exit code based on reading if (humidity >= warning and humidity < critical): exitcode = 1 print("WARNING: Humidity is at %s %%" % humidity) if (humidity >= critical): exitcode = 2 print("CRITICAL: Humidity is at %s %%" % humidity) if (humidity < warning): exitcode = 0 print("OK: Humidity is at %s %%" % humidity) #exit dev.reset() #Perfomance Data if (humidity <= 100): print("|humidity=%s;%s;%s;0;100\n" % (humidity, warning, critical)) sys.exit(exitcode)
def startAudioCaptureLinux(): global startAudioCounter audioEndpoint = getAudioEndpoint() audioHost = audioEndpoint['host'] audioPort = audioEndpoint['port'] # if a comma delimited list of rates is given, this # switches the rate each time this is called. for some reason this makes a C920 work more reliably # particularly on cornbot if ',' in robotSettings.audio_rate: rates = robotSettings.audio_rate.split(',') audioRate = int(rates[startAudioCounter % len(rates)]) startAudioCounter += 1 else: audioRate = int(robotSettings.audio_rate) audioDevNum = robotSettings.audio_device_number if robotSettings.audio_device_name is not None: audioDevNum = audio_util.getAudioRecordingDeviceByName( robotSettings.audio_device_name) if audioDevNum is None: raise Exception("the name doesn't exist" + robotSettings.audio_device_name) print((robotSettings.ffmpeg_path, audioRate, robotSettings.mic_channels, audioDevNum, audioHost, audioPort, robotSettings.stream_key)) #audioCommandLine = '%s -f alsa -ar 44100 -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 32k -muxdelay 0.001 http://%s:%s/%s/640/480/' % (robotSettings.ffmpeg_path, robotSettings.mic_channels, audioDevNum, audioHost, audioEndpoint['port'], robotSettings.stream_key) audioCommandLine = '%s -f alsa -ar %d -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 64k -muxdelay 0.01 http://%s:%s/%s/640/480/'\ % (robotSettings.ffmpeg_path, audioRate, robotSettings.mic_channels, audioDevNum, audioHost, audioPort, robotSettings.stream_key) print(audioCommandLine) if commandArgs.usb_reset_id != None: if len(commandArgs.usb_reset_id) == 8: vendor_id = int(commandArgs.usb_reset_id[0:4], 16) product_id = int(commandArgs.usb_reset_id[4:], 16) dev = finddev(idVendor=vendor_id, idProduct=product_id) dev.reset() #return subprocess.Popen(shlex.split(audioCommandLine)) return runAndMonitor("audio", shlex.split(audioCommandLine))
def __usb_reset(self): """ Sends the USB reset command. """ logger.debug('Attempting to reset USB.') err = self.__get_device() if err != self.USB_NOT_FOUND: try: dev = finddev(idVendor=0x04d8, idProduct=0x00dd) dev.reset() # After USB device is reset, must reinitialize USB handle # and set interrupts enabled flag before servicing any # future interface requests. err = self.initialize() if not err: err = self.__get_device() if not err: log = 'Device found, USB reset of Janus Interface succeeded.' logger.info(log) if not err: err = self.interrupts_enable() else: log = 'Device not found, USB reset of Janus Interface failed.' logger.critical(log) except usb.USBError: logger.critical('USB reset of Janus Interface failed.') else: logger.warning( 'Janus interface not found during attempted USB reset.') return err
def startAudioCaptureLinux(): audioEndpoint = getAudioEndpoint() audioHost = audioEndpoint['host'] audioPort = audioEndpoint['port'] audioDevNum = robotSettings.audio_device_number if robotSettings.audio_device_name is not None: audioDevNum = audio_util.getAudioDeviceByName( robotSettings.audio_device_name) #audioCommandLine = '%s -f alsa -ar 44100 -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 32k -muxdelay 0.001 http://%s:%s/%s/640/480/' % (robotSettings.ffmpeg_path, robotSettings.mic_channels, audioDevNum, audioHost, audioEndpoint['port'], robotSettings.stream_key) audioCommandLine = '%s -f alsa -ar %d -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 64k -muxdelay 0.01 http://%s:%s/%s/640/480/'\ % (robotSettings.ffmpeg_path, robotSettings.audio_rate, robotSettings.mic_channels, audioDevNum, audioHost, audioPort, robotSettings.stream_key) print(audioCommandLine) if commandArgs.usb_reset_id != None: if len(commandArgs.usb_reset_id) == 8: vendor_id = int(commandArgs.usb_reset_id[0:4], 16) product_id = int(commandArgs.usb_reset_id[4:], 16) dev = finddev(idVendor=vendor_id, idProduct=product_id) dev.reset() #return subprocess.Popen(shlex.split(audioCommandLine)) return runAndMonitor("audio", shlex.split(audioCommandLine))
from usb.core import find as finddev dev = finddev(idVendor=0x26ac, idProduct=0x0011) dev.reset()
#!/usr/bin/python3 from usb.core import find as finddev devices = finddev(find_all=1, idVendor=0x1366) for dev in devices: try: dev.reset() except: pass
from ThorlabsPM100 import ThorlabsPM100 import usbtmc import time import usb from usb.core import find as finddev dev = finddev(idVendor=0x1313, idProduct=0x8072) dev.reset() time.sleep(2) print('Initializing PM100... ', end='') instr = usbtmc.Instrument(4883, 32882) try: print(instr.ask("*IDN?")) except usb.core.USBError: print('...Failed! Exiting') sys.exit('ERROR: PM100 NOT DETECTED. TRY TURNING IT OFF AND ON AGAIN') #rm = visa.ResourceManager() #inst = rm.open_resource('USB0::0x0001::0x0007::13138072::INSTR', term_chars='\n', timeout=1) #Bus 001 Device 007: ID 1313:8072 #power_meter = ThorlabsPM100(inst=inst) #inst = USBTMC(instr) power_meter = ThorlabsPM100(inst=instr) #power_meter.configure.scalar.power() #pdensity() power_meter.configure.scalar.pdensity() power_meter.sense.average.count = 50 power_meter.system.beeper.immediate() power_meter.sense.power.dc.range.auto = "ON"
#!/usr/bin/python3 from usb.core import find as finddev from yamlio import read_yaml_all, SYSTEM_PATH # Change it according to user SYSTEM_YAML_PATH = "/home/sixfab/.core/system.yaml" temp = {} try: temp = read_yaml_all(SYSTEM_YAML_PATH) except Exception as e: exit(1) vendor_id = temp.get("modem_vendor_id", "") product_id = temp.get("modem_product_id", "") vendor_id_int = int(vendor_id, 16) product_id_int = int(product_id, 16) try: dev = finddev(idVendor=vendor_id_int, idProduct=product_id_int) dev.reset() except Exception as e: exit(1) else: exit(0)
#!/usr/bin/python from usb.core import find as finddev dev = finddev(idVendor=0x13d3, idProduct=0x3362) dev.reset()
#!/usr/bin/python # This script allows hard-resetting the Intel Wireless Bluetooth 8265 chip # (ID 8087:0a2b) built into newer Thinkpads which tends to get stuck as other # people noticed before: https://bbs.archlinux.org/viewtopic.php?id=193813 # Setup: pip install pyusb # Usage: sudo python reset.py from usb.core import find as finddev dev = finddev(idVendor=0x8087, idProduct=0x0a2b) dev.reset()
#!/usr/bin/python2.7 import freenect import cv2 import numpy as np import time from usb.core import find as finddev dev1 = finddev(idVendor=0x045e, idProduct=0x02ae) dev2 = finddev(idVendor=0x045e, idProduct=0x02b0) dev3 = finddev(idVendor=0x045e, idProduct=0x02ad) dev1.reset() dev2.reset() ctx = freenect.init() mdev = freenect.open_device(ctx, 0) freenect.shutdown(ctx) print(ctx) print(mdev) freenect.sync_stop() def applyCustomColorMap(im_gray): lut = np.zeros((256, 1, 3), dtype=np.uint8) lut[:, 0, 0] = [ 0, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 52, 49, 51, 0, 48, 48, 48, 46, 47, 47, 43, 45, 45, 45, 44, 44, 43, 43, 43, 0, 46, 45, 46, 45, 50, 50, 50, 51, 55, 56, 56, 56, 62, 61, 61, 0, 61, 68, 67, 67, 68, 73, 73, 73, 73, 78, 79,
#!/usr/bin/python from usb.core import find as finddev dev = finddev(idVendor=0xfc02, idProduct=0x0101) dev.reset()
def play_video(year): try: ser.write('-' + year + '/') ser.flush() print('-' + year + '/') try: if read_serial() == "READY": myprocess_.stdin.write('q') if year == "1927": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1927], stdin=subprocess.PIPE) check_halt(25) myprocess.stdin.write('q') if year == "1995": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1995], stdin=subprocess.PIPE) check_halt(20) myprocess.stdin.write('q') if year == "2013": myprocess = subprocess.Popen(['omxplayer', '-b -z', _2013], stdin=subprocess.PIPE) check_halt(15) myprocess.stdin.write('q') if year == "1980": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1980], stdin=subprocess.PIPE) check_halt(22) myprocess.stdin.write('q') if year == "1970": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1970], stdin=subprocess.PIPE) check_halt(15) myprocess.stdin.write('q') if year == "1998": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1998], stdin=subprocess.PIPE) check_halt(32) myprocess.stdin.write('q') if year == "1967": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1967], stdin=subprocess.PIPE) check_halt(17) myprocess.stdin.write('q') if year == "1928": myprocess = subprocess.Popen(['omxplayer', '-b -z', _1928], stdin=subprocess.PIPE) check_halt(132) myprocess.stdin.write('q') except: print "SERIAL PORT NOT READY TO READ!!!!" return except: print "LOST SERIAL PORT!!!!" try: myprocess.stdin.write('q') except: print "Main video not running!!!!" try: myprocess_.stdin.write('q') except: print "Transition video not running!!!!" try: print "Reseting Driver" dev = finddev(idVendor=0x10c4, idProduct=0xea60) dev.reset() ser.close() except: print "Failed to Reopen Driver" sleep(10) return
#!/usr/bin/python3 from usb.core import find as finddev #for hackrf dev = finddev(idVendor=0x1d50, idProduct=0x6089) dev.reset()