private static bool asduHandler(object parameter, IMasterConnection connection, ASDU asdu) { if (asdu.TypeId == TypeID.C_SC_NA_1) { Console.WriteLine("Single command"); SingleCommand sc = (SingleCommand)asdu.GetElement(0); if (sc.Select) { Console.WriteLine(" received select"); } else { Console.WriteLine(" received execute"); } Console.WriteLine(sc.ToString()); connection.SendACT_CON(asdu, false); } else if (asdu.TypeId == TypeID.C_CS_NA_1) { ClockSynchronizationCommand qsc = (ClockSynchronizationCommand)asdu.GetElement(0); Console.WriteLine("Received clock sync command with time " + qsc.NewTime.ToString()); connection.SendACT_CON(asdu, false); } return(true); }
private static bool asduHandler(object parameter, IMasterConnection connection, ASDU asdu) { if (asdu.TypeId == TypeID.C_SC_NA_1) { Console.WriteLine("Single command"); SingleCommand sc = (SingleCommand)asdu.GetElement(0); Console.WriteLine(sc.ToString()); } else if (asdu.TypeId == TypeID.C_CS_NA_1) { ClockSynchronizationCommand qsc = (ClockSynchronizationCommand)asdu.GetElement(0); Console.WriteLine("Received clock sync command with time " + qsc.NewTime.ToString()); } if (asdu.TypeId == TypeID.M_ME_TF_1) { MeasuredValueShortWithCP56Time2a sc = (MeasuredValueShortWithCP56Time2a)asdu.GetElement(0); Console.WriteLine(sc.ToString()); } if (asdu.TypeId == TypeID.M_ME_NC_1) { MeasuredValueShort sc = (MeasuredValueShort)asdu.GetElement(0); Console.WriteLine(sc.ToString()); } return(true); }
private static bool asduHandler(object parameter, IMasterConnection connection, ASDU asdu) { if (asdu.TypeId == TypeID.C_SC_NA_1) { Console.WriteLine("Single command"); SingleCommand sc = (SingleCommand)asdu.GetElement(0); Console.WriteLine(sc.ToString()); } else if (asdu.TypeId == TypeID.M_EI_NA_1) { Console.WriteLine("End of initialization received"); } else if (asdu.TypeId == TypeID.F_DR_TA_1) { Console.WriteLine("Received file directory"); } else if (asdu.TypeId == TypeID.C_CS_NA_1) { ClockSynchronizationCommand qsc = (ClockSynchronizationCommand)asdu.GetElement(0); Console.WriteLine("Received clock sync command with time " + qsc.NewTime.ToString()); } return(true); }
public async Task ExecuteAsync() { IDataPortal <SingleCommand> dataPortal = _testDIContext.CreateDataPortal <SingleCommand>(); SingleCommand cmd = dataPortal.Create(123); var result = await dataPortal.ExecuteAsync(cmd); Assert.IsNotNull(result); Assert.AreEqual(124, result.Value); }
private static bool asduHandler(object parameter, IMasterConnection connection, ASDU asdu) { if (asdu.TypeId == TypeID.C_SC_NA_1) { SingleCommand sc = (SingleCommand)asdu.GetElement(0); if (sc.ObjectAddress != 100) { // Unkown IOA --> send negative confirmation asdu.Cot = CauseOfTransmission.UNKNOWN_INFORMATION_OBJECT_ADDRESS; asdu.IsNegative = true; connection.SendASDU(asdu); } else { // execute command // send positive confirmation connection.SendACT_CON(asdu, false); } } if (asdu.TypeId == TypeID.C_SC_NA_1) { Console.WriteLine("Single command"); SingleCommand sc = (SingleCommand)asdu.GetElement(0); Console.WriteLine(sc.ToString()); } else if (asdu.TypeId == TypeID.M_EI_NA_1) { Console.WriteLine("End of initialization received"); } else if (asdu.TypeId == TypeID.F_DR_TA_1) { Console.WriteLine("Received file directory"); } else if (asdu.TypeId == TypeID.C_CS_NA_1) { ClockSynchronizationCommand qsc = (ClockSynchronizationCommand)asdu.GetElement(0); Console.WriteLine("Received clock sync command with time " + qsc.NewTime.ToString()); } return(true); }
/// <summary> /// 主站遥控命令 /// </summary> /// <param name="cot">传输原因</param> /// <param name="sco">单命令</param> /// <param name="objectAddr">信息对象地址</param> private void SendMasterCommand(CauseOfTransmissionList cot, SingleCommand sco, UInt32 objectAddr) { try { var id = TypeIdentification.C_SC_NA_1;//遥控命令 eventTypeIDManager.AddEventProcess(new EventProperty(id)); var frame = new MasterCommand(appMessageManager.TransmitSequenceNumber, appMessageManager.RealReceiveSequenceNumber, id, cot, appMessageManager.ASDUADdress, objectAddr, sco.SCO); var array = frame.GetAPDUDataArray(); MainTypeIProcess(array, array.Length, appMessageManager.WaitTime, id); appMessageManager.UpdateTransmitSequenceNumber(); } catch (Exception ex) { MessageBox.Show(ex.Message, "SendMasterCommand主站遥控命令"); } }
BuildInfoObj( Int32 asdu, Int32 addr, Double value, Boolean sbo = false, Int32 cmdqualif = 0, QualityDescriptor quality = null, CP56Time2a time_tag = null, Double kconv1 = 1, Double kconv2 = 0, Boolean transient = false ) { InformationObject sc = null; if (time_tag == null) { time_tag = new CP56Time2a(DateTime.Now); } else { // has time tag, so change ASDU if necessary to embed a timetag var maptowithcp56time = new Dictionary <TypeID, TypeID>(); maptowithcp56time.Add(TypeID.M_SP_NA_1, TypeID.M_SP_TB_1); maptowithcp56time.Add(TypeID.M_DP_NA_1, TypeID.M_DP_TB_1); maptowithcp56time.Add(TypeID.M_ST_NA_1, TypeID.M_ST_TB_1); maptowithcp56time.Add(TypeID.M_BO_NA_1, TypeID.M_BO_TB_1); maptowithcp56time.Add(TypeID.M_ME_NA_1, TypeID.M_ME_TD_1); maptowithcp56time.Add(TypeID.M_ME_NB_1, TypeID.M_ME_TE_1); maptowithcp56time.Add(TypeID.M_ME_NC_1, TypeID.M_ME_TF_1); maptowithcp56time.Add(TypeID.M_IT_NA_1, TypeID.M_IT_TB_1); if (maptowithcp56time.TryGetValue((TypeID)asdu, out var newasdu)) { asdu = (Int32)newasdu; } } Boolean bval; Int32 ival; UInt32 uival; switch ((TypeID)asdu) { case TypeID.M_SP_NA_1: // 1 bval = value != 0 ? true : false; if (kconv1 == -1) { bval = !bval; } sc = new SinglePointInformation(addr, bval, quality); break; case TypeID.M_SP_TB_1: // 30 bval = value != 0 ? true : false; if (kconv1 == -1) { bval = !bval; } sc = new SinglePointWithCP56Time2a(addr, bval, quality, time_tag ); break; case TypeID.M_DP_NA_1: // 3 if (transient) { sc = new DoublePointInformation(addr, DoublePointValue.INTERMEDIATE, quality); } else if (kconv1 == -1) { sc = new DoublePointInformation(addr, value != 0 ? DoublePointValue.OFF : DoublePointValue.ON, quality); } else { sc = new DoublePointInformation(addr, value != 0 ? DoublePointValue.ON : DoublePointValue.OFF, quality); } break; case TypeID.M_DP_TB_1: // 31 if (transient) { sc = new DoublePointWithCP56Time2a(addr, DoublePointValue.INTERMEDIATE, quality, time_tag); } else if (kconv1 == -1) { sc = new DoublePointWithCP56Time2a(addr, value != 0 ? DoublePointValue.OFF : DoublePointValue.ON, quality, time_tag); } else { sc = new DoublePointWithCP56Time2a(addr, value != 0 ? DoublePointValue.ON : DoublePointValue.OFF, quality, time_tag); } break; case TypeID.M_ST_NA_1: // 5 value = value * kconv1 + kconv2; if (value > 63) { value = 63; quality.Overflow = true; } else if (value < -64) { value = -64; quality.Overflow = true; } sc = new StepPositionInformation(addr, System.Convert.ToInt16(value), transient, quality); break; case TypeID.M_ST_TB_1: // 32 value = value * kconv1 + kconv2; if (value > 63) { value = 63; quality.Overflow = true; } else if (value < -64) { value = -64; quality.Overflow = true; } sc = new StepPositionWithCP56Time2a(addr, System.Convert.ToInt16(value), transient, quality, time_tag); break; case TypeID.M_ME_NA_1: // 9 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; quality.Overflow = true; } else if (value < -32768) { value = -32768; quality.Overflow = true; } sc = new MeasuredValueNormalized(addr, System.Convert.ToInt16(value), quality); break; case TypeID.M_ME_ND_1: // 21 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; quality.Overflow = true; } else if (value < -32768) { value = -32768; quality.Overflow = true; } sc = new MeasuredValueNormalizedWithoutQuality(addr, System.Convert.ToInt16(value)); break; case TypeID.M_ME_TD_1: // 34 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; quality.Overflow = true; } else if (value < -32768) { value = -32768; quality.Overflow = true; } sc = new MeasuredValueNormalizedWithCP56Time2a(addr, System.Convert.ToInt16(value), quality, time_tag); break; case TypeID.M_ME_NB_1: // 11 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; quality.Overflow = true; } else if (value < -32768) { value = -32768; quality.Overflow = true; } sc = new MeasuredValueScaled(addr, System.Convert.ToInt16(value), quality); break; case TypeID.M_ME_TE_1: // 35 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; quality.Overflow = true; } else if (value < -32768) { value = -32768; quality.Overflow = true; } sc = new MeasuredValueScaledWithCP56Time2a(addr, System.Convert.ToInt16(value), quality, time_tag); break; case TypeID.M_ME_NC_1: // 13 value = value * kconv1 + kconv2; sc = new MeasuredValueShort(addr, System.Convert.ToSingle(value), quality); break; case TypeID.M_ME_TF_1: // 36 value = value * kconv1 + kconv2; sc = new MeasuredValueShortWithCP56Time2a(addr, System.Convert.ToSingle(value), quality, time_tag); break; case TypeID.M_IT_NA_1: //15 break; case TypeID.M_IT_TB_1: // 37 break; case TypeID.M_PS_NA_1: // 20 Log(" TODO Packed single point information with status change detection! "); break; case TypeID.M_EP_TD_1: // 38 break; case TypeID.M_EP_TE_1: // 39 break; case TypeID.M_EP_TF_1: // 40 break; case TypeID.M_BO_NA_1: // 7 uival = System.Convert.ToUInt32(value); if (kconv1 == -1) { uival = ~uival; } sc = new Bitstring32(addr, uival, quality); break; case TypeID.M_BO_TB_1: // 33 uival = System.Convert.ToUInt32(value); if (kconv1 == -1) { uival = ~uival; } sc = new Bitstring32WithCP56Time2a(addr, uival, quality, time_tag); break; case TypeID.C_SC_NA_1: // 45 bval = value != 0 ? true : false; if (kconv1 == -1) { bval = !bval; } sc = new SingleCommand(addr, bval, sbo, cmdqualif); break; case TypeID.C_DC_NA_1: // 46 if (kconv1 == -1) { ival = value != 0 ? System.Convert.ToInt32(DoublePointValue.OFF) : System.Convert.ToInt32(DoublePointValue.ON); } else { ival = value != 0 ? System.Convert.ToInt32(DoublePointValue.ON) : System.Convert.ToInt32(DoublePointValue.OFF); } sc = new DoubleCommand(addr, ival, sbo, cmdqualif); break; case TypeID.C_RC_NA_1: // 47 if (kconv1 == -1) { sc = new StepCommand(addr, value >= 1 ? StepCommandValue.LOWER : StepCommandValue.HIGHER, sbo, cmdqualif); } else { sc = new StepCommand(addr, value >= 1 ? StepCommandValue.HIGHER : StepCommandValue.LOWER, sbo, cmdqualif); } break; case TypeID.C_SE_NA_1: // 48 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new SetpointCommandNormalized(addr, System.Convert.ToInt16(value), new SetpointCommandQualifier(sbo, 0)); break; case TypeID.C_SE_NB_1: // 49 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new SetpointCommandScaled(addr, new ScaledValue(System.Convert.ToInt16(value)), new SetpointCommandQualifier(sbo, 0)); break; case TypeID.C_SE_NC_1: // 50 value = value * kconv1 + kconv2; sc = new SetpointCommandShort(addr, System.Convert.ToSingle(value), new SetpointCommandQualifier(sbo, 0)); break; case TypeID.C_BO_NA_1: // 51 uival = System.Convert.ToUInt32(value); if (kconv1 == -1) { uival = ~uival; } sc = new Bitstring32Command(addr, uival); break; case TypeID.C_SC_TA_1: // 58 bval = value != 0 ? true : false; if (kconv1 == -1) { bval = !bval; } sc = new SingleCommandWithCP56Time2a(addr, bval, sbo, cmdqualif, time_tag); break; case TypeID.C_DC_TA_1: // 59 if (kconv1 == -1) { ival = value != 0 ? System.Convert.ToInt32(DoublePointValue.OFF) : System.Convert.ToInt32(DoublePointValue.ON); } else { ival = value != 0 ? System.Convert.ToInt32(DoublePointValue.ON) : System.Convert.ToInt32(DoublePointValue.OFF); } sc = new DoubleCommandWithCP56Time2a(addr, ival, sbo, cmdqualif, time_tag); break; case TypeID.C_RC_TA_1: // 60 if (kconv1 == -1) { sc = new StepCommandWithCP56Time2a(addr, value >= 1 ? StepCommandValue.LOWER : StepCommandValue.HIGHER, sbo, cmdqualif, time_tag); } else { sc = new StepCommandWithCP56Time2a(addr, value >= 1 ? StepCommandValue.HIGHER : StepCommandValue.LOWER, sbo, cmdqualif, time_tag); } break; case TypeID.C_SE_TA_1: // 61 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new SetpointCommandNormalizedWithCP56Time2a(addr, System.Convert.ToInt16(value), new SetpointCommandQualifier(sbo, 0), time_tag); break; case TypeID.C_SE_TB_1: // 62 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new SetpointCommandScaledWithCP56Time2a(addr, new ScaledValue(System.Convert.ToInt16(value)), new SetpointCommandQualifier(sbo, 0), time_tag); break; case TypeID.C_SE_TC_1: // 63 value = value * kconv1 + kconv2; sc = new SetpointCommandShortWithCP56Time2a(addr, System.Convert.ToSingle(value), new SetpointCommandQualifier(sbo, 0), time_tag); break; case TypeID.C_BO_TA_1: // 64 uival = System.Convert.ToUInt32(value); if (kconv1 == -1) { uival = ~uival; } sc = new Bitstring32CommandWithCP56Time2a(addr, uival, time_tag); break; case TypeID.C_IC_NA_1: // 100 sc = new InterrogationCommand(0, System.Convert.ToByte(cmdqualif)); break; case TypeID.C_CI_NA_1: // 101 sc = new CounterInterrogationCommand(0, System.Convert.ToByte(cmdqualif)); break; case TypeID.C_RD_NA_1: // 102 sc = new ReadCommand(addr); break; case TypeID.C_CS_NA_1: // 103 sc = new ClockSynchronizationCommand(0, time_tag); break; case TypeID.C_RP_NA_1: // 105 sc = new ResetProcessCommand(addr, System.Convert.ToByte(cmdqualif)); break; case TypeID.C_TS_TA_1: // 107 sc = new TestCommandWithCP56Time2a(System .Convert .ToUInt16(value), time_tag); break; case TypeID.P_ME_NA_1: // 110 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new ParameterNormalizedValue(System .Convert .ToInt32(addr), System.Convert.ToInt32(value), System.Convert.ToByte(cmdqualif)); break; case TypeID.P_ME_NB_1: // 111 value = value * kconv1 + kconv2; if (value > 32767) { value = 32767; } else if (value < -32768) { value = -32768; } sc = new ParameterScaledValue(addr, new ScaledValue(System.Convert.ToInt16(value)), System.Convert.ToByte(cmdqualif)); break; case TypeID.P_ME_NC_1: // 112 value = value * kconv1 + kconv2; sc = new ParameterFloatValue(addr, System.Convert.ToSingle(value), System.Convert.ToByte(cmdqualif)); break; case TypeID.P_AC_NA_1: // 113 sc = new ParameterActivation(System.Convert.ToInt32(addr), System.Convert.ToByte(cmdqualif)); break; default: break; } return(sc); }
public SingleCommandViewModel(SingleCommand command) : base(string.Empty, command?.Text ?? string.Empty, editable: true, run: true, delete: true) { Command = command ?? throw new ArgumentNullException(nameof(command)); DescriptionEditAction = d => Command.Text = d; }
public static void startCAFImportImpl(ICswResources CswResources, string CAFDatabase, string CAFSchema, string CAFPassword, CswEnumSetupMode SetupMode) { CswNbtResources _CswNbtResources = (CswNbtResources)CswResources; //connect to the CAF database CswDbVendorOpsOracle CAFConnection = new CswDbVendorOpsOracle("CAFImport", CAFDatabase, CAFSchema, CAFPassword, (CswDataDictionary)_CswNbtResources.DataDictionary, _CswNbtResources.CswLogger, CswEnumPooledConnectionState.Open, ""); string Error = ""; if (false == CAFConnection.IsDbConnectionHealthy(ref Error)) { throw new CswDniException(CswEnumErrorType.Error, "Check the supplied parameters for the CAF database.", Error); } //Run the SQL to generate the table, views, triggers, and other setup operations. //there is no clean solution for running the contents of .SQL file from inside C#, so please forgive the horrible hacks that follow. //Assumptions made here: // the only PL/SQL blocks are the deletes at the top of the script and the triggers at the bottom, // the / at the end of PL/SQL is always at the beginning of a line, // triggers always have two lines of spaces before them, except the very first trigger, which has 3 string CAFSql = generateCAFSql(_CswNbtResources); //add a / before the first trigger and split the file into an array of strings on space-only preceded / chars (breaking off potential PL/SQL blocks) string[] SQLCommands = Regex.Split(CAFSql .Replace(");\r\n\r\n\r\ncreate or replace trigger", ");\r\n\r\n\r\n/\r\ncreate or replace trigger") .Replace("create or replace procedure", "\r\n/\r\ncreate or replace procedure") .Replace("/*+", "*+"),//Strip slash out of Oracle Hints to prevent splitting the view query @"\s+/"); foreach (string Command in SQLCommands) { //If we stripped a slash out of an Oracle Hint, put it back in string SQLCommand = Command.Replace("*+", "/*+"); //if the string starts with any of these, it's a PL/SQL block and can be sent as-is if (SQLCommand.Trim().StartsWith("begin") || SQLCommand.Trim().StartsWith("create or replace trigger") || SQLCommand.Trim().StartsWith("create or replace procedure")) { CAFConnection.execArbitraryPlatformNeutralSql(SQLCommand); } //otherwise, we need to further split out each command on ; chars else { foreach (string SingleCommand in SQLCommand.Split(';')) { if (SingleCommand.Trim() != String.Empty) { CAFConnection.execArbitraryPlatformNeutralSql(SingleCommand.Trim()); } } } }//foreach PL/SQL block in CAF.sql //create the database link, after cleaning up an old one if it exists _CswNbtResources.execArbitraryPlatformNeutralSql(@" begin execute immediate 'drop database link caflink'; exception when others then null; end; "); _CswNbtResources.execArbitraryPlatformNeutralSql("create database link caflink connect to " + CAFSchema + " identified by " + CAFPassword + " using '" + CAFDatabase + "'"); //Create custom NodeTypeProps from CAF Properties collections and set up bindings for them CreateAllCAFProps(_CswNbtResources, SetupMode); // Enable the CAFImport rule CswTableUpdate TableUpdate = _CswNbtResources.makeCswTableUpdate("enableCafImportRule", "scheduledrules"); DataTable DataTable = TableUpdate.getTable("where rulename = '" + CswEnumNbtScheduleRuleNames.CAFImport + "'"); if (DataTable.Rows.Count > 0) { DataTable.Rows[0]["disabled"] = CswConvert.ToDbVal(false); TableUpdate.update(DataTable); } //create a connection to the schedule service WSHttpBinding Binding = new WSHttpBinding(); EndpointAddress Endpoint = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]); CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient(Binding, Endpoint); //fetch the CAFImport rule from ScheduleService CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams(); CswSchedSvcParams.CustomerId = _CswNbtResources.AccessId; CswSchedSvcParams.RuleName = CswEnumNbtScheduleRuleNames.CAFImport; CswSchedSvcReturn CAFRuleResponse; try { CAFRuleResponse = SchedSvcRef.getRules(CswSchedSvcParams); } catch (Exception e) { throw new CswDniException(CswEnumErrorType.Error, "Could not connect to schedule service", e.Message); } //take the rule that was returned from the last request, set disabled to false, then send it back as an update CswScheduleLogicDetail CAFImport = CAFRuleResponse.Data[0]; CAFImport.Disabled = false; CswSchedSvcParams.LogicDetails = new Collection <CswScheduleLogicDetail>(); CswSchedSvcParams.LogicDetails.Add(CAFImport); CswSchedSvcReturn svcReturn = SchedSvcRef.updateScheduledRules(CswSchedSvcParams); if (false == svcReturn.Status.Success) { throw new CswDniException(svcReturn.Status.Errors[0].Message); } }//startCAFImport
private void button2_Click(object sender, EventArgs e) { SingleCommand.ResetText(); }