Skip to content

Commit e974983

Browse files
authored
Bug fix for char stuffing
1 parent 37c6c1f commit e974983

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pySerialTransfer/pySerialTransfer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ def tx_obj(self, val, start_pos=0, byte_format='', val_type_override=''):
278278
val_bytes = struct.pack(byte_format + format_str, val)
279279

280280
else:
281-
val_bytes = struct.pack(self.byte_format + format_str, val)
281+
if format_str == 'c':
282+
val_bytes = struct.pack(self.byte_format + format_str, bytes(str(val), "utf-8"))
283+
else:
284+
val_bytes = struct.pack(self.byte_format + format_str, val)
282285

283286
for index in range(len(val_bytes)):
284287
self.txBuff[index + start_pos] = val_bytes[index]
@@ -455,7 +458,7 @@ def send(self, message_len, packet_id=0):
455458
stack.append(STOP_BYTE)
456459

457460
stack = bytearray(stack)
458-
461+
459462
if self.open():
460463
self.connection.write(stack)
461464

0 commit comments

Comments
 (0)