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 __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 = b"" for portType, portId, port, portInfo in self._getTryPorts(port): # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType == bdDetect.KEY_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 range(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, EB_FALSE) # A device identification results in multiple packets. # Make sure we've received everything before we continue while self._dev.waitForRead(self.timeout * 2): 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 __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, port="auto"): super(BrailleDisplayDriver, self).__init__() self._serial = None if port == "auto": portsToTry = itertools.chain(self._getUSBPorts(), self._getBluetoothPorts()) elif port == "usb": portsToTry = self._getUSBPorts() elif port == "bluetooth": portsToTry = self._getBluetoothPorts() else: portsToTry = (port, ) for port in portsToTry: log.debug("Checking port %s for a BrailleNote", port) try: self._serial = hwIo.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_NONE, onReceive=self._onReceive) except EnvironmentError: continue # Check for cell information if self._describe(): log.debug("BrailleNote found on %s with %d cells", port, self.numCells) break else: self._serial.close() else: raise RuntimeError("Can't find a braillenote device (port = %s)" % port)
def __init__(self, port="Auto"): super(BrailleDisplayDriver, self).__init__() for portType, portId, port, portInfo in self._getTryPorts(port): 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: log.debugWarning("", exc_info=True) 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 __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self._serial = None for portType, portId, port, portInfo in self._getTryPorts(port): log.debug("Checking port %s for a BrailleNote", port) try: self._serial = hwIo.Serial(port, baudrate=BAUD_RATE, timeout=TIMEOUT, writeTimeout=TIMEOUT, parity=serial.PARITY_NONE, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue # Check for cell information if self._describe(): log.debug("BrailleNote found on %s with %d cells", port, self.numCells) break else: self._serial.close() else: raise RuntimeError("Can't find a braillenote device (port = %s)" % port)
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._dotFirmness = 1 self._hidSerialBuffer = b"" self._atc = False self._sleepcounter = 0 for portType, portId, port, portInfo in self._getTryPorts(port): # At this point, a port bound to this display has been found. # Try talking to the display. self.isHid = portType == bdDetect.KEY_HID self.isHidSerial = portId in USB_IDS_HID_CONVERTER self.port = port 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 range(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)) # Create the message window on the ui thread. wx.CallAfter(self.create_message_window) break self._dev.close() else: raise RuntimeError("No Handy Tech display found")
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, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None for match in self._getTryPorts(port): portType, portId, port, portInfo = match self.isBulk = portType == bdDetect.KEY_CUSTOM # 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 self._sendIdentificationRequests(match) 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): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 for portType, port in _getPorts(): self.isHid = portType == "USB HID" # Try talking to the display. try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._serOnReceive) except EnvironmentError: continue if self.isHid: data = self._dev.getFeature(HR_CAPS) self.numCells = ord(data[24]) else: # This will cause the number of cells to be returned. self._serSendMessage(MSG_INIT) # #5406: With the new USB driver, the first command is ignored after a reconnection. # Send the init message again just in case. self._serSendMessage(MSG_INIT) self._dev.waitForRead(TIMEOUT) if not self.numCells: # HACK: When connected via bluetooth, the display sometimes reports communication not allowed on the first attempt. self._serSendMessage(MSG_INIT) self._dev.waitForRead(TIMEOUT) 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._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 wake_up(self): if self._sleepcounter > 0: self._sleepcounter -= 1 if self._sleepcounter > 0: # Still not zero after decrementing return # Might throw if device no longer exists. # We leave it to autodetection to grab it when it reappears. 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(self.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(self.port, onReceive=self._hidOnReceive) else: self._dev = hwIo.Serial(self.port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._serialOnReceive)
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 for portType, portId, port, portInfo in self._getTryPorts(port): self.isHid = portType == bdDetect.KEY_HID # Try talking to the display. try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=TIMEOUT, writeTimeout=TIMEOUT, onReceive=self._serOnReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue # Couldn't connect. # The Brailliant can fail to init if you try immediately after connecting. time.sleep(DELAY_AFTER_CONNECT) # Sometimes, a few attempts are needed to init successfully. for attempt in xrange(INIT_ATTEMPTS): if attempt > 0: # Not the first attempt time.sleep(INIT_RETRY_DELAY) # Delay before next attempt. self._initAttempt() if self.numCells: break # Success! 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 # This device can't be initialized. Move on to the next (if any). 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._rawKeyboardInput = False self._deviceId = None for portType, portId, port, portInfo in self._getTryPorts(port): self.isHid = portType == bdDetect.KEY_HID # Try talking to the display. try: if self.isHid: self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive) self._deviceId = int(portId[-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 range(3): self._dev.waitForRead(self.timeout) if self._deviceId: # Display responded break else: # No response from display continue except EnvironmentError: log.debugWarning("", exc_info=True) 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 ALVA display found") self._keysDown = set() self._ignoreKeyReleases = False
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 __init__(self, port="auto"): self.numCells = 0 self._ackPending = False self._pendingCells = [] self._keyBits = 0 self._extendedKeyBits = 0 self._ignoreKeyReleases = False self._model = None self._manufacturer = None self._firmwareVersion = None self.translationTable = None 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__() for portType, portId, port, portInfo in self._getTryPorts(port): self.isUsb = portType == bdDetect.KEY_CUSTOM # Try talking to the display. try: if self.isUsb: self._dev = hwIo.Bulk( port, epIn=1, epOut=0, onReceive=self._onReceive, writeSize=0, onReceiveSize=56 ) 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 # Send an identification request self._sendPacket(FS_PKT_QUERY) for _i in xrange(3): self._dev.waitForRead(self.timeout) if self.numCells and self._model: break if self.numCells and self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Freedom Scientific display found") self._configureDisplay() self.gestureMap.add("br(freedomScientific):topRouting1", "globalCommands", "GlobalCommands", "braille_scrollBack") self.gestureMap.add("br(freedomScientific):topRouting%d" % self.numCells, "globalCommands", "GlobalCommands", "braille_scrollForward")
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, port: typing.Union[None, str, DeviceMatch]): super().__init__() self.numCells = 0 self.numBtns = 0 self.numRoutingKeys = 0 self.handle = None self._hidBuffer = b"" self._command: typing.Optional[bytes] = None self._argsLen: typing.Optional[int] = None log.debug(f"Seika Notetaker braille driver: ({port!r})") dev: typing.Optional[typing.Union[hwIo.Hid, hwIo.Serial]] = None for match in self._getTryPorts(port): self.isHid = match.type == bdDetect.KEY_HID self.isSerial = match.type == bdDetect.KEY_SERIAL try: if self.isHid: log.info(f"Trying Seika notetaker on USB-HID") self._dev = dev = hwIo.Hid( path=match. port, # for a Hid match type 'port' is actually 'path'. onReceive=self._onReceiveHID) dev.setFeature( SEIKA_HID_FEATURES) # baud rate, stop bit usw dev.setFeature(SEIKA_CMD_ON) # device on elif self.isSerial: log.info( f"Trying Seika notetaker on Bluetooth (serial) port:{match.port}" ) self._dev = dev = hwIo.Serial( port=match.port, onReceive=self._onReceiveSerial, baudrate=BAUD, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE, ) # Note: SEIKA_CMD_ON not sent as per USB-HID, testing from users hasn't indicated any problems. # The exact purpose of SEIKA_CMD_ON isn't known/documented here. else: log.debug(f"Port type not handled: {match.type}") continue except EnvironmentError: log.debugWarning("", exc_info=True) continue if self._getDeviceInfo(dev): break elif dev: dev.close() dev = None if not dev: RuntimeError("No MINI-SEIKA display found") elif self.numCells == 0: dev.close() dev = None raise RuntimeError("No MINI-SEIKA display found, no response") else: log.info(f"Seika notetaker," f" Cells {self.numCells}" f" Buttons {self.numBtns}")