I am using the lib presented in https://github.com/cmcqueen/cobs-python to make sure i can send data over a serial line. However, this lib requires a string as input, which can be about anything (text files, images, etc...). Since I'm using serial line without any special features on, there is no need to worry about special characters triggering some events.
If I could, I would send for example the image in raw mode, since it does not matter how the data is passed to the other end, but I need to encode it with this lib.
I have tried the following:
data = open('img.jpg', 'wb')
cobs_packet = cobs.encode(''.join(data).encode('utf-8'))
This gives me the following error:
>>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
The problem is, if I use different encoding types, the data length is changed, and that can't happen for what I'm trying to do.
Isn't there any way to simply convert the input to string as-is?
EDIT: I'm using python version 2.7