コード例 #1
0
        public async Task <bool> SendMultipleAnalogCommand(Dictionary <long, float> commandingValues, CommandOriginType commandOriginType)
        {
            if (commandingValues.Count == 0)
            {
                string warnMessage = $"{baseLogString} SendMultipleAnalogCommand => commandingValues is empty and thus aborting the call.";
                Logger.LogWarning(warnMessage);
                return(false);
            }

            #region Log commanding values
            var sb = new StringBuilder();

            foreach (var kvp in commandingValues)
            {
                sb.AppendLine($"Gid: 0x{kvp.Key:X16} | Value: {kvp.Value}");
            }

            Logger.LogInformation($"{baseLogString} SendMultipleAnalogCommand => Origin: {commandOriginType} Values {Environment.NewLine}{sb}");
            #endregion Log commanding values

            ushort startAddress = 1; //EasyModbus spec
            IScadaModelReadAccessContract           scadaModelReadAccessClient = ScadaModelReadAccessClient.CreateClient();
            Dictionary <long, IScadaModelPointItem> gidToPointItemMap          = await scadaModelReadAccessClient.GetGidToPointItemMap();

            Dictionary <short, Dictionary <ushort, long> > addressToGidMap = await scadaModelReadAccessClient.GetAddressToGidMap();

            if (gidToPointItemMap == null)
            {
                string message = $"{baseLogString} SendMultipleAnalogCommand => SCADA model is null.";
                Logger.LogError(message);
                return(false);
            }

            int   analogOutputCount        = addressToGidMap[(short)PointType.ANALOG_OUTPUT].Count;
            int[] multipleCommandingValues = new int[addressToGidMap[(short)PointType.ANALOG_OUTPUT].Count];

            foreach (ushort address in addressToGidMap[(short)PointType.ANALOG_OUTPUT].Keys)
            {
                long gid = addressToGidMap[(short)PointType.ANALOG_OUTPUT][address];

                if (!gidToPointItemMap.ContainsKey(gid))
                {
                    string message = $"{baseLogString} SendMultipleAnalogCommand => Entity with gid: 0x{gid:X16} does not exist in current SCADA model.";
                    Logger.LogError(message);
                    return(false);
                }
                else if (!(gidToPointItemMap[gid] is IAnalogPointItem analogPointItem))
                {
                    string message = $"{baseLogString} SendMultipleAnalogCommand => Entity with gid: 0x{gid:X16} does not implement IAnalogPointItem interface.";
                    Logger.LogError(message);
                    return(false);
                }
コード例 #2
0
        public async Task <bool> SendMultipleAnalogCommand(Dictionary <long, float> commandingValues, CommandOriginType commandOriginType)
        {
            if (commandingValues.Count == 0)
            {
                string warnMessage = $"{baseLogString} SendMultipleAnalogCommand => commandingValues is empty and thus aborting the call.";
                Logger.LogWarning(warnMessage);
                return(false);
            }

            ushort startAddress = 1; //EasyModbus spec
            IScadaModelReadAccessContract           scadaModelReadAccessClient = ScadaModelReadAccessClient.CreateClient();
            Dictionary <long, IScadaModelPointItem> gidToPointItemMap          = await scadaModelReadAccessClient.GetGidToPointItemMap();

            Dictionary <short, Dictionary <ushort, long> > addressToGidMap = await scadaModelReadAccessClient.GetAddressToGidMap();

            if (gidToPointItemMap == null)
            {
                string message = $"{baseLogString} SendMultipleAnalogCommand => SCADA model is null.";
                Logger.LogError(message);
                //throw new InternalSCADAServiceException(message);
                return(false);
            }

            int analogOutputCount = addressToGidMap[(short)PointType.ANALOG_OUTPUT].Count;

            int[] multipleCommandingValues = new int[addressToGidMap[(short)PointType.ANALOG_OUTPUT].Count];

            //for (ushort address = 1; address <= analogOutputCount; address++)
            //{
            foreach (ushort address in addressToGidMap[(short)PointType.ANALOG_OUTPUT].Keys)
            {
                long gid = addressToGidMap[(short)PointType.ANALOG_OUTPUT][address];

                if (!gidToPointItemMap.ContainsKey(gid))
                {
                    string message = $"{baseLogString} SendMultipleAnalogCommand => Entity with gid: 0x{gid:X16} does not exist in current SCADA model.";
                    Logger.LogError(message);
                    //throw new ArgumentException(message);
                    return(false);
                }
                else if (!(gidToPointItemMap[gid] is IAnalogPointItem analogPointItem))
                {
                    string message = $"{baseLogString} SendMultipleAnalogCommand => Entity with gid: 0x{gid:X16} does not implement IAnalogPointItem interface.";
                    Logger.LogError(message);
                    //throw new InternalSCADAServiceException(message);
                    return(false);
                }