Esempio n. 1
0
        public RegisterData ReadCommand(int point)
        {
            var         pointToRead = storage.GetPoint(point) as BasePointItem;
            Transaction trans       = null;

            try
            {
                ushort tranId = configuration.GetTransactionId();
                processingManager.Transactions.Add(trans = new Transaction(tranId, pointToRead.Address, false));

                processingManager.ExecuteReadCommand(pointToRead.ConfigItem, tranId, configuration.UnitAddress, pointToRead.Address, 1);

                while (!(trans = processingManager.Transactions.Find(t => t.TransactionId == tranId)).Finished)
                {
                    Thread.Sleep(10);
                }

                processingManager.Transactions.Remove(trans);

                pointToRead = storage.GetPoint(point) as BasePointItem;

                var returnValue = new RegisterData()
                {
                    PointId   = pointToRead.PointId,
                    Alarm     = (WCFContract.AlarmType)pointToRead.Alarm,
                    Address   = pointToRead.Address,
                    Timestamp = pointToRead.Timestamp,
                    Type      = (WCFContract.PointType)pointToRead.ConfigItem.RegistryType,
                    RawValue  = pointToRead.RawValue,
                    EguValue  = pointToRead.ConfigItem.RegistryType == Common.PointType.ANALOG_INPUT || pointToRead.ConfigItem.RegistryType == Common.PointType.ANALOG_OUTPUT ? ((AnalogBase)pointToRead).EguValue : 0,
                    State     = pointToRead.ConfigItem.RegistryType == Common.PointType.DIGITAL_INPUT || pointToRead.ConfigItem.RegistryType == Common.PointType.DIGITAL_OUTPUT ? (WCFContract.DState)((DigitalBase)pointToRead).State : 0
                };

                return(returnValue);
            }
            catch
            {
                processingManager.Transactions.Remove(trans);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Acquisitor thread logic.
        /// </summary>
        private void Acquisition_DoWork()
        {
            List <IConfigItem> configs = configuration.GetConfigurationItems();

            while (true)
            {
                acquisitionTrigger.WaitOne();
                foreach (var item in configs)
                {
                    if (item.SecondsPassedSinceLastPoll == item.AcquisitionInterval)
                    {
                        processingManager.ExecuteReadCommand(item, configuration.GetTransactionId(), configuration.UnitAddress, item.StartAddress, item.NumberOfRegisters);
                        item.SecondsPassedSinceLastPoll = 0;
                    }
                    item.SecondsPassedSinceLastPoll++;
                }
            }
        }