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 to utilize control operation for Python (SWIG)? #67

Open libusr opened 6 years ago

libusr commented 6 years ago

I've managed to build the lib for Python and now am using it to run a IEC 61850 server. However SWIG was not able to adopt the control model callback "typedef ControlHandlerResult" in order to utilize the corresponding IedServer_setControlHandler(). The way I see it, there are two options to convert the callback function / typedefs via SWIG:

  1. Modifying the interface-file (*.i) and adding the callback.
  2. Modifying the C source code and rewriting the function. Anyway I'm struggling to find the correct solution to make the control operation available in Python, mainly because my skills in C are only very basic. Also my aim is to use the libIEC61850 in Python, since I'm connecting to different APIs via Python.

How can I utilize the control operation with Python? Does anyone have a description on how to modify the interface file or the source code in order to utilize the control operation with Python?

Regards!

darkjhesus commented 4 years ago

Could you share the python library, I have problems trying to compile in python 3.6. When I impot the module I get the next error: ImportError: DLL load failed: No se puede encontrar el módulo especificado

Could you help me?

libusr commented 4 years ago

I have a version for Python 3.7, feel free to use it. Note that with this build the original problem regarding the utilization of the control operation remains unsolved. 20190826_libiec61850_py37.zip

darkjhesus commented 4 years ago

Dear libusr, What is the OS thaht you use with python, Windows 32 64 bits or Linux?

libusr commented 4 years ago

I'm running it on Win10, 64 bit.

darkjhesus commented 4 years ago

Maybe do you have some example to read comtrade files from IED??

libusr commented 4 years ago

Sorry, no example for this function yet. But I would also be interessted in the solution. Please share

darkjhesus commented 4 years ago

I am trying to develope some code to do this but I don't know how to use the function iec61850.LinkedList_destroyDeep. Maybe have you ever work with this function?

libusr commented 4 years ago

I'm only familiar with the *.LinkedList_destroy function, which is part of the Python client example. No need for destroyDeep in my use cases.

darkjhesus commented 4 years ago

Dear, I implement another method and it is succefull, but I am getting the next data: '\udcd0\udcf2\udcee\x0f\udcb9\n' 'p\udcf0\udcee\x0f%\udc93' 'p\udcf3\udcee\x0f\udc89\n'

These values are one in each iteration.

The code implemented is: folList = iec61850.IedConnection_getFileDirectory(con,'') direcEntry = iec61850.LinkedList_getNext(folList[0]) while(direcEntry != None): aux1 = direcEntry.data

I would like to know how could I convert this data to string.? Sin título

slemadin commented 4 years ago

It seems that we are working on the same thing. I used your code and file-tool.c to make something that should work but I still have a problem:

    rootdir = iec61850.IedConnection_getFileDirectory(con,'')
    iec61850.LinkedList_printStringList(rootdir[0])
    direcEntry = iec61850.LinkedList_create()
    direcEntry = iec61850.LinkedList_getNext(rootdir[0])
    while direcEntry:
        #FileDirectoryEntry entry = (FileDirectoryEntry) direcEntry.data
        print(iec61850.FileDirectoryEntry_getFileName(direcEntry.data))
        direcEntry = iec61850.LinkedList_getNext(direcEntry)

The commented line is the one that should be translated to python (right now it is just c/p from C). I don't seem to be able to create FileDirectoryEntry because no such function is available in iec61850.py, and the FileDirectoryEntry_create(fileName, fileSize, lastModified) requres arguments that I can't give because they are what I want to get in the first place. Documentation says it's deprecated and will be removed from API.

Any ideas?

darkjhesus commented 4 years ago

I couldn't solve the problem showed above, I finally had to use the C# library.

darkjhesus commented 4 years ago

You could write to my mail pro_ele_pro@outlook.comq

ogunozfidan commented 3 years ago

It seems that we are working on the same thing. I used your code and file-tool.c to make something that should work but I still have a problem:

  rootdir = iec61850.IedConnection_getFileDirectory(con,'')
  iec61850.LinkedList_printStringList(rootdir[0])
  direcEntry = iec61850.LinkedList_create()
  direcEntry = iec61850.LinkedList_getNext(rootdir[0])
  while direcEntry:
      #FileDirectoryEntry entry = (FileDirectoryEntry) direcEntry.data
      print(iec61850.FileDirectoryEntry_getFileName(direcEntry.data))
      direcEntry = iec61850.LinkedList_getNext(direcEntry)

The commented line is the one that should be translated to python (right now it is just c/p from C). I don't seem to be able to create FileDirectoryEntry because no such function is available in iec61850.py, and the FileDirectoryEntry_create(fileName, fileSize, lastModified) requres arguments that I can't give because they are what I want to get in the first place. Documentation says it's deprecated and will be removed from API.

Any ideas?

Hello, I'm having the same trouble. I need to create a FileDirectoryEntry object but the is no class defined in the Python library. When I check if it is defined in the C library. It says it will be removed.

Have you been able to solve the issue?

typedef struct sFileDirectoryEntry* FileDirectoryEntry; /**

slemadin commented 3 years ago

I modified C code from one of the examples to fit my needs and ran compiled .exe from Python.

ogunozfidan commented 3 years ago

Could you give me some details when you're available. I'm pretty new at this. Thank you.

Herve3 commented 3 years ago

To solve this probleme I added:

 FileDirectoryEntry toFileDirectoryEntry(void *data){
        return (FileDirectoryEntry) data;
   }

and

FileDirectoryEntry toFileDirectoryEntry(void *);

in iec61850.i and then recompile the library

with this modification this python code is running:

[rootDirectory, error] = iec61850.IedConnection_getFileDirectory(con, "")
directoryEntry = iec61850.LinkedList_getNext(rootDirectory)
while directoryEntry:
    entry = iec61850.toFileDirectoryEntry(directoryEntry.data)
    file_name=iec61850.FileDirectoryEntry_getFileName(entry)
    print(file_name)
    directoryEntry = iec61850.LinkedList_getNext(directoryEntry)
jeslorena commented 2 years ago

How can I utilize the control operation with Python? Help me please