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

Invalid Type Values - Quality (INVALID/RESERVED) #281

Open hanusek opened 3 years ago

hanusek commented 3 years ago

When I read the value from the server (value on server == 2 [Reserved]) then the client (python) reads the value == 1 [Invalid]

Code:

#define QUALITY_VALIDITY_GOOD 0
#define QUALITY_VALIDITY_INVALID 2
#define QUALITY_VALIDITY_RESERVED 1
#define QUALITY_VALIDITY_QUESTIONABLE 3

source: https://github.com/mz-automation/libiec61850/blob/8c1b75b382a7aa45918b850bf6f801de83cc0a4c/src/iec61850/inc/iec61850_common.h#L314

Correct values: bits IAttribute name Attribute value
0-1 Validity Validity Good(00) / Invalid(01) /Reserved(10) / Questionable(11)

source: https://www.diva-portal.org/smash/get/diva2:1052501/FULLTEXT01.pdf (Table 4) https://libiec61850.com/csharp-api/namespace_i_e_c61850_1_1_common.html

hanusek commented 3 years ago

I use the libiec6185 library in python. I did write quick fix:

def read_quality(var_name):
    con = iec61850.IedConnection_create()
    error = iec61850.IedConnection_connect(con, "127.0.0.1", 102)
    if error != iec61850.IED_ERROR_OK:
        iec61850.IedConnection_destroy(con)
        assert False, "IEC-61850 connection failed!"

    obj = iec61850.IedConnection_readObject(con, var_name, iec61850.IEC61850_FC_ST)
    bs = ""
    for i in range(2):
        b = iec61850.MmsValue_getBitStringBit(obj[0], i)
        bs = bs + str(int(b))

    q = int(bs, 2)
    iec61850.IedConnection_close(con)
    iec61850.IedConnection_destroy(con)
    return q