Example #1
0
        private int lastInfoLength;       // the last info text length


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public DeviceLogic(ICommContext commContext, ILineContext lineContext, DeviceConfig deviceConfig)
        {
            CommContext  = commContext ?? throw new ArgumentNullException(nameof(commContext));
            LineContext  = lineContext ?? throw new ArgumentNullException(nameof(lineContext));
            DeviceConfig = deviceConfig ?? throw new ArgumentNullException(nameof(deviceConfig));
            AppDirs      = commContext.AppDirs;
            Log          = lineContext.LineConfig.LineOptions.DetailedLog ? lineContext.Log : LogStub.Instance;
            AssemblyName asmName = GetType().Assembly.GetName();

            DriverName         = ScadaUtils.RemoveFileNameSuffixes(asmName.Name) + " " + asmName.Version;
            LastRequestOK      = false;
            ReqRetries         = lineContext.LineConfig.LineOptions.ReqRetries;
            IsBound            = lineContext.LineConfig.IsBound && deviceConfig.IsBound;
            DeviceNum          = deviceConfig.DeviceNum;
            Title              = CommUtils.GetDeviceTitle(DeviceNum, deviceConfig.Name);
            NumAddress         = deviceConfig.NumAddress;
            StrAddress         = deviceConfig.StrAddress;
            PollingOptions     = deviceConfig.PollingOptions;
            CanSendCommands    = false;
            ConnectionRequired = false;
            DeviceStatus       = DeviceStatus.Undefined;
            LastSessionTime    = DateTime.MinValue;
            LastCommandTime    = DateTime.MinValue;
            DeviceTags         = new DeviceTags();
            DeviceData         = new DeviceData(deviceConfig.DeviceNum);
            DeviceStats        = new DeviceStats();

            terminated     = false;
            connection     = null;
            lastInfoLength = 0;
        }
Example #2
0
        /// <summary>
        /// Binds the device tags to the configuration database.
        /// </summary>
        public virtual void BindDeviceTags(BaseDataSet baseDataSet)
        {
            foreach (InCnl inCnl in baseDataSet.InCnlTable.SelectItems(new TableFilter("DeviceNum", DeviceNum), true))
            {
                if (inCnl.Active && inCnl.CnlTypeID == CnlTypeID.Measured)
                {
                    DeviceTag deviceTag = null;

                    if (!string.IsNullOrEmpty(inCnl.TagCode))
                    {
                        // find tag by code
                        DeviceTags.TryGetTag(inCnl.TagCode, out deviceTag);
                    }
                    else if (inCnl.TagNum > 0)
                    {
                        // find tag by index
                        DeviceTags.TryGetTag(inCnl.TagNum.Value - 1, out deviceTag);
                    }

                    // check match and bind tag
                    if (deviceTag != null &&
                        (int)deviceTag.DataType == (inCnl.DataTypeID ?? DataTypeID.Double) &&
                        deviceTag.DataLength == Math.Max(inCnl.DataLen ?? 1, 1))
                    {
                        deviceTag.InCnl = inCnl;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Binds the device tags to the configuration database.
        /// </summary>
        public virtual void BindDeviceTags(ConfigDataset configDataset)
        {
            foreach (Cnl cnl in configDataset.CnlTable.SelectItems(new TableFilter("DeviceNum", DeviceNum), true))
            {
                if (cnl.Active && cnl.IsInput())
                {
                    DeviceTag deviceTag = null;

                    if (!string.IsNullOrEmpty(cnl.TagCode))
                    {
                        // find tag by code
                        DeviceTags.TryGetTag(cnl.TagCode, out deviceTag);
                    }
                    else if (cnl.TagNum > 0)
                    {
                        // find tag by index
                        DeviceTags.TryGetTag(cnl.TagNum.Value - 1, out deviceTag);
                    }

                    // check match and bind tag
                    if (deviceTag != null &&
                        (int)deviceTag.DataType == (cnl.DataTypeID ?? DataTypeID.Double) &&
                        deviceTag.DataLength == Math.Max(cnl.DataLen ?? 1, 1))
                    {
                        deviceTag.Cnl = cnl;
                    }
                }
            }
        }
Example #4
0
        private Connection connection;    // the device connection


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public DeviceLogic(ICommContext commContext, ILineContext lineContext, DeviceConfig deviceConfig)
        {
            CommContext    = commContext ?? throw new ArgumentNullException(nameof(commContext));
            LineContext    = lineContext ?? throw new ArgumentNullException(nameof(lineContext));
            DeviceConfig   = deviceConfig ?? throw new ArgumentNullException(nameof(deviceConfig));
            AppDirs        = commContext.AppDirs;
            Log            = lineContext.LineConfig.LineOptions.DetailedLog ? lineContext.Log : new LogStub();
            LastRequestOK  = false;
            IsBound        = lineContext.LineConfig.IsBound && deviceConfig.IsBound;
            DeviceNum      = deviceConfig.DeviceNum;
            Title          = CommUtils.GetDeviceTitle(DeviceNum, deviceConfig.Name);
            NumAddress     = deviceConfig.NumAddress;
            StrAddress     = deviceConfig.StrAddress;
            PollingOptions = deviceConfig.PollingOptions;
            ReqRetries     = lineContext.LineConfig.LineOptions.ReqRetries;

            CanSendCommands    = false;
            ConnectionRequired = false;
            LastSessionTime    = DateTime.MinValue;
            LastCommandTime    = DateTime.MinValue;
            DeviceTags         = new DeviceTags();
            DeviceData         = new DeviceData();

            terminated = false;
            connection = null;
        }
Example #5
0
        private CnlData[] rawData;                   // the raw tag data


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public DeviceData(int deviceNum)
        {
            this.deviceNum = deviceNum;
            slices         = new Queue <DeviceSlice>();
            events         = new Queue <DeviceEvent>();
            dataView       = new DeviceDataView();
            curDataLock    = new object();

            deviceTags    = null;
            modifiedFlags = null;
            rawData       = null;
        }
Example #6
0
        /// <summary>
        /// Initializes the device data to maintain the specified device tags.
        /// </summary>
        public void Init(DeviceTags deviceTags)
        {
            this.deviceTags = deviceTags ?? throw new ArgumentNullException(nameof(deviceTags));
            int dataLength = 0;

            foreach (DeviceTag deviceTag in deviceTags)
            {
                deviceTag.DataIndex = dataLength;
                dataLength         += deviceTag.DataLength;
            }

            modifiedFlags = new bool[deviceTags.Count];
            rawData       = new CnlData[dataLength];
            dataView.PrepareCurData(deviceTags);
        }
Example #7
0
        /// <summary>
        /// Prepares the current data for display.
        /// </summary>
        public void PrepareCurData(DeviceTags deviceTags)
        {
            if (deviceTags == null)
            {
                throw new ArgumentNullException(nameof(deviceTags));
            }

            // calculate row count
            int rowCount = 1;

            foreach (TagGroup tagGroup in deviceTags.TagGroups)
            {
                if (!tagGroup.Hidden)
                {
                    if (!deviceTags.FlattenGroups)
                    {
                        rowCount++;
                    }

                    foreach (DeviceTag deviceTag in tagGroup.DeviceTags)
                    {
                        rowCount++;

                        if (deviceTag.IsArray)
                        {
                            rowCount += deviceTag.DataLength;
                        }
                    }
                }
            }

            // initialize table
            if (rowCount > 1)
            {
                curDataTable = new Table(5, rowCount);
                curDataTable.Columns[3].VarWidth  = true;
                curDataTable.Columns[3].AlignLeft = false;
                curDataTable.Columns[4].AlignLeft = false;
                curDataRowIndexes = new int[deviceTags.Count];

                if (Locale.IsRussian)
                {
                    Row headerRow = curDataTable.Rows[0];
                    headerRow.Cells[0] = "Номер";
                    headerRow.Cells[1] = "Код";
                    headerRow.Cells[2] = "Наименование";
                    headerRow.Cells[3] = "Значение";
                    headerRow.Cells[4] = "Канал";
                }
                else
                {
                    Row headerRow = curDataTable.Rows[0];
                    headerRow.Cells[0] = "#";
                    headerRow.Cells[1] = "Code";
                    headerRow.Cells[2] = "Name";
                    headerRow.Cells[3] = "Value";
                    headerRow.Cells[4] = "Channel";
                }

                int rowIndex = 1;

                foreach (TagGroup tagGroup in deviceTags.TagGroups)
                {
                    if (tagGroup.Hidden)
                    {
                        foreach (DeviceTag deviceTag in tagGroup.DeviceTags)
                        {
                            curDataRowIndexes[deviceTag.Index] = -1;
                        }
                    }
                    else
                    {
                        if (!deviceTags.FlattenGroups)
                        {
                            Row row = curDataTable.Rows[rowIndex++];
                            row.IsSubheader = true;
                            row.Cells[0]    = tagGroup.Name;
                        }

                        foreach (DeviceTag deviceTag in tagGroup.DeviceTags)
                        {
                            curDataRowIndexes[deviceTag.Index] = rowIndex;
                            int dataLen = deviceTag.DataLength;
                            int cnlNum  = deviceTag.InCnl == null ? 0 : deviceTag.InCnl.CnlNum;

                            Row row = curDataTable.Rows[rowIndex++];
                            row.Cells[0] = deviceTag.TagNum.ToString();
                            row.Cells[1] = deviceTag.Code;
                            row.Cells[2] = deviceTag.Name;

                            if (cnlNum > 0)
                            {
                                row.Cells[4] = dataLen > 1 ?
                                               cnlNum + "-" + (cnlNum + dataLen - 1) : cnlNum.ToString();
                            }

                            if (deviceTag.IsArray)
                            {
                                for (int i = 0, lastIdx = dataLen - 1; i <= lastIdx; i++)
                                {
                                    row          = curDataTable.Rows[rowIndex++];
                                    row.Cells[2] = deviceTag.Name + "[" + i + "]";

                                    if (cnlNum > 0)
                                    {
                                        row.Cells[4] = (cnlNum + i).ToString();
                                    }
                                }
                            }
                        }
                    }
                }

                PadColumn(curDataTable, 0);
                PadColumn(curDataTable, 1);
                PadColumn(curDataTable, 2);
                PadColumn(curDataTable, 4);
            }
        }
Example #8
0
 /// <summary>
 /// Initializes the device data.
 /// </summary>
 public virtual void InitDeviceData()
 {
     DeviceTags.AddStatusTag();
     DeviceData.Init(DeviceTags);
 }
Example #9
0
 /// <summary>
 /// Initializes the device data to maintain the specified device tags.
 /// </summary>
 public void Init(DeviceTags deviceTags)
 {
 }