Skip to content

Commit

Permalink
Merge pull request #62 from DownD/Allow-to-send-specific-byte-array
Browse files Browse the repository at this point in the history
Allow the user to send a user specified bytearray
  • Loading branch information
PowerBroker2 authored Sep 2, 2022
2 parents 6958f93 + d83c31d commit 20a4b3c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pySerialTransfer/pySerialTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ def tx_obj(self, val, start_pos=0, byte_format='', val_type_override=''):
val_bytes = struct.pack(self.byte_format + format_str, bytes(str(val), "utf-8"))
else:
val_bytes = struct.pack(self.byte_format + format_str, val)

return self.tx_struct_obj(val_bytes, start_pos)

def tx_struct_obj(self, val_bytes, start_pos=0):
'''
Description:
-----------
Insert a byte array into the TX buffer starting at the
specified index
:param val_bytes: bytearray - value to be inserted into TX buffer
:param start_pos: int - index of TX buffer where the first byte
of the value is to be stored in
:return: int - index of the last byte of the value in the TX buffer + 1,
None if operation failed
'''

for index in range(len(val_bytes)):
self.txBuff[index + start_pos] = val_bytes[index]
Expand Down

0 comments on commit 20a4b3c

Please sign in to comment.