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
854 stars 457 forks source link

How to read INT16U in Python? #276

Open hanusek opened 3 years ago

hanusek commented 3 years ago

Hello. how to read INT16U value by IEC client?

This not working:

def read_int16u(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!"
    val = iec61850.IedConnection_readUnsigned32Value(con, var_name, iec61850.IEC61850_FC_ST)
    print("READ IEC Var: ", var_name, " value: ", val)
    iec61850.IedConnection_close(con)
    iec61850.IedConnection_destroy(con)
mzillgith commented 3 years ago

It should work this way. What is the error?

hanusek commented 3 years ago

It should work this way. What is the error?

Value is 0. Correct value is 2.

hanusek commented 3 years ago

I did solved this problem.

I did created new function -> IedConnection_readBitStringAsIntegerBigEndian()

def read_bit_string(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!"
    val = iec61850.IedConnection_readBitStringAsIntegerBigEndian(con, var_name, iec61850.IEC61850_FC_ST)
    print("READ IEC Var:", var_name, " value:", val)
    iec61850.IedConnection_close(con)
    iec61850.IedConnection_destroy(con)
    return val[0]

My pull request - https://github.com/mz-automation/libiec61850/pull/277