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

Python - how to write boolean value? #173

Open hanusek opened 4 years ago

hanusek commented 4 years ago

Hello. I have a problem with write to ### CSWI1.Pos.Oper.ctlVal. Whats wrong?

    con = iec61850.IedConnection_create()
    error = iec61850.IedConnection_connect(con, "127.0.0.1", 102)
    if (error == iec61850.IED_ERROR_OK):
        theVal = "IECLDevice/CSWI1.Pos.Oper.ctlVal"
        theValType = iec61850.IEC61850_FC_CO
        err = iec61850.IedConnection_writeBooleanValue(con, theVal, theValType, True)
        print ("Error: " + str(err))
        assert(err == 0), "IEC-61850  Cannot write bool"
        iec61850.IedConnection_close(con)
        iec61850.IedConnection_destroy(con)
        print("IEC-61850 Write Bool OK")

Output : Error: 21

mzillgith commented 4 years ago

Hello. You cannot directly write to "Oper.ctlVal". The server won't accept it as it requires the whole "Oper" structure to execute a command. The library has support for send correct commands with the ControlObjectClient functions. Please see _iec61850_client_examplecontrol. There is no example in Python for that.

hanusek commented 4 years ago

I solved this problem.

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!"
setVal = iec61850.MmsValue_newBoolean(True)
assert setVal is not None, "IEC-61850 MmsValue_newBoolean failed!"
var = "IECLDevice/CSWI1.Pos"
ctrlobj = iec61850.ControlObjectClient_create(var, con)
assert ctrlobj is not None, "IEC-61850 ControlObjectClient_create failed!"     
print ("Operating : %s value : %s" % (var, value))
res = iec61850.ControlObjectClient_operate(ctrlobj, setVal, 0)
assert(res == False), "IEC-61850  Cannot operate."
iec61850.IedConnection_close(con)
iec61850.IedConnection_destroy(con)
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?