Serial Comm shared library sending wrong data when used with ctypes

Python in C/C++ embedden, C-Module, ctypes, Cython, SWIG, SIP etc sind hier richtig.
Antworten
sandeepmanjunath22
User
Beiträge: 2
Registriert: Montag 25. Juni 2018, 09:54

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.
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

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.
sandeepmanjunath22
User
Beiträge: 2
Registriert: Montag 25. Juni 2018, 09:54

Thank you for your suggestion. I will give CFFI a try.
Benutzeravatar
DeaD_EyE
User
Beiträge: 1012
Registriert: Sonntag 19. September 2010, 13:45
Wohnort: Hagen
Kontaktdaten:

PySerial is not an option for you?
sourceserver.info - sourceserver.info/wiki/ - ausgestorbener Support für HL2-Server
Antworten