mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
857 stars 459 forks source link

How convert a void *data in python? #1

Closed hackerboygn closed 7 years ago

hackerboygn commented 7 years ago

I want find the LD name in python like this:

deviceList, error = iec61850.IedConnection_getLogicalDeviceList(con)
assert (error == iec61850.IED_ERROR_OK)
device = iec61850.LinkedList_getNext(deviceList)
while device:
    print device.data
    device = iec61850.LinkedList_getNext(device)

But 'device.data' is a SWIG void obj, so result is: `<Swig Object of type 'void ' at 0x........>`

I don't know how convert it in python, just modify the 'iec61850.i':

%module iec61850
%{
......
char* Prt2Char(void *prt)
{ return (char*)prt;}
%}
......
char* Prt2Char(void *prt);

then I try again like this:

......
while device:
    print iec61850.Prt2Char(device.data)
......

It's work, but I don't think is good way, does anyone have a better idea?

cedricboudinet commented 7 years ago

Hello

The trouble is that LinkedList.device type is void, so you have to convert it explicitly to char (like it is done in C with the cast). This can be done with the toCharP function that has already been implemented (there is an example in the README.md of pyiec61850 directory).

Cedric

hackerboygn commented 7 years ago

@cedricboudinet I used the old version(http://libiec61850.com/libiec61850/wp-content/uploads/2016/11/libiec61850-1.0.0.tgz) without these features, now I found out in the git repository.

Thanks again!