Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex and serial variable
#1
Hi all,

I am new to pyhton and pyserial and got a question please.

I got a file with hex code

final_CW
b'\xEA\x10\xC6\x26\x4B\x37\xE4\x87\xC3\x2E\xB2\xB6\x9F\x07\x3D\x2D\xC6\x30'

I'd like to send this array to the serial port.


f=open("final_CW","r")
CW = f.read()
print("Send CW")
f.close()
ser.write(CW)
I'd like to send

CW = b'\xEA\x10\xC6\x26\x4B\x37\xE4\x87\xC3\x2E\xB2\xB6\x9F\x07\x3D\x2D\xC6\x30'
ser.write(CW)
I am getting the following error if I read from file.

File "x.last", line 8049, in <module>
ser.write(CW)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 518, in write
d = to_bytes(data)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: "b' \\xEA\\x10\\xC6\\x26\\x4B\\x37\\xE4\\x87\\xC3\\x2E\\xB2\\xB6\\x9F\\x07\\x 3D\\x2D\\xC6\\x30'\n"

Thanks for any help.
Reply


Messages In This Thread
Hex and serial variable - by deal0703 - Feb-11-2019, 08:45 PM
RE: Hex and serial variable - by deal0703 - Feb-13-2019, 03:26 PM
RE: Hex and serial variable - by Larz60+ - Feb-13-2019, 03:34 PM
RE: Hex and serial variable - by deal0703 - Feb-13-2019, 04:25 PM
RE: Hex and serial variable - by Larz60+ - Feb-13-2019, 10:27 PM
RE: Hex and serial variable - by deal0703 - Feb-14-2019, 09:02 AM
RE: Hex and serial variable - by DeaD_EyE - Feb-14-2019, 09:12 AM
RE: Hex and serial variable - by deal0703 - Feb-14-2019, 09:26 AM
RE: Hex and serial variable - by deal0703 - Feb-17-2019, 09:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,030 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  assign the variable to every value received serial from Arduino barry76 4 3,333 Feb-01-2019, 10:19 AM
Last Post: barry76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020