|
44 | 44 |
|
45 | 45 | # Python 3rd party imports |
46 | 46 | from serial import Serial |
| 47 | +from serial.serialutil import SerialException |
47 | 48 |
|
48 | 49 | # Nordic Semiconductor imports |
49 | 50 | from nordicsemi.dfu.dfu_transport import DfuTransport, DfuEvent, TRANSPORT_LOGGING_LEVEL |
@@ -116,7 +117,12 @@ def __init__(self, serial_port): |
116 | 117 | def send_message(self, data): |
117 | 118 | packet = Slip.encode(data) |
118 | 119 | logger.log(TRANSPORT_LOGGING_LEVEL, 'SLIP: --> ' + str(data)) |
119 | | - self.serial_port.write(packet) |
| 120 | + try: |
| 121 | + self.serial_port.write(packet) |
| 122 | + except SerialException as e: |
| 123 | + raise NordicSemiException('Writing to serial port failed: ' + str(e) + '. ' |
| 124 | + 'If MSD is enabled on the target device, try to disable it ref. ' |
| 125 | + 'https://wiki.segger.com/index.php?title=J-Link-OB_SAM3U') |
120 | 126 |
|
121 | 127 | def get_message(self): |
122 | 128 | current_state = Slip.SLIP_STATE_DECODING |
@@ -351,6 +357,11 @@ def __calculate_checksum(self): |
351 | 357 | self.dfu_adapter.send_message([DfuTransportSerial.OP_CODE['CalcChecSum']]) |
352 | 358 | response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum']) |
353 | 359 |
|
| 360 | + if response is None: |
| 361 | + raise NordicSemiException('Did not receive checksum response from DFU target. ' |
| 362 | + 'If MSD is enabled on the target device, try to disable it ref. ' |
| 363 | + 'https://wiki.segger.com/index.php?title=J-Link-OB_SAM3U') |
| 364 | + |
354 | 365 | (offset, crc) = struct.unpack('<II', bytearray(response)) |
355 | 366 | return {'offset': offset, 'crc': crc} |
356 | 367 |
|
|
0 commit comments