Beispiel #1
0
        public async Task <IQueryResult <ushort[]> > ReadHoldingResgistersAsync(ushort startAddress, ushort numberOfPoints,
                                                                                string dataTitle)
        {
            if (IsConnectionLost)
            {
                _lastQuerySucceed = false;
                TransactionCompleteSubscription?.Execute();
                _currentDeviceLogger.LogFailedQuery("pup");

                return(new DefaultQueryResult <ushort[]>()
                {
                    IsSuccessful = false
                });
            }

            await Task.Delay(1);

            PopulateMemoryIfNeeded(startAddress, numberOfPoints);
            _lastQuerySucceed = true;
            TransactionCompleteSubscription?.Execute();

            return(new DefaultQueryResult <ushort[]>()
            {
                IsSuccessful = true,

                Result = MemorySlotDictionary
                         .Where((pair) => startAddress <= pair.Key && pair.Key <= (startAddress + numberOfPoints - 1))
                         .OrderBy(pair => pair.Key).Select((pair) => pair.Value)
                         .ToArray()
            });
        }
Beispiel #2
0
 private void PopulateMemoryIfNeeded(ushort address, ushort numberOfPoints)
 {
     for (ushort i = address; i < address + numberOfPoints; i++)
     {
         if (!MemorySlotDictionary.ContainsKey(i))
         {
             try
             {
                 MemorySlotDictionary.Add(i, 0);
             }
             catch (Exception e)
             {
             }
         }
     }
 }