def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: try: btName = next(portInfo.get("bluetoothName","") for portInfo in hwPortUtils.listComPorts() if portInfo.get("port")==port) btPrefix = next(prefix for prefix in bluetoothPrefixes if btName.startswith(prefix)) tryPorts = ((port, "bluetooth", btPrefix),) except StopIteration: tryPorts = () for port, portType, identifier in tryPorts: self.isBulk = portType=="USB bulk" # Try talking to the display. try: if self.isBulk: # onReceiveSize based on max packet size according to USB endpoint information. self._dev = hwIo.Bulk(port, 0, 1, self._onReceive, writeSize=0, onReceiveSize=64) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue for i in xrange(3): self._sendCellCountRequest() # Wait for an expected response. if self.isBulk: # Hims Bulk devices sometimes present themselves to the system while not yet ready. # For example, when switching the connection mode toggle on the Braille EDGE from Bluetooth to USB, # the USB device is connected but not yet ready. # Wait ten times the timeout, which is ugly, but effective. self._dev.waitForRead(self.timeout*10) else: self._dev.waitForRead(self.timeout) if self.numCells: break if not self.numCells: log.debugWarning("No response from potential Hims display") self._dev.close() continue if portType=="USB serial": self._model = SyncBraille() elif self.isBulk: self._sendIdentificationRequests(usbId=identifier) elif portType=="bluetooth" and identifier: self._sendIdentificationRequests(bluetoothPrefix=identifier) else: self._sendIdentificationRequests() if self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Hims display found")
def __init__(self): global deviceFound super(BrailleDisplayDriver, self).__init__() self._messageWindowClassAtom = windll.user32.RegisterClassExW( byref(nvdaHIMSBrlWndCls)) self._messageWindow = windll.user32.CreateWindowExW( 0, self._messageWindowClassAtom, u"nvdaHIMSBrlWndCls window", 0, 0, 0, 0, 0, None, None, appInstance, None) code = himsLib.Open("USB", self._messageWindow, nvdaHIMSBrlWm) if code == 0: for portInfo in sorted( hwPortUtils.listComPorts(onlyAvailable=True), key=lambda item: "bluetoothName" in item): port = portInfo["port"].lower() btName = portInfo.get("bluetoothName") if btName and any( btName.startswith(prefix) for prefix in HIMS_BLUETOOTH_NAMES): try: if int(port.split("com")[1]) > 8: port = "\\\\.\\" + port except (IndexError, ValueError): pass code = himsLib.Open(str(port), self._messageWindow, nvdaHIMSBrlWm) if code >= 1: deviceFound = HIMS_CODE_DEVICES[code] log.info("%s device found" % deviceFound) return raise RuntimeError("No display found")
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType == "USB HID" try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._onReceive) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._onReceive) except EnvironmentError: continue if self.isHid: try: # It's essential to send protocol on for the Orbit Reader 20. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) except EnvironmentError: # Pronto! and VarioUltra don't support BAUM_PROTOCOL_ONOFF. pass # Explicitly request device info. # Even where it's supported, BAUM_PROTOCOL_ONOFF doesn't always return device info. self._sendRequest(BAUM_REQUEST_INFO, 0) else: # Serial # If the protocol is already on, sending protocol on won't return anything. # First ensure it's off. self._sendRequest(BAUM_PROTOCOL_ONOFF, False) # This will cause the device id, serial number and number of cells to be returned. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) # Send again in case the display misses the first one. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) for i in xrange(3): # An expected response hasn't arrived yet, so wait for it. self._dev.waitForRead(TIMEOUT) if self.numCells and self._deviceID: break if self.numCells: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Baum display found") self._keysDown = {} self._ignoreKeyReleases = False
def __init__(self): super(BrailleDisplayDriver, self).__init__() pint = c_int * 1 nCells = pint(0) nBut = pint(0) # seikaDll.BrailleOpen.errcheck=self.seika_errcheck seikaDll.BrailleOpen.restype=c_int seikaDll.BrailleOpen.argtype=(c_int, c_int) # seikaDll.GetBrailleDisplayInfo.errcheck=self.seika_errcheck seikaDll.GetBrailleDisplayInfo.restype=c_int seikaDll.GetBrailleDisplayInfo.argtype=(c_void_p, c_void_p) # seikaDll.UpdateBrailleDisplay.errcheck=self.seika_errcheck seikaDll.UpdateBrailleDisplay.restype=c_int seikaDll.UpdateBrailleDisplay.argtype=(c_char_p, c_int) # seikaDll.GetBrailleKey.errcheck=self.seika_errcheck seikaDll.GetBrailleKey.restype=c_int seikaDll.GetBrailleKey.argtype=(c_void_p, c_void_p) seikaDll.BrailleClose.restype=c_int if seikaDll.BrailleOpen(2, 0): # test USB seikaDll.GetBrailleDisplayInfo(nCells, nBut) log.info("seikamini an USB-HID, Cells {c} Buttons {b}".format(c=nCells[0], b=nBut[0])) self.numCells=nCells[0] # self.numBtns=nBut[0] else: # search the blutooth ports for portInfo in sorted(hwPortUtils.listComPorts(onlyAvailable=True), key=lambda item: "bluetoothName" in item): port = portInfo["port"] hwID = portInfo["hardwareID"] if not hwID.startswith(r"BTHENUM"): # Bluetooth Ports continue bName = "" try: bName = portInfo["bluetoothName"] except KeyError: continue if not bName.startswith(r"TSM"): # seikamini and then the 4-Digits continue try: pN = port.split("COM")[1] except IndexError: pN = "0" portNum = int(pN) log.info("seikamini test {c}, {b}".format(c=port, b=bName)) if seikaDll.BrailleOpen(0, portNum): seikaDll.GetBrailleDisplayInfo(nCells, nBut) log.info("seikamini via Bluetooth {p} Cells {c} Buttons {b}".format(p=port, c=nCells[0], b=nBut[0])) self.numCells=nCells[0] # self.numBtns=nBut[0] break else: raise RuntimeError("No MINI-SEIKA display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(READ_INTERVAL)
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: try: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, stopbits=serial.STOPBITS_ONE, parity=serial.PARITY_NONE, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._onReceive) except EnvironmentError: continue # try to initialize the device and request number of cells self._dev.write(DESCRIBE_TAG) self._dev.waitForRead(TIMEOUT) # Check for cell information if self.numCells: # ok, it is a SuperBraille log.info("Found superBraille device, version %s" % self.version) break else: self._dev.close() else: raise RuntimeError("No SuperBraille found")
def getPossiblePorts(cls): ports = OrderedDict() for p in hwPortUtils.listComPorts(): # Translators: Name of a serial communications port ports[p["port"]] = _("Serial: {portName}").format( portName=p["friendlyName"]) return ports
def _getPorts(): # USB. try: rootKey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Enum\USB\Vid_1c71&Pid_c005") except WindowsError: # A display has never been connected via USB. pass else: with rootKey: for index in itertools.count(): try: keyName = _winreg.EnumKey(rootKey, index) except WindowsError: break try: with _winreg.OpenKey( rootKey, os.path.join(keyName, "Device Parameters")) as paramsKey: yield "USB", _winreg.QueryValueEx( paramsKey, "PortName")[0] except WindowsError: continue # Bluetooth. for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): try: btName = portInfo["bluetoothName"] except KeyError: continue if btName.startswith("Brailliant B") or btName == "Brailliant 80": yield "bluetooth", portInfo["port"]
def getPossiblePorts(cls): ports = OrderedDict() usb = bluetooth = False # See if we have any USB ports available: try: cls._getUSBPorts().next() usb = True except StopIteration: pass # See if we have any bluetooth ports available: try: cls._getBluetoothPorts().next() bluetooth = True except StopIteration: pass if usb or bluetooth: ports.update([cls.AUTOMATIC_PORT]) if usb: ports["usb"] = "USB" if bluetooth: ports["bluetooth"] = "Bluetooth" for p in hwPortUtils.listComPorts(): # Translators: Name of a serial communications port ports[p["port"]] = _("Serial: {portName}").format( portName=p["friendlyName"]) return ports
def _getPorts(): # USB HID. for portInfo in hwPortUtils.listHidDevices(): if portInfo.get("usbID") == "VID_1C71&PID_C006": yield "USB HID", portInfo["devicePath"] # USB serial. try: rootKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Enum\USB\Vid_1c71&Pid_c005") except WindowsError: # A display has never been connected via USB. pass else: with rootKey: for index in itertools.count(): try: keyName = _winreg.EnumKey(rootKey, index) except WindowsError: break try: with _winreg.OpenKey(rootKey, os.path.join(keyName, "Device Parameters")) as paramsKey: yield "USB serial", _winreg.QueryValueEx(paramsKey, "PortName")[0] except WindowsError: continue # Bluetooth. for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): try: btName = portInfo["bluetoothName"] except KeyError: continue if btName.startswith("Brailliant B") or btName == "Brailliant 80": yield "bluetooth", portInfo["port"]
def __init__(self): self.gestureMap=inputCore.GlobalGestureMap() self.gestureMap.add("br(freedomScientific):routing","globalCommands","GlobalCommands","braille_routeTo") self.leftWizWheelActionCycle=itertools.cycle(self.wizWheelActions) action=self.leftWizWheelActionCycle.next() self.gestureMap.add("br(freedomScientific):leftWizWheelUp",*action[1]) self.gestureMap.add("br(freedomScientific):leftWizWheelDown",*action[2]) self.rightWizWheelActionCycle=itertools.cycle(self.wizWheelActions) action=self.rightWizWheelActionCycle.next() self.gestureMap.add("br(freedomScientific):rightWizWheelUp",*action[1]) self.gestureMap.add("br(freedomScientific):rightWizWheelDown",*action[2]) super(BrailleDisplayDriver,self).__init__() self._messageWindowClassAtom=windll.user32.RegisterClassExW(byref(nvdaFsBrlWndCls)) self._messageWindow=windll.user32.CreateWindowExW(0,self._messageWindowClassAtom,u"nvdaFsBrlWndCls window",0,0,0,0,0,None,None,appInstance,None) fbHandle=-1 for port in itertools.chain(("USB",), (portInfo["port"].encode("mbcs") for portInfo in hwPortUtils.listComPorts(onlyAvailable=True) if portInfo.get("bluetoothName") == "Focus 40 BT") ): fbHandle=fbOpen(port,self._messageWindow,nvdaFsBrlWm) if fbHandle!=-1: break if fbHandle==-1: raise RuntimeError("No display found") self.fbHandle=fbHandle
def __init__(self): super(BrailleDisplayDriver, self).__init__() self._serial = None self._buffer = "" # Check all available COM ports for a braillenote: found = False for port in hwPortUtils.listComPorts(): name = port['port'] if not name.startswith("COM"): continue log.debug("Checking port %s for a BrailleNote", name) try: self._serial = serial.Serial(name, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_NONE) log.debug("Port opened.") except serial.SerialException: continue # Check for cell information if self._describe(): # ok, it is a braillenote log.debug("BrailleNote found in %s with %d cells", name, self.numCells) found = True break else: self._serial.close() if not found: raise RuntimeError, "No BralleNote found" # start reading keys self._readTimer = wx.PyTimer(self._readKeys) self._readTimer.Start(READ_INTERVAL)
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType == "USB HID" try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._onReceive) else: self._dev = hwIo.Serial( port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._onReceive ) except EnvironmentError: continue if self.isHid: try: # It's essential to send protocol on for the Orbit Reader 20. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) except EnvironmentError: # Pronto! and VarioUltra don't support BAUM_PROTOCOL_ONOFF. pass # Explicitly request device info. # Even where it's supported, BAUM_PROTOCOL_ONOFF doesn't always return device info. self._sendRequest(BAUM_REQUEST_INFO, 0) else: # Serial # If the protocol is already on, sending protocol on won't return anything. # First ensure it's off. self._sendRequest(BAUM_PROTOCOL_ONOFF, False) # This will cause the device id, serial number and number of cells to be returned. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) # Send again in case the display misses the first one. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) for i in xrange(3): # An expected response hasn't arrived yet, so wait for it. self._dev.waitForRead(TIMEOUT) if self.numCells and self._deviceID: break if self.numCells: # A display responded. log.info( "Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port ) ) break self._dev.close() else: raise RuntimeError("No Baum display found") self._keysDown = {} self._ignoreKeyReleases = False
def getPossiblePorts(cls): ports = OrderedDict() usb = bluetooth = False # See if we have any USB ports available: try: cls._getUSBPorts().next() usb = True except StopIteration: pass # See if we have any bluetooth ports available: try: cls._getBluetoothPorts().next() bluetooth = True except StopIteration: pass if usb or bluetooth: ports.update([cls.AUTOMATIC_PORT]) if usb: ports["usb"] = "USB" if bluetooth: ports["bluetooth"] = "Bluetooth" for p in hwPortUtils.listComPorts(): # Translators: Name of a serial communications port ports[p["port"]] = _("Serial: {portName}").format(portName=p["friendlyName"]) return ports
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None self._ignoreKeyReleases = False self._keysDown = set() self.brailleInput = False self._hidSerialBuffer = b"" self._atc = False if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType.startswith("USB HID") self.isHidSerial = portType == "USB HID serial converter" try: if self.isHidSerial: # This is either the standalone HID adapter cable for older displays, # or an older display with a HID - serial adapter built in self._dev = hwIo.Hid(port, onReceive=self._hidSerialOnReceive) # Send a flush to open the serial channel self._dev.write(HT_HID_RPT_InCommand + HT_HID_CMD_FlushBuffers) elif self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._serialOnReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue self.sendPacket(HT_PKT_RESET) for _i in xrange(3): # An expected response hasn't arrived yet, so wait for it. self._dev.waitForRead(self.timeout) if self.numCells and self._model: break if self.numCells: # A display responded. self._model.postInit() log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Handy Tech display found")
def __init__(self): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None # Scan all available com ports. # Try bluetooth ports last. for portInfo in sorted(hwPortUtils.listComPorts(onlyAvailable=True), key=lambda item: "bluetoothName" in item): port = portInfo["port"] hwID = portInfo["hardwareID"] if hwID.startswith(r"FTDIBUS\COMPORT"): # USB. portType = "USB" try: usbID = hwID.split("&", 1)[1] except IndexError: continue if usbID not in USB_IDS: continue elif "bluetoothName" in portInfo: # Bluetooth. portType = "bluetooth" btName = portInfo["bluetoothName"] if not any(btName.startswith(prefix) for prefix in BLUETOOTH_NAMES): continue else: continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT) except serial.SerialException: continue # This will cause the number of cells to be returned. self._sendRequest(BAUM_DISPLAY_DATA) # Send again in case the display misses the first one. self._sendRequest(BAUM_DISPLAY_DATA) # We just sent less bytes than we should, # so we need to send another request in order for the display to know the previous request is finished. self._sendRequest(BAUM_DEVICE_ID) self._handleResponses(wait=True) if self.numCells: # A display responded. if not self._deviceID: # Bah. The response to our device ID query hasn't arrived yet, so wait for it. self._handleResponses(wait=True) log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break else: raise RuntimeError("No Baum display found") self._readTimer = wx.PyTimer(self._handleResponses) self._readTimer.Start(READ_INTERVAL) self._keysDown = {} self._ignoreKeyReleases = False
def _getBluetoothPorts(cls): for p in hwPortUtils.listComPorts(): try: btName = p["bluetoothName"] except KeyError: continue if not any(btName == prefix or btName.startswith(prefix + " ") for prefix in bluetoothNames): continue yield p["port"].encode("mbcs")
def _getBluetoothPorts(cls): for p in hwPortUtils.listComPorts(): try: addr = p["bluetoothAddress"] name = p["bluetoothName"] except KeyError: continue if (any(first <= addr <= last for first, last in BLUETOOTH_ADDRS) or any(name.startswith(prefix) for prefix in BLUETOOTH_NAMES)): yield p["port"]
def getPossiblePorts(cls): ports = OrderedDict() comPorts = list(hwPortUtils.listComPorts(onlyAvailable = True)) try: next(cls._getAutoPorts(comPorts)) ports.update((cls.AUTOMATIC_PORT,)) except StopIteration: pass for portInfo in comPorts: # Translators: Name of a serial communications port. ports[portInfo["port"]] = _("Serial: {portName}").format(portName = portInfo["friendlyName"]) return ports
def getPossiblePorts(cls): ports = OrderedDict() comPorts = list(hwPortUtils.listComPorts(onlyAvailable=True)) try: next(cls._getAutoPorts(comPorts)) ports.update((cls.AUTOMATIC_PORT,)) except StopIteration: pass for portInfo in comPorts: # Translators: Name of a serial communications port. ports[portInfo["port"]] = _("Serial: {portName}").format(portName=portInfo["friendlyName"]) return ports
def _getBluetoothPorts(cls): for p in hwPortUtils.listComPorts(): try: addr = p["bluetoothAddress"] name = p["bluetoothName"] except KeyError: continue if (any(first <= addr <= last for first, last in BLUETOOTH_ADDRS) or any( name.startswith(prefix) for prefix in BLUETOOTH_NAMES)): yield p["port"]
def getPossiblePorts(cls): ports = dict() comPorts = list(hwPortUtils.listComPorts(onlyAvailable=True)) try: next(cls._getAutoPorts(comPorts)) ports.update((cls.AUTOMATIC_PORT, )) except StopIteration: pass for portInfo in comPorts: portName = portInfo["friendlyName"] ports[portInfo["port"]] = f"Serial: {portName}" return ports
def __init__(self): super(BrailleDisplayDriver, self).__init__() for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): port = portInfo["port"] hwID = portInfo["hardwareID"] #log.info("Found port {port} with hardwareID {hwID}".format(port=port, hwID=hwID)) if not hwID.startswith(r"FTDIBUS\COMPORT"): continue try: usbID = hwID.split("&", 1)[1] except IndexError: continue if usbID not in HEDO_USB_IDS: continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=HEDO_BAUDRATE, timeout=HEDO_TIMEOUT, writeTimeout=HEDO_TIMEOUT, parity=serial.PARITY_ODD, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE) except serial.SerialException: continue # Prepare a blank line totalCells: int = HEDO_CELL_COUNT + HEDO_CELL_COUNT cells: bytes = HEDO_INIT + bytes(totalCells) # Send the blank line twice self._ser.write(cells) self._ser.flush() self._ser.write(cells) self._ser.flush() # Read out the input buffer ackS: bytes = self._ser.read(2) if HEDO_ACK in ackS: log.info("Found hedo ProfiLine connected via {port}".format( port=port)) break else: raise RuntimeError("No hedo display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(HEDO_READ_INTERVAL) self._keysDown = set() self._ignoreKeyReleases = False
def connectBluetooth(self): """try to connect to bluetooth device first, bluetooth is only supported on Braillex Trio""" if(self._baud == 0 and self._dev is None): for portInfo in sorted(hwPortUtils.listComPorts(onlyAvailable=True), key=lambda item: "bluetoothName" in item): port = portInfo["port"] hwID = portInfo["hardwareID"] if "bluetoothName" in portInfo: if portInfo["bluetoothName"][0:14] == "braillex trio " or portInfo["bluetoothName"][0:13] == "braillex live": try: self._dev = serial.Serial(port, baudrate = 57600,timeout = BLUETOOTH_TIMEOUT, writeTimeout = BLUETOOTH_TIMEOUT) log.info("connectBluetooth success") except: log.debugWarning("connectBluetooth failed")
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None self._ignoreKeyReleases = False self._keysDown = set() self._brailleInput = False self._hidSerialBuffer = "" if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType.startswith("USB HID") self.isHidSerial = portType == "USB HID serial converter" try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._onReceive) if self.isHidSerial: # This is either the standalone HID adapter cable for older displays, # or an older display with a HID - serial adapter built in # Send a flush to open the serial channel self._dev.write(HT_HID_RPT_InCommand + HT_HID_CMD_FlushBuffers) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue self.sendPacket(HT_PKT_RESET) for _i in xrange(3): # An expected response hasn't arrived yet, so wait for it. self._dev.waitForRead(self.timeout) if self.numCells and self._model: break if self.numCells: # A display responded. self._model.postInit() log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Handy Tech display found")
def getPossiblePorts(cls): ports = OrderedDict() comPorts = list(hwPortUtils.listComPorts(onlyAvailable=True)) try: next(cls._getAutoPorts(comPorts)) ports.update((cls.AUTOMATIC_PORT,)) except StopIteration: pass for portInfo in comPorts: if not portInfo.get("bluetoothName","").startswith("ALVA "): continue # Translators: Name of a bluetooth serial communications port. ports[portInfo["port"]] = _("Bluetooth serial: {portName}").format(portName=portInfo["friendlyName"]) return ports
def __init__(self): super(BrailleDisplayDriver, self).__init__() for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): port = portInfo["port"] hwID = portInfo["hardwareID"] # log.info("Found port {port} with hardwareID {hwID}".format(port=port, hwID=hwID)) if not hwID.upper().startswith(r"USB\VID_10C4&PID_EA60"): # Seika USB to Serial, in XP it is lowercase, in Win7 uppercase continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUDRATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_ODD, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE) except serial.SerialException: continue log.debug("serial port open {port}".format(port=port)) self._ser.write(b"\xFF\xFF\x1C") self._ser.flush() # Read out the input buffer versionS = self._ser.read(13) log.debug("receive {p}".format(p=versionS)) if versionS.startswith("seika80"): log.info("Found Seika80 connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 80 break if versionS.startswith("seika3"): log.info("Found Seika40 connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 40 self.s40 = b"\xFF\xFF\x73\x65\x69\x6B\x61\x00" break # is it a old Seika3? log.debug("test if it is a old Seika3") self._ser.write(b"\xFF\xFF\x0A") self._ser.flush() # Read out the input buffer versionS = self._ser.read(12) log.debug("receive {p}".format(p=versionS)) if versionS.startswith(( b"\x00\x05\x28\x08\x76\x35\x2E\x30\x01\x01\x01\x01", b"\x00\x05\x28\x08\x73\x65\x69\x6b\x61\x00" )): log.info("Found Seika3 old Version connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 40 self.s40 = b"\xFF\xFF\x04\x00\x63\x00\x50\x00" break self._ser.close() else: raise RuntimeError("No SEIKA40/80 display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(READ_INTERVAL)
def getPossiblePorts(cls): ports = OrderedDict() comPorts = list(hwPortUtils.listComPorts(onlyAvailable=True)) try: next(cls._getAutoPorts(comPorts)) ports.update((cls.AUTOMATIC_PORT, )) except StopIteration: pass for portInfo in comPorts: if not portInfo.get("bluetoothName", "").startswith("ALVA "): continue # Translators: Name of a bluetooth serial communications port. ports[portInfo["port"]] = _("Bluetooth serial: {portName}").format( portName=portInfo["friendlyName"]) return ports
def getPossiblePorts(cls): ports = OrderedDict() for p in hwPortUtils.listComPorts(): log.info("Port %s" % p) if "bluetoothAddress" in p.keys(): if p["bluetoothAddress"] and p["bluetoothName"].startswith( "408L-"): # Translators: Name of a Bluetooth serial communications port ports[p["port"]] = _( "Bluetooth Serial: {port} ({deviceName})").format( port=p["port"], deviceName=p["bluetoothName"]) continue # Translators: Name of a serial communications port ports[p["port"]] = _("Serial: {portName}").format( portName=p["friendlyName"]) return ports
def __init__(self): super(BrailleDisplayDriver, self).__init__() for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): port = portInfo["port"] hwID = portInfo["hardwareID"] # log.info("Found port {port} with hardwareID {hwID}".format(port=port, hwID=hwID)) if not hwID.upper().startswith(r"USB\VID_10C4&PID_EA60"): # Seika USB to Serial, in XP it is lowercase, in Win7 uppercase continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUDRATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_ODD, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE) except serial.SerialException: continue log.debug("serial port open {port}".format(port=port)) self._ser.write("\xFF\xFF\x1C") self._ser.flush() # Read out the input buffer versionS = self._ser.read(13) log.debug("receive {p}".format(p=versionS)) if versionS.startswith("seika80"): log.info("Found Seika80 connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 80 break if versionS.startswith("seika3"): log.info("Found Seika40 connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 40 self.s40 = "\xFF\xFF\x73\x65\x69\x6B\x61\x00" break # is it a old Seika3? log.debug("test if it is a old Seika3") self._ser.write("\xFF\xFF\x0A") self._ser.flush() # Read out the input buffer versionS = self._ser.read(12) log.debug("receive {p}".format(p=versionS)) if versionS.startswith("\x00\x05\x28\x08\x76\x35\x2E\x30\x01\x01\x01\x01") or versionS.startswith("\x00\x05\x28\x08\x73\x65\x69\x6b\x61\x00"): log.info("Found Seika3 old Version connected via {port} Version {versionS}".format(port=port, versionS=versionS)) self.numCells = 40 self.s40 = "\xFF\xFF\x04\x00\x63\x00\x50\x00" break self._ser.close() else: raise RuntimeError("No SEIKA40/80 display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(READ_INTERVAL)
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._rawKeyboardInput = False self._deviceId = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "bluetooth", "ALVA"), ) for port, portType, identifier in tryPorts: self.isHid = portType == "USB HID" # Try talking to the display. try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) self._deviceId = int(identifier[-2:], 16) else: self._dev = hwIo.Serial(port, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._ser6OnReceive) # Get the device ID self._ser6SendMessage(b"?", b"?") for i in xrange(3): self._dev.waitForRead(self.timeout) if self._deviceId: # Display responded break else: # No response from display continue except EnvironmentError: continue self._updateSettings() if self.numCells: # A display responded. log.info( "Found display with {cells} cells connected via {type} ({port})" .format(cells=self.numCells, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No display found") self._keysDown = set() self._ignoreKeyReleases = False
def _getPorts(): # HID. for portInfo in hwPortUtils.listHidDevices(): if portInfo.get("usbID") in USB_IDS_HID: yield "USB HID", portInfo["devicePath"] # In Windows 10, the Bluetooth vendor and product ids don't get recognised. # Use strings instead. elif portInfo.get("manufacturer") == "Humanware" and portInfo.get( "product") == "Brailliant HID": yield "Bluetooth HID", portInfo["devicePath"] # USB serial. for usbId in USB_IDS_SER: try: rootKey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Enum\USB\%s" % usbId) except WindowsError: # A display with this id has never been connected via USB. continue with rootKey: for index in itertools.count(): try: keyName = _winreg.EnumKey(rootKey, index) except WindowsError: break # No more sub-keys. try: with _winreg.OpenKey( rootKey, os.path.join(keyName, "Device Parameters")) as paramsKey: yield "USB serial", _winreg.QueryValueEx( paramsKey, "PortName")[0] except WindowsError: continue # Bluetooth serial. for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): try: btName = portInfo["bluetoothName"] except KeyError: continue if btName.startswith( "Brailliant B" ) or btName == "Brailliant 80" or "BrailleNote Touch" in btName: yield "Bluetooth serial", portInfo["port"]
def kgsListComPorts(preferSerial=False): ports = [] btPorts = {} usbPorts = {} # BM bluetooth ports for p in hwPortUtils.listComPorts(onlyAvailable=True): if 'bluetoothName' in p and p['bluetoothName'][:2].upper() == u'BM': p['friendlyName'] = u"Bluetooth: %s (%s)" % (p['bluetoothName'], p['port']) ports.append(p) btPorts[p['port']] = True # BM-SMART USB try: rootKey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Enum\USB\VID_1148&PID_0301") except WindowsError as e: pass else: with rootKey: for index in itertools.count(): try: keyName = _winreg.EnumKey(rootKey, index) except WindowsError: break try: with _winreg.OpenKey( rootKey, os.path.join(keyName, "Device Parameters")) as paramsKey: portName = _winreg.QueryValueEx(paramsKey, "PortName")[0] ports.append({ 'friendlyName': u'USB: KGS BM-SMART USB Serial (%s)' % portName, 'hardwareID': ur'USB\VID_1148&PID_0301', 'port': unicode(portName) }) usbPorts[portName] = True except WindowsError: continue
def __init__(self): super(BrailleDisplayDriver, self).__init__() for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): port = portInfo["port"] hwID = portInfo["hardwareID"] #log.info("Found port {port} with hardwareID {hwID}".format(port=port, hwID=hwID)) if not hwID.startswith(r"FTDIBUS\COMPORT"): continue try: usbID = hwID.split("&", 1)[1] except IndexError: continue if usbID not in HEDO_USB_IDS: continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=HEDO_BAUDRATE, timeout=HEDO_TIMEOUT, writeTimeout=HEDO_TIMEOUT, parity=serial.PARITY_ODD, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE) except serial.SerialException: continue # Prepare a blank line cells = chr(HEDO_INIT) + chr(0) * (HEDO_CELL_COUNT + HEDO_STATUS_CELL_COUNT) # Send the blank line twice self._ser.write(cells) self._ser.flush() self._ser.write(cells) self._ser.flush() # Read out the input buffer ackS = self._ser.read(2) if chr(HEDO_ACK) in ackS: log.info("Found hedo ProfiLine connected via {port}".format(port=port)) break else: raise RuntimeError("No hedo display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(HEDO_READ_INTERVAL) self._keysDown = set() self._ignoreKeyReleases = False
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT) except serial.SerialException: continue # If the protocol is already on, sending protocol on won't return anything. # First ensure it's off. self._sendRequest(BAUM_PROTOCOL_ONOFF, False) # This will cause the device id, serial number and number of cells to be returned. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) # Send again in case the display misses the first one. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) self._handleResponses(wait=True) if not self.numCells or not self._deviceID: # An expected response hasn't arrived yet, so wait for it. self._handleResponses(wait=True) if self.numCells: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break else: raise RuntimeError("No Baum display found") self._readTimer = wx.PyTimer(self._handleResponses) self._readTimer.Start(READ_INTERVAL) self._keysDown = {} self._ignoreKeyReleases = False
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT) except serial.SerialException: continue # This will cause the number of cells to be returned. self._sendRequest(BAUM_DISPLAY_DATA) # Send again in case the display misses the first one. self._sendRequest(BAUM_DISPLAY_DATA) # We just sent less bytes than we should, # so we need to send another request in order for the display to know the previous request is finished. self._sendRequest(BAUM_DEVICE_ID) self._handleResponses(wait=True) if self.numCells: # A display responded. if not self._deviceID: # Bah. The response to our device ID query hasn't arrived yet, so wait for it. self._handleResponses(wait=True) log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break else: raise RuntimeError("No Baum display found") self._readTimer = wx.PyTimer(self._handleResponses) self._readTimer.Start(READ_INTERVAL) self._keysDown = {} self._ignoreKeyReleases = False
def __init__(self, port="auto"): super(BrailleDisplayDriver,self).__init__() self.numCells = 0 self._rawKeyboardInput = False self._deviceId = None if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "bluetooth", "ALVA"),) for port, portType, identifier in tryPorts: self.isHid = portType == "USB HID" # Try talking to the display. try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) self._deviceId = int(identifier[-2:],16) else: self._dev = hwIo.Serial(port, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._ser6OnReceive) # Get the device ID self._ser6SendMessage(b"?", b"?") for i in xrange(3): self._dev.waitForRead(self.timeout) if self._deviceId: # Display responded break else: # No response from display continue except EnvironmentError: continue self._updateSettings() if self.numCells: # A display responded. log.info("Found display with {cells} cells connected via {type} ({port})".format( cells=self.numCells, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No display found") self._keysDown = set() self._ignoreKeyReleases = False
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT) except serial.SerialException: continue # If the protocol is already on, sending protocol on won't return anything. # First ensure it's off. self._sendRequest(BAUM_PROTOCOL_ONOFF, False) # This will cause the device id, serial number and number of cells to be returned. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) # Send again in case the display misses the first one. self._sendRequest(BAUM_PROTOCOL_ONOFF, True) self._handleResponses(wait=True) if not self.numCells or not self._deviceID: # An expected response hasn't arrived yet, so wait for it. self._handleResponses(wait=True) if self.numCells: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break else: raise RuntimeError("No Baum display found") self._readTimer = wx.PyTimer(self._handleResponses) self._readTimer.Start(READ_INTERVAL) self._keysDown = {} self._ignoreKeyReleases = False
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._deviceID = None if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT) except serial.SerialException: continue # This will cause the number of cells to be returned. self._sendRequest(BAUM_DISPLAY_DATA) # Send again in case the display misses the first one. self._sendRequest(BAUM_DISPLAY_DATA) # We just sent less bytes than we should, # so we need to send another request in order for the display to know the previous request is finished. self._sendRequest(BAUM_DEVICE_ID) self._handleResponses(wait=True) if self.numCells: # A display responded. if not self._deviceID: # Bah. The response to our device ID query hasn't arrived yet, so wait for it. self._handleResponses(wait=True) log.info("Found {device} connected via {type} ({port})".format( device=self._deviceID, type=portType, port=port)) break else: raise RuntimeError("No Baum display found") self._readTimer = wx.PyTimer(self._handleResponses) self._readTimer.Start(READ_INTERVAL) self._keysDown = {} self._ignoreKeyReleases = False
def __init__(self): global deviceFound super(BrailleDisplayDriver, self).__init__() self._messageWindowClassAtom = windll.user32.RegisterClassExW(byref(nvdaHIMSBrlWndCls)) self._messageWindow = windll.user32.CreateWindowExW(0,self._messageWindowClassAtom,u"nvdaHIMSBrlWndCls window",0,0,0,0,0,None,None,appInstance,None) code = himsLib.Open("USB",self._messageWindow,nvdaHIMSBrlWm) if code == 0: for portInfo in sorted(hwPortUtils.listComPorts(onlyAvailable=True), key=lambda item: "bluetoothName" in item): port = portInfo["port"].lower() btName = portInfo.get("bluetoothName") if btName and any(btName.startswith(prefix) for prefix in HIMS_BLUETOOTH_NAMES): try: if int(port.split("com")[1]) > 8: port = "\\\\.\\"+port except (IndexError, ValueError): pass code = himsLib.Open(str(port),self._messageWindow,nvdaHIMSBrlWm) if code >= 1: deviceFound = HIMS_CODE_DEVICES[code] log.info("%s device found"%deviceFound) return raise RuntimeError("No display found")
def __init__(self, port="Auto"): log.info("BAUM VarioPro Init") super().__init__() self.numCells = 0 self._dev = None self.bp_trans_prev_byte = 0 # BAUM protocol transport layer (ESC dedoubling) self.mainModule = None self.statusModule = None self.telephoneModule = None self.connected_modules = {} try: if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"), ) for port, portType in tryPorts: if self._dev: if self._dev.is_open(): self._dev.close() self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) self.vp_query_modules() for i in range(10): # wait for dev arrival self._dev.waitForRead(self.timeout) if self.numCells: break else: log.error("Device arrival timeout") except Exception as e: log.error(e) raise RuntimeError("No BAUM VarioPro display found")
def _getPorts(): # HID. for portInfo in hwPortUtils.listHidDevices(): if portInfo.get("usbID") in USB_IDS_HID: yield "USB HID", portInfo["devicePath"] # In Windows 10, the Bluetooth vendor and product ids don't get recognised. # Use strings instead. elif portInfo.get("manufacturer") == "Humanware" and portInfo.get("product") == "Brailliant HID": yield "Bluetooth HID", portInfo["devicePath"] # USB serial. for usbId in USB_IDS_SER: try: rootKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Enum\USB\%s" % usbId) except WindowsError: # A display with this id has never been connected via USB. continue with rootKey: for index in itertools.count(): try: keyName = _winreg.EnumKey(rootKey, index) except WindowsError: break # No more sub-keys. try: with _winreg.OpenKey(rootKey, os.path.join(keyName, "Device Parameters")) as paramsKey: yield "USB serial", _winreg.QueryValueEx(paramsKey, "PortName")[0] except WindowsError: continue # Bluetooth serial. for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): try: btName = portInfo["bluetoothName"] except KeyError: continue if btName.startswith("Brailliant B") or btName == "Brailliant 80" or "BrailleNote Touch" in btName: yield "Bluetooth serial", portInfo["port"]
def __init__(self,port="Auto"): super(BrailleDisplayDriver, self).__init__() if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: try: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, stopbits=serial.STOPBITS_ONE, parity=serial.PARITY_NONE, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._onReceive) except EnvironmentError: continue # try to initialize the device and request number of cells self._dev.write(DESCRIBE_TAG) self._dev.waitForRead(TIMEOUT) # Check for cell information if self.numCells: # ok, it is a SuperBraille log.info("Found superBraille device, version %s"%self.version) break else: self._dev.close() else: raise RuntimeError("No SuperBraille found")
def _getBluetoothPorts(cls): return (p["port"].encode("mbcs") for p in hwPortUtils.listComPorts() if p.get("bluetoothName") in bluetoothNames)
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: try: btName = next( portInfo.get("bluetoothName", "") for portInfo in hwPortUtils.listComPorts() if portInfo.get("port") == port) btPrefix = next(prefix for prefix in bluetoothPrefixes if btName.startswith(prefix)) tryPorts = ((port, "bluetooth", btPrefix), ) except StopIteration: tryPorts = () for port, portType, identifier in tryPorts: self.isBulk = portType == "USB bulk" # Try talking to the display. try: if self.isBulk: # onReceiveSize based on max packet size according to USB endpoint information. self._dev = hwIo.Bulk(port, 0, 1, self._onReceive, writeSize=0, onReceiveSize=64) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue for i in xrange(3): self._sendCellCountRequest() # Wait for an expected response. if self.isBulk: # Hims Bulk devices sometimes present themselves to the system while not yet ready. # For example, when switching the connection mode toggle on the Braille EDGE from Bluetooth to USB, # the USB device is connected but not yet ready. # Wait ten times the timeout, which is ugly, but effective. self._dev.waitForRead(self.timeout * 10) else: self._dev.waitForRead(self.timeout) if self.numCells: break if not self.numCells: log.debugWarning("No response from potential Hims display") self._dev.close() continue if portType == "USB serial": self._model = SyncBraille() elif self.isBulk: self._sendIdentificationRequests(usbId=identifier) elif portType == "bluetooth" and identifier: self._sendIdentificationRequests(bluetoothPrefix=identifier) else: self._sendIdentificationRequests() if self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Hims display found")
def getPossiblePorts(cls): ports = OrderedDict() for p in hwPortUtils.listComPorts(): # Translators: Name of a serial communications port ports[p["port"]] = _("Serial: {portName}").format(portName=p["friendlyName"]) return ports
portName = _winreg.QueryValueEx(paramsKey, "PortName")[0] ports.append({ 'friendlyName': u'USB: KGS USB To Serial Com Port (%s)' % portName, 'hardwareID': ur'USB\VID_1148&PID_0001', 'port': unicode(portName) }) usbPorts[portName] = True except WindowsError: continue # serial ports for p in hwPortUtils.listComPorts(onlyAvailable=True): if 'hardwareID' in p and p['hardwareID'].upper().startswith( u'BTHENUM'): if p['hardwareID'].upper().startswith( ur'BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG' ): log.info("skipping %s" % p['hardwareID']) continue else: log.info("appending non-kgs device: %s" % p['hardwareID']) p["friendlyName"] = u"Bluetooth: {portName}".format( portName=p["friendlyName"]) ports.append(p) elif p['port'] not in btPorts and p['port'] not in usbPorts: p["friendlyName"] = _("Serial: {portName}").format( portName=p["friendlyName"])
def _getUSBPorts(cls): return (p["port"] for p in hwPortUtils.listComPorts() if p["hardwareID"].startswith("USB\\") and any( p["hardwareID"][4:].startswith(id) for id in USB_IDS))
def _get_comPorts(self) -> typing.List[typing.Dict]: return list(hwPortUtils.listComPorts(onlyAvailable=True))
def __init__(self): super(BrailleDisplayDriver, self).__init__() for portInfo in hwPortUtils.listComPorts(onlyAvailable=True): port = portInfo["port"] hwID = portInfo["hardwareID"] # Seika USB to Serial, in XP it is lowercase, in Win7 uppercase if not hwID.upper().startswith(r"USB\VID_10C4&PID_EA60"): continue # At this point, a port bound to this display has been found. # Try talking to the display. try: self._ser = serial.Serial( port, baudrate=BAUDRATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_ODD, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE ) except serial.SerialException: continue log.debug(f"serial port open {port}") # get the version information VERSION_INFO_REQUEST = b"\x1C" self._ser.write(BUF_START + VERSION_INFO_REQUEST) self._ser.flush() # Read out the input buffer versionS = self._ser.read(13) log.debug(f"receive {versionS}") if versionS.startswith(b"seika80"): log.info(f"Found Seika80 connected via {port} Version {versionS}") self.numCells = 80 self._maxCellRead = 20 # data header for seika 80 self.sendHeader = (BUF_START + b"s80").ljust(8, b"\x00") break elif versionS.startswith(b"seika3"): log.info(f"Found Seika3/5 connected via {port} Version {versionS}") self.numCells = 40 self._maxCellRead = 10 # data header for v3, v5 self.sendHeader = (BUF_START + b"seika").ljust(8, b"\x00") break # is it a old Seika3? log.debug("test if it is a old Seika3") LEGACY_VERSION_REQUEST = b"\x0A" self._ser.write(BUF_START + LEGACY_VERSION_REQUEST) self._ser.flush() # Read out the input buffer versionS = self._ser.read(12) log.debug(f"receive {versionS}") if versionS.startswith(prefix=( b'\x00\x05(\x08v5.0\x01\x01\x01\x01', b'\x00\x05(\x08seika\x00' )): log.info(f"Found Seika3 old Version connected via {port} Version {versionS}") self.numCells = 40 self._maxCellRead = 10 self.sendHeader = BUF_START + b"\x04\x00\x63\x00\x50\x00" break self._ser.close() else: raise RuntimeError("No SEIKA40/80 display found") self._readTimer = wx.PyTimer(self.handleResponses) self._readTimer.Start(READ_INTERVAL)
def _get_comPorts(self): return list(hwPortUtils.listComPorts(onlyAvailable=True))
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self.deviceType = None self._deviceData = {} self._awaitingFrameReceipts = {} self._frameLength = None self._frame = 0x20 self._frameLock = threading.Lock() self._hidKeyboardInput = False self._hidInputBuffer = "" if port == "auto": tryPorts = self._getAutoPorts(hwPortUtils.listComPorts(onlyAvailable=True)) else: tryPorts = ((port, "serial"),) for port, portType in tryPorts: # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType == "USB HID" try: if self.isHid: self._dev = hwIo.Hid( port, onReceive=self._onReceive, # Eurobraille wants us not to block other application's access to this handle. exclusive=False ) else: self._dev = hwIo.Serial( port, baudrate=BAUD_RATE, bytesize=serial.EIGHTBITS, parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive ) except EnvironmentError: log.debugWarning("Error while connecting to port %r"%port, exc_info=True) continue for i in xrange(3): # Request device identification self._sendPacket(EB_SYSTEM, EB_SYSTEM_IDENTITY) # Make sure visualisation packets are disabled, as we ignore them anyway. self._sendPacket(EB_VISU, EB_VISU_DOT, '0') # A device identification results in multiple packets. # Make sure we've received everything before we continue while self._dev.waitForRead(self.timeout): continue if self.numCells and self.deviceType: break if self.numCells and self.deviceType: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self.deviceType, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No supported Eurobraille display found") self.keysDown = defaultdict(int) self._ignoreCommandKeyReleases = False
def _getUSBPorts(cls): return (p["port"] for p in hwPortUtils.listComPorts() if p["hardwareID"].startswith("USB\\") and any(p["hardwareID"][4:].startswith(id) for id in USB_IDS))