示例#1
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmConfig(AppDirs appDirs, int deviceNum)
     : this()
 {
     this.appDirs      = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
     this.deviceNum    = deviceNum;
     deviceConfig      = new OpcDeviceConfig();
     configFileName    = "";
     modified          = false;
     changing          = false;
     opcSession        = null;
     subscriptionsNode = null;
     commandsNode      = null;
 }
示例#2
0
        private Dictionary <string, CommandConfig> cmdByCode;  // the commands accessed by code


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public DevOpcUaLogic(ICommContext commContext, ILineContext lineContext, DeviceConfig deviceConfig)
            : base(commContext, lineContext, deviceConfig)
        {
            opcLock          = new object();
            opcDeviceConfig  = null;
            connected        = false;
            connAttemptDT    = DateTime.MinValue;
            opcSession       = null;
            reconnectHandler = null;
            subscrByID       = null;
            cmdByNum         = null;
            cmdByCode        = null;

            CanSendCommands    = true;
            ConnectionRequired = false;
        }
示例#3
0
        /// <summary>
        /// Performs actions when starting a communication line.
        /// </summary>
        public override void OnCommLineStart()
        {
            opcDeviceConfig = new OpcDeviceConfig();

            if (opcDeviceConfig.Load(Storage, OpcDeviceConfig.GetFileName(DeviceNum), out string errMsg))
            {
                InitCmdMaps();
            }
            else
            {
                opcDeviceConfig = null;
                Log.WriteLine(errMsg);
                Log.WriteLine(Locale.IsRussian ?
                              "Взаимодействие с OPC-сервером невозможно, т.к. конфигурация устройства не загружена" :
                              "Interaction with OPC server is impossible because device configuration is not loaded");
            }
        }
示例#4
0
        /// <summary>
        /// Gets the channel prototypes for the device.
        /// </summary>
        public override ICollection <CnlPrototype> GetCnlPrototypes()
        {
            OpcDeviceConfig opcDeviceConfig = new();

            if (!opcDeviceConfig.Load(Path.Combine(AppDirs.ConfigDir, OpcDeviceConfig.GetFileName(DeviceNum)),
                                      out string errMsg))
            {
                throw new ScadaException(errMsg);
            }

            // create channels for subscriptions
            List <CnlPrototype> cnlPrototypes = new();
            int tagNum = 1;
            int eventMask = new EventMask {
                Enabled = true, StatusChange = true, Command = true
            }.Value;
            int cmdEventMask = new EventMask {
                Enabled = true, Command = true
            }.Value;

            foreach (SubscriptionConfig subscriptionConfig in opcDeviceConfig.Subscriptions)
            {
                foreach (ItemConfig itemConfig in subscriptionConfig.Items)
                {
                    CnlPrototype cnl = new()
                    {
                        Active    = itemConfig.Active,
                        Name      = itemConfig.DisplayName,
                        CnlTypeID = CnlTypeID.InputOutput,
                        TagNum    = string.IsNullOrEmpty(itemConfig.TagCode) ? tagNum : null,
                        TagCode   = itemConfig.TagCode,
                        EventMask = eventMask
                    };

                    if (itemConfig.IsString)
                    {
                        cnl.DataTypeID = DataTypeID.Unicode;
                        cnl.DataLen    = DriverUtils.GetTagDataLength(itemConfig.DataLength);
                        cnl.FormatCode = FormatCode.String;
                    }
                    else if (itemConfig.IsArray)
                    {
                        cnl.DataLen = itemConfig.DataLength;
                    }

                    if (DriverUtils.DataTypeEquals(itemConfig.DataTypeName, typeof(DateTime)))
                    {
                        cnl.FormatCode = FormatCode.DateTime;
                    }

                    cnlPrototypes.Add(cnl);
                    tagNum++;
                }
            }

            // create channels for commands
            foreach (CommandConfig commandConfig in opcDeviceConfig.Commands)
            {
                CnlPrototype cnl = new()
                {
                    Name      = commandConfig.DisplayName,
                    CnlTypeID = CnlTypeID.Output,
                    TagNum    = string.IsNullOrEmpty(commandConfig.CmdCode) ? commandConfig.CmdNum : null,
                    TagCode   = commandConfig.CmdCode,
                    EventMask = cmdEventMask
                };

                if (commandConfig.IsMethod)
                {
                    cnl.FormatCode = FormatCode.Execute;
                }
                else if (DriverUtils.DataTypeEquals(commandConfig.DataTypeName, typeof(string)))
                {
                    cnl.FormatCode = FormatCode.String;
                }
                else if (DriverUtils.DataTypeEquals(commandConfig.DataTypeName, typeof(DateTime)))
                {
                    cnl.FormatCode = FormatCode.DateTime;
                }

                cnlPrototypes.Add(cnl);
            }

            return(cnlPrototypes);
        }
    }
}