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
858 stars 460 forks source link

Client can't access dataset vars with pylibiec61850 #428

Closed llutze2s closed 1 year ago

llutze2s commented 1 year ago

Hi,

I have problems reading the dataset vars on the client-side with the pylibiec61850 lib.

I checked my MMS Server config with the IED Explorer. The Explorer can access the datasets without problems.

IED Explorer: image

With my client I can also access individual variables without any problems (iec61850.IedConnection_readFloatValue). When I access the dataset with the command iec61850.ClientDataSet_getValues(dataSetObj), I get an object of type "MMS Value *". I have tested everything and only get "0.0"/"0"/"None" as value when I use the iec16850.MmsValue_toXY() function. When I try to go deeper into the MMS value (as in client_example4.c), I get a segregation error.

I would be grateful for any help or hints!

Output: image

My Client Code:

#!/usr/bin/python
import sys
import os
import time
import signal

# lib for IEC61850 traffic
import iec61850

# Function for connecting to IEC61850 Server 
def testClient():
    while True:
        con = iec61850.IedConnection_create()
        error = iec61850.IedConnection_connect(con, os.environ.get('SERVERIP'), int(os.environ.get('TCPPORT')))
        if (error == iec61850.IED_ERROR_OK):
            # Reading vars with Datasets
            # A data set in IEC 61850 is a list of variables that can be observed and transmitted together in a more efficient manner. Source: https://libiec61850.com/glossary/

            [dataSetDirectory,error] = iec61850.IedConnection_getDataSetDirectory(con, "Trafostation1_Trafo1/MMXU_LV_1$Trafo1_DS_MMXU_LV_1", None)
            #<iec61850.sLinkedList; proxy of <Swig Object of type 'LinkedList' at 0x7f5727f52120>>
            print(dataSetDirectory)

            [dataSetObj,error] = iec61850.IedConnection_readDataSetValues(con, "Trafostation1_Trafo1/MMXU_LV_1$Trafo1_DS_MMXU_LV_1", None)
            #<Swig Object of type 'sClientDataSet *' at 0x7f5727f52900>
            print(dataSetObj)
            # Trafostation1_Trafo1/MMXU_LV_1$Trafo1_DS_MMXU_LV_1
            print(iec61850.ClientDataSet_getReference(dataSetObj))

            dataSetEntrys = iec61850.ClientDataSet_getValues(dataSetObj)
            # 6 Elements
            print(iec61850.MmsValue_getArraySize(dataSetEntrys))

            if dataSetDirectory != None:
                for i in range(iec61850.MmsValue_getArraySize(dataSetEntrys)):
                    if iec61850.MmsValue_getElement(dataSetEntrys, i) != None:
                        value = iec61850.MmsValue_getElement(dataSetEntrys, i)
                        print("Index: "+str(i))
                        print(value)
                        # Float values
                        print(iec61850.MmsValue_getType(value))
                        print(iec61850.MmsValue_toFloat(value))
                        # Try every type just in case
                        print(iec61850.MmsValue_toDouble(value))
                        print(iec61850.MmsValue_toInt32(value))
                        print(iec61850.MmsValue_toInt64(value))
                        print(iec61850.MmsValue_toString(value))
                        print(iec61850.MmsValue_toUint32(value))

            iec61850.IedConnection_close(con)
            print(time.strftime("%H:%M:%S")+": client ok")
        else:
            print(time.strftime("%H:%M:%S")+": Connection error")

        iec61850.IedConnection_destroy(con)
        time.sleep(60)

if __name__ == "__main__":
    testClient()
llutze2s commented 1 year ago

The error was that the index of the dataset entry was 1 instead of -1 (iec.DataSetEntry_create(DS_MMXU_LV_1, "MMXU_LV_1$MX$PhV$phsA$cVal", -1, None))