Beispiel #1
0
    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")
Beispiel #2
0
    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")
Beispiel #3
0
    def __init__(self, port="hid"):
        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.info(f"Seika Notetaker braille driver path: {self.path}")

        if self.path == "":
            raise RuntimeError("No MINI-SEIKA display found, no path found")
        self._dev = dev = hwIo.Hid(path=self.path, onReceive=self._onReceive)
        if dev._file == INVALID_HANDLE_VALUE:
            raise RuntimeError("No MINI-SEIKA display found, open error")
        dev.setFeature(SEIKA_CONFIG)  # baud rate, stop bit usw
        dev.setFeature(SEIKA_CMD_ON)  # device on
        dev.write(SEIKA_REQUEST_INFO)  # Request the Info from the device

        # wait and try to get info from the Braille display
        for i in range(MAX_READ_ATTEMPTS):  # the info-block is about
            dev.waitForRead(READ_TIMEOUT_SECS)
            if self.numCells:
                log.info(f"Seika notetaker on USB-HID,"
                         f" Cells {self.numCells}"
                         f" Buttons {self.numBtns}")
                break

        if self.numCells == 0:
            dev.close()
            raise RuntimeError("No MINI-SEIKA display found, no response")
Beispiel #4
0
    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.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 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)
Beispiel #7
0
    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
Beispiel #8
0
    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
Beispiel #9
0
    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
Beispiel #10
0
    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
Beispiel #11
0
    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}")