def checkConnected(ip): try: con = iec61850.IedConnection_create() error = iec61850.IedConnection_connect(con, ip, tcpPort) state = iec61850.IedConnection_getState(con) if (error == iec61850.IED_ERROR_OK): iec61850.IedConnection_destroy(con) return True else: iec61850.IedConnection_destroy(con) return False except Exception: print("Connection error") sys.exit(-1) iec61850.IedConnection_destroy(con)
def testClient(): con = iec61850.IedConnection_create() error = iec61850.IedConnection_connect(con, "localhost", tcpPort) if (error == iec61850.IED_ERROR_OK): # Accessing to SAV values theVal = "testmodelSENSORS/TTMP1.TmpSv.instMag.f" theValType = iec61850.IEC61850_FC_MX temperatureValue = iec61850.IedConnection_readFloatValue( con, theVal, theValType) assert (temperatureValue[1] == 0) newValue = temperatureValue[0] + 10 err = iec61850.IedConnection_writeFloatValue(con, theVal, theValType, newValue) assert (err == 21) # Accessing to ASG values theVal = "testmodelSENSORS/TTMP1.TmpSp.setMag.f" theValType = iec61850.IEC61850_FC_SP temperatureSetpoint = iec61850.IedConnection_readFloatValue( con, theVal, theValType) print(temperatureSetpoint) assert (temperatureValue[1] == 0) newValue = temperatureValue[0] + 10 err = iec61850.IedConnection_writeFloatValue(con, theVal, theValType, newValue) assert (err == 0) temperatureSetpoint = iec61850.IedConnection_readFloatValue( con, theVal, theValType) print(temperatureSetpoint) assert (temperatureSetpoint[0] == newValue) iec61850.IedConnection_close(con) else: print("Connection error") sys.exit(-1) iec61850.IedConnection_destroy(con) print("client ok")
def getLNlist_fromIED(ip): res_list = [] con = iec61850.IedConnection_create() error = iec61850.IedConnection_connect(con, ip, tcpPort) state = iec61850.IedConnection_getState(con) if (error == iec61850.IED_ERROR_OK): [deviceList, error] = iec61850.IedConnection_getLogicalDeviceList(con) device = iec61850.LinkedList_getNext(deviceList) size = iec61850.LinkedList_size(deviceList) while device: #Iterate over each device from deviceList [logicalNodes, error] = iec61850.IedConnection_getLogicalDeviceDirectory( con, iec61850.toCharP(device.data)) lnode = iec61850.LinkedList_getNext(logicalNodes) while lnode: #Iterate over each node from LNodeList LN_name = iec61850.toCharP(lnode.data) res_list.append(LN_name) lnode = iec61850.LinkedList_getNext(lnode) iec61850.LinkedList_destroy(logicalNodes) device = iec61850.LinkedList_getNext(device) iec61850.LinkedList_destroy(deviceList) iec61850.IedConnection_close(con) else: print("Connection error") sys.exit(-1) iec61850.IedConnection_destroy(con) return res_list
def run_client(ip, dt, var): print(ip, dt, var) con = iec61850.IedConnection_create() timeout = iec61850.IedConnection_setConnectTimeout(con, 2000) error = iec61850.IedConnection_connect(con, ip, tcpPort) state = iec61850.IedConnection_getState(con) if (error == iec61850.IED_ERROR_OK and state): print("Good connection") if dt == 'b': [booleanValue, error] = iec61850.IedConnection_readBooleanValue( con, var, iec61850.IEC61850_FC_ST) print("booleanValue: ", booleanValue) elif dt == 'f': [analogValue, error ] = iec61850.IedConnection_readFloatValue(con, var, iec61850.IEC61850_FC_MX) print("Analog Value: ", analogValue) elif dt == 't': time = iec61850.Timestamp() [timeStampValue, error] = iec61850.IedConnection_readTimestampValue( con, var, iec61850.IEC61850_FC_MX, time) print("timeStampValue: ", iec61850.Timestamp_getTimeInSeconds(time)) elif dt == 'q': [qualityValue, error] = iec61850.IedConnection_readQualityValue( con, var, iec61850.IEC61850_FC_MX) print("qualityValue: ", qualityValue) else: print("Connection error status") sys.exit(-1) iec61850.IedConnection_destroy(con) print("Client OK")
def install_handler1(self): print("Start") hostname = "localhost" tcpPort = 102 con = iec61850.IedConnection_create() error = iec61850.IedConnection_connect(con, hostname, tcpPort) print(str(error)) CB_PROTO = CFUNCTYPE(None, c_void_p, c_void_p) cbinst = CB_PROTO(self.func_handler) val = c_int() api = CDLL("/home/ivan/Projects/libiec61850/build/src/libiec61850.so") ReportHandler = api.IedConnection_installReportHandlerAddr ReportHandler.argtypes = [ c_uint, c_char_p, c_char_p, CB_PROTO, c_void_p ] ReportHandler.restype = None addr = iec61850.IedConnection_ToAddress(con) rcb, error = iec61850.IedConnection_getRCBValues( con, "TEMPLATELD0/LLN0.BR.brcbST0101", None) print("RCB:" + str(rcb)) rid = iec61850.ClientReportControlBlock_getRptId(rcb) print("OriginalID: " + rid) rptRef = create_string_buffer(b"TEMPLATELD0/LLN0.BR.brcbST0101") rptID = create_string_buffer(b"TEMPLATELD0/LLN0$BR$brcbST0101") ReportHandler(addr, rptRef, rptID, cbinst, None) print("Enabled " + str(iec61850.ClientReportControlBlock_getRptEna(rcb))) iec61850.ClientReportControlBlock_setTrgOps( rcb, iec61850.TRG_OPT_DATA_UPDATE | iec61850.TRG_OPT_GI) iec61850.ClientReportControlBlock_setRptEna(rcb, True) error = iec61850.IedConnection_setRCBValues( con, rcb, iec61850.RCB_ELEMENT_RPT_ENA | iec61850.RCB_ELEMENT_TRG_OPS, True) print(error) if (error == iec61850.IED_ERROR_OK): print("Connection is OK") else: print("Connection error status") print("Enabled " + str(iec61850.ClientReportControlBlock_getRptEna(rcb))) input("Wait input ... ") iec61850.IedConnection_close(con) iec61850.IedConnection_destroy(con)
value1 = iec61850.IedConnection_readStringValue(con, theVal1, theValType1); print(" Read Value of TTMP1.Temp1.string: %s" % value1[0]); assert(value1[1]==0) newValue1= value1[0] err1 = iec61850.IedConnection_writeVisibleStringValue(con, theVal1, theValType1, newValue1) assert(err1==21) # Accessing to VSG values theVal1 = "testmodelSENSORS/TTMP1.TmpSt.setVal" theValType1 = iec61850.IEC61850_FC_SP setpoint1 = iec61850.IedConnection_readStringValue(con, theVal1, theValType1) assert(value1[1]==0) newValue1= "Networked System Lab" err1 = iec61850.IedConnection_writeVisibleStringValue(con, theVal1, theValType1, newValue1) assert(err1==0) #Write Data Object with new value setpoint1 = iec61850.IedConnection_readStringValue(con, theVal1, theValType1) print(" Write Value of TTMP1.Temp1.string: %s" % setpoint1[0]) assert(setpoint1[0]==newValue1) time.sleep(5) else: print("Connection error") sys.exit(-1) iec61850.IedConnection_close(con) iec61850.IedConnection_destroy(con) print("\n Client Disconnected.")
def stop(self): iec61850.IedConnection_close(self.__con) iec61850.IedConnection_destroy(self.__con)
def stop(self): self.logger.debug("stopping iec-61850 client") iec61850.IedConnection_close(self._con) iec61850.IedConnection_destroy(self._con)