(s: serial.Serial)
| 99 | |
| 100 | |
| 101 | def reader(s: serial.Serial): |
| 102 | starting = False |
| 103 | count = 0 |
| 104 | command = bytes() |
| 105 | while True: |
| 106 | b = s.read() |
| 107 | if len(b) != 0: |
| 108 | if count: |
| 109 | count -= 1 |
| 110 | if count == 0: |
| 111 | if calc_crc8(command) == ord(b): |
| 112 | print("resp: " + "".join("%02x " % x for x in command)) |
| 113 | process(command) |
| 114 | else: |
| 115 | s.flushInput() |
| 116 | else: |
| 117 | command += b |
| 118 | elif starting: |
| 119 | starting = False |
| 120 | if ord(b) > 62: |
| 121 | s.flushInput() |
| 122 | else: |
| 123 | count = ord(b) |
| 124 | command = bytes() |
| 125 | else: |
| 126 | starting = True |
| 127 | |
| 128 | |
| 129 | def send(s: serial.Serial, sync: int, line: bytes): |