Hi Chris,
On Monday, 5. October 2015 12:18:50 Chris Brackert wrote:
> Regardless of using python2 or python3, libftdi’s write_data takes a
> “string”. In python2 this means bytes and in python3 this means unicode.
>
>
> My problem is that certain strings are not being written properly with
> python3. For example, when ‘\xAB’ is encoded to bytes with UTF-8 (as it
> does in libftdi), it turns into b’\xC2\xAB’.
>
>
> I have a temporary fix that is working for me and it involves modifying
> the swig built file `build/python/ftdi1PYTHON_wrap.c`. In the function
> SWIG_AsCharPtrAndSize I replace PyUnicode_AsUTF8String with
> PyUnicode_AsLatin1String in line 3161. Now python3 unicode strings are
> converted using Latin-1 so my example ‘\xAB’ converts to the byte b’\AB’
> instead of the bytes b’\xC2\xAB’.
>
>
> I know this fix is not the proper way to do this but it is working for me.
> Can you please investigate this issue and fix the library to work with
> all python3 strings?
>
>
> Another option I would be happy with is for ftdi.write_data to accept
> python3 bytes instead of unicode. As of now, if you try and actually pass
> the bytes b’\xAB’ to write_data, libftdi complains about the type not
> being correct.
this is probably something in the swig layer that generates
the wrapper code. I don't know swig myself, but I guess we need
to configure it to do better type mapping or so.
@xantares09: Any idea about this?
Cheers,
Thomas
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|