Пример #1
0
        /// <summary>
        /// Sends the telecontrol command.
        /// </summary>
        public override void SendCommand(TeleCommand cmd)
        {
            base.SendCommand(cmd);

            if (cmd.CmdCode == TagCode.DO || cmd.CmdNum == 4)
            {
                double relayVal = cmd.CmdVal > 0 ? 1 : 0;
                Log.WriteLine(Locale.IsRussian ?
                              "Установить состояние реле в {0}" :
                              "Set the relay state to {0}", relayVal);
                DeviceData.Set(TagCode.DO, relayVal);
            }
            else if (cmd.CmdCode == TagCode.AO || cmd.CmdNum == 5)
            {
                Log.WriteLine(Locale.IsRussian ?
                              "Установить аналоговый выход в {0}" :
                              "Set the analog output to {0}", cmd.CmdVal);
                DeviceData.Set(TagCode.AO, cmd.CmdVal);
            }
            else if (cmd.CmdCode == "Hist")
            {
                // demonstrate how to create a historical data slice
                DateTime    now         = DateTime.UtcNow;
                DeviceSlice deviceSlice = new DeviceSlice(
                    new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, DateTimeKind.Utc),
                    1, 1);
                deviceSlice.DeviceTags[0] = DeviceTags[TagCode.Sin];
                deviceSlice.CnlData[0]    = new CnlData(cmd.CmdVal, CnlStatusID.Defined);
                deviceSlice.Descr         = "Demo slice";
                DeviceData.EnqueueSlice(deviceSlice);
            }
            else if (cmd.CmdCode == "Event")
            {
                // demonstrate how to create an event
                DeviceData.EnqueueEvent(new DeviceEvent(DeviceTags[TagCode.Sin])
                {
                    Timestamp = DateTime.UtcNow,
                    CnlVal    = cmd.CmdVal,
                    CnlStat   = CnlStatusID.Defined,
                    Descr     = "Demo event"
                });
            }
            else
            {
                LastRequestOK = false;
                Log.WriteLine(CommPhrases.InvalidCommand);
            }

            FinishCommand();
        }