def send(self, b, end=False):
"""Send up to 7 bytes of data.
:param bytes b:
0 - 7 bytes of data to transmit.
:param bool end:
If this is the last data.
"""
assert len(b) <= 7, "Max 7 bytes can be sent"
if not end:
assert len(b) == 7, "Less than 7 bytes only allowed if last data"
self._seqno += 1
command = self._seqno
if end:
command |= NO_MORE_BLOCKS
self._done = True
# Change expected ACK:ed sequence
self._blksize = self._seqno
# Save how many bytes this message contains since this is the last
self._last_bytes_sent = len(b)
request = bytearray(8)
request[0] = command
request[1:len(b) + 1] = b
self.sdo_client.send_request(request)
self.pos += len(b)
if self.crc_supported:
# Calculate CRC
self._crc = binascii.crc_hqx(b, self._crc)
if self._seqno >= self._blksize:
# End of this block, wait for ACK
self._block_ack()
评论列表
文章目录