lsgunth / pyft232

Python bindings to d2xx and libftdi to access FT232 chips with the same interface as pyserial
GNU Lesser General Public License v2.1
11 stars 11 forks source link

sending integer as raw byte #11

Closed JBSchueler closed 5 years ago

JBSchueler commented 5 years ago

This is not a driver issue but I am unable to find the right answer.

outputStr = bytearray([123, 32, 12, 1, 245])

for h in outputStr:
   sp.write( h )

this gives an error...

outputStr = bytearray([123, 32, 12, 1, 245])

for h in outputStr:
   sp.write( sp.write( (format(h, "c")) ) )

Now I get a TypeError

Traceback (most recent call last):
  File "ftwrite.py", line 79, in <module>
    sp.write( (format(h, "c")) )
  File "C:\Users\bsc\AppData\Local\Programs\Python\Python37\lib\site-packages\ft232\d2xx.py", line 339, in write
    buf = c.create_string_buffer(s)
  File "C:\Users\bsc\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 63, in create_string_buffer
    raise TypeError(init)
TypeError: ª

So I tried

outputStr = bytearray([123, 32, 12, 1, 245])

for h in outputStr:
   sp.write( chr(h).encode('utf-8') )

Now I am able to print but for none-ascii chars I get 2 bytes

Can someone help me to just send raw bytes?

JBSchueler commented 5 years ago

Uhm... problem solved...

sp.write( bytes(outputStr) )