Beispiel #1
0
        private List <Tuple <DataAddress, TValue> > ScanAddress(IPlc plc, List <EventInfo <TValue> > eventInfoes)
        {
            var        result     = new List <Tuple <DataAddress, TValue> >();
            SortResult sortResult = InMemoryCache.GetOrAdd <SortResult>(eventInfoes.GetHashCode().ToString(), key =>
            {
                var r = new SortResult();
                var distinctPlcAddresses = eventInfoes.Select(e => (e.Event as EventBase).PlcAddress).Distinct();

                r.AddressNotSegment.Addresses = distinctPlcAddresses.ToList();

                if (!PlcMonitorImp.IsPlcManualSimulator)
                {
                    r = PlcAddressSortHelper.Sort <TValue>(distinctPlcAddresses);
                }

                return(r);
            });

            sortResult.AddressSegments.ForEach(addressSegment =>
            {
                var startAddress = addressSegment.StartAddress;
                List <TValue> values;

                startAddress.Offset = addressSegment.AllAddressesByDes.Count - 1;

                values = plc.Read <TValue>(startAddress).ToList();

                for (var index = 0; index < values.Count(); index++)
                {
                    result.Add(new Tuple <DataAddress, TValue>(addressSegment.AllAddressesByDes[index], values[index]));
                }
            });

            sortResult.AddressNotSegment.Addresses.ForEach(address =>
            {
                var value = plc.ReadSingle <TValue>(address);

                result.Add(new Tuple <DataAddress, TValue>(address, value));
            });

            return(result);
        }