libiec61850 icon indicating copy to clipboard operation
libiec61850 copied to clipboard

How to read INT16U in Python?

Open hanusek opened this issue 5 years ago • 3 comments

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)

hanusek avatar Nov 09 '20 17:11 hanusek

It should work this way. What is the error?

mzillgith avatar Nov 10 '20 15:11 mzillgith

It should work this way. What is the error?

Value is 0. Correct value is 2.

hanusek avatar Nov 10 '20 16:11 hanusek

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

hanusek avatar Nov 10 '20 17:11 hanusek