@@ -470,6 +470,7 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
470
470
self ._crc = sdo_client .crc_cls ()
471
471
self ._server_crc = None
472
472
self ._ackseq = 0
473
+ self ._error = False
473
474
474
475
logger .debug ("Reading 0x%X:%d from node %d" , index , subindex ,
475
476
sdo_client .rx_cobid - 0x600 )
@@ -483,9 +484,12 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
483
484
response = sdo_client .request_response (request )
484
485
res_command , res_index , res_subindex = SDO_STRUCT .unpack_from (response )
485
486
if res_command & 0xE0 != RESPONSE_BLOCK_UPLOAD :
487
+ self ._error = True
488
+ self .sdo_client .abort (0x05040001 )
486
489
raise SdoCommunicationError ("Unexpected response 0x%02X" % res_command )
487
490
# Check that the message is for us
488
491
if res_index != index or res_subindex != subindex :
492
+ self ._error = True
489
493
raise SdoCommunicationError ((
490
494
"Node returned a value for 0x{:X}:{:d} instead, "
491
495
"maybe there is another SDO client communicating "
@@ -537,6 +541,7 @@ def read(self, size=-1):
537
541
self ._crc .process (data )
538
542
if self ._done :
539
543
if self ._server_crc != self ._crc .final ():
544
+ self ._error = True
540
545
self .sdo_client .abort (0x05040004 )
541
546
raise SdoCommunicationError ("CRC is not OK" )
542
547
logger .info ("CRC is OK" )
@@ -556,6 +561,8 @@ def _retransmit(self):
556
561
# We should be back in sync
557
562
self ._ackseq = seqno
558
563
return response
564
+ self ._error = True
565
+ self .sdo_client .abort (0x05040000 )
559
566
raise SdoCommunicationError ("Some data were lost and could not be retransmitted" )
560
567
561
568
def _ack_block (self ):
@@ -571,9 +578,11 @@ def _end_upload(self):
571
578
response = self .sdo_client .read_response ()
572
579
res_command , self ._server_crc = struct .unpack_from ("<BH" , response )
573
580
if res_command & 0xE0 != RESPONSE_BLOCK_UPLOAD :
581
+ self ._error = True
574
582
self .sdo_client .abort (0x05040001 )
575
583
raise SdoCommunicationError ("Unexpected response 0x%02X" % res_command )
576
584
if res_command & 0x3 != END_BLOCK_TRANSFER :
585
+ self ._error = True
577
586
self .sdo_client .abort (0x05040001 )
578
587
raise SdoCommunicationError ("Server did not end transfer as expected" )
579
588
# Return number of bytes not used in last message
@@ -583,7 +592,7 @@ def close(self):
583
592
if self .closed :
584
593
return
585
594
super (BlockUploadStream , self ).close ()
586
- if self ._done :
595
+ if self ._done and not self . _error :
587
596
request = bytearray (8 )
588
597
request [0 ] = REQUEST_BLOCK_UPLOAD | END_BLOCK_TRANSFER
589
598
self .sdo_client .send_request (request )
0 commit comments