I'm currently working on a small interface that communicates with an FPGA via serial port. It works quite fine, but the data i get is a string e.g. '00CCEE' which has to be interpreted as hex values so 00CCEE is 0x00CCEE.
I read here(How to build and send hex commands to TV) that you can simply rewrite your string as hex like this: \x00\xCC\xEE
I did this with a regex:
plainText = re.sub("(.{2})", "\\x\\1", plainText, 0, re.DOTALL)
Now i'm sending this string to the device:
\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF
This should be 16 Bytes, but ser.write() returns 64. Meaning that it wrote 64 Bytes(each character in the stirng as a byte) instead of interpreting it as a hex value.
Here is the corresponding piece of code
plainText = re.sub("(.{2})", "\\x\\1", plainText, 0, re.DOTALL)
print ser.isOpen()
print plainText
AmountPlain = ser.write(plainText)
print AmountPlain
And the Output then is
\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF
True
64
Any clues?