public void ControlWriteAccessToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal"); IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal"); IedServer iedServer = new IedServer(iedModel); int opDlTmmsValue = 0; iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { opDlTmmsValue = value.ToInt32(); return(MmsDataAccessError.SUCCESS); }, null); iedServer.HandleWriteAccess(rsDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { if (value.ToInt32() > 1000) { return(MmsDataAccessError.OBJECT_VALUE_INVALID); } else { return(MmsDataAccessError.SUCCESS); } }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_OBJECT_VALUE_INVALID, e.GetIedClientError()); } connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(999, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); Assert.AreEqual((int)1234, opDlTmmsValue); iedServer.Destroy(); }
public void ControlWriteAccessComplexDAToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg"); IEC61850.Server.DataAttribute setAnVal_setMag = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/LLN0.SetAnVal.setMag"); IedServer iedServer = new IedServer(iedModel); int handlerCalled = 0; MmsValue receivedValue = null; iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); iedServer.HandleWriteAccessForComplexAttribute(setAnVal_setMag, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { receivedValue = value; handlerCalled++; return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue complexValue = MmsValue.NewEmptyStructure(1); complexValue.SetElement(0, new MmsValue((float)1.0)); connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag", FunctionalConstraint.SP, complexValue); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_STRUCTURE, receivedValue.GetType()); Assert.AreEqual(1.0, receivedValue.GetElement(0).ToFloat()); receivedValue.Dispose(); receivedValue = null; connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag.f", FunctionalConstraint.SP, new MmsValue((float)2.0)); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_FLOAT, receivedValue.GetType()); Assert.AreEqual(2.0, receivedValue.ToFloat()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
public void WriteAccessPolicy() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal"); IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal"); IedServer iedServer = new IedServer(iedModel); iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_ALLOW); connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_ACCESS_DENIED, e.GetIedClientError()); } MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(1234, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }