@@ -272,26 +272,23 @@ def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
272272
273273 @classmethod
274274 def getManualPorts (cls ):
275- return braille .getSerialPorts (filterFunc = lambda info : "bluetoothName" in info )
275+ return braille .getSerialPorts ()
276276
277277 def __init__ (self , port = "auto" ):
278278 super (BrailleDisplayDriver , self ).__init__ ()
279279 self .numCells = 0
280280 self ._model = None
281+ self ._serData = b''
281282
282283 for match in self ._getTryPorts (port ):
283284 portType , portId , port , portInfo = match
284285 self .isBulk = portType == bdDetect .DeviceType .CUSTOM
285286 self .isHID = portType == bdDetect .DeviceType .HID
287+ self .isSerial = portType == bdDetect .DeviceType .SERIAL
286288 # Try talking to the display.
287289 try :
288290 match portType :
289- case bdDetect .DeviceType .HID :
290- self ._dev = hwIo .Hid (port , onReceive = self ._hidOnReceive )
291- case bdDetect .DeviceType .CUSTOM :
292- # onReceiveSize based on max packet size according to USB endpoint information.
293- self ._dev = hwIo .Bulk (port , 0 , 1 , self ._onReceive , onReceiveSize = 64 )
294- case _:
291+ case bdDetect .DeviceType .SERIAL :
295292 self ._dev = hwIo .Serial (
296293 port ,
297294 baudrate = BAUD_RATE ,
@@ -300,6 +297,11 @@ def __init__(self, port="auto"):
300297 writeTimeout = self .timeout ,
301298 onReceive = self ._onReceive
302299 )
300+ case bdDetect .DeviceType .HID :
301+ self ._dev = hwIo .Hid (port , onReceive = self ._hidOnReceive )
302+ case bdDetect .DeviceType .CUSTOM :
303+ # onReceiveSize based on max packet size according to USB endpoint information.
304+ self ._dev = hwIo .Bulk (port , 0 , 1 , self ._onReceive , onReceiveSize = 64 )
303305 except EnvironmentError :
304306 log .debugWarning ("" , exc_info = True )
305307 continue
@@ -497,15 +499,35 @@ def _onReceive(self, data: bytes):
497499 firstByte = data
498500 # data only contained the first byte. Read the rest from the device.
499501 stream = self ._dev
502+
503+ # sometimes serial data received splited data. so accmulate data until it reaches 10 bytes.
504+ if self ._serData :
505+ self ._serData += data
506+ if len (self ._serData ) == 10 :
507+ firstByte = b'\xfa '
508+ else :
509+ return
510+
500511 if firstByte == b"\x1c " :
501512 # A device is identifying itself
502513 deviceId : bytes = stream .read (2 )
503514 # When a device identifies itself, the packets ends with 0x1f
504515 assert stream .read (1 ) == b"\x1f "
505516 self ._handleIdentification (deviceId )
506517 elif firstByte == b"\xfa " :
507- # Command packets are ten bytes long
508- packet = firstByte + stream .read (9 )
518+ # serial data first received
519+ if not self ._serData :
520+ try :
521+ # Command packets are ten bytes long
522+ packet = firstByte + stream .read (9 )
523+ except :
524+ # remained data will be received next onReceive
525+ self ._serData = firstByte
526+ return
527+ else :
528+ packet = self ._serData
529+ self ._serData = b''
530+
509531 assert packet [2 ] == 0x01 # Fixed value
510532 CHECKSUM_INDEX = 8
511533 checksum : int = packet [CHECKSUM_INDEX ]
0 commit comments