Seite 1 von 1

Serial Comm shared library sending wrong data when used with ctypes

Verfasst: Montag 25. Juni 2018, 10:03
von sandeepmanjunath22
Hello All,
I have a built a simple serial communication shared library which i am trying to use in python using the ctypes library. The steps that i am following are:
1. Load the .so file by calling ctypes.cdll.loadlibrary().
2. Initialize the serial communication module.
3. Send 0xFF as sync bytes.

When i do the above steps i am not getting only junk data at the other end. Funnily when i use the .so file in C and do the same operation it works absolutely fine. So My question is does the ctypes module manipulate the loaded library in any way? I am quite new to using C in Python and i am drawing blank here. Any suggestions would be very helpful.
Thanks in advance.

Re: Serial Comm shared library sending wrong data when used with ctypes

Verfasst: Montag 25. Juni 2018, 10:33
von __deets__
As you do not show any code, we can't possibly get to the bottom of this. Wrapping a C API in ctypes has a few pitfalls, you might want to consider using CFFI instead, as that reads your .h header for the C-lib & generates bindings that match types and subtleties like paddings etc. But if you want more help, please provide code.

Also this is a mainly german speaking forum. You're welcome to post here of course, but you might have greater reach on stack overflow or the english python sources such as comp.lang.python etc.

Re: Serial Comm shared library sending wrong data when used with ctypes

Verfasst: Montag 25. Juni 2018, 14:58
von sandeepmanjunath22
Thank you for your suggestion. I will give CFFI a try.

Re: Serial Comm shared library sending wrong data when used with ctypes

Verfasst: Montag 25. Juni 2018, 16:31
von DeaD_EyE
PySerial is not an option for you?