Example #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()
            });
        }
Example #2
0
        public async Task <IQueryResult> WriteMultipleRegistersAsync(ushort startAddress, ushort[] dataToWrite,
                                                                     string dataTitle)
        {
            if (IsConnectionLost)
            {
                _lastQuerySucceed = false;
                TransactionCompleteSubscription?.Execute();
                _currentDeviceLogger.LogFailedQuery("pup");

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

            await Task.Delay(1);

            PopulateMemoryIfNeeded(startAddress, (ushort)dataToWrite.Count());
            for (ushort i = startAddress; i < startAddress + (ushort)dataToWrite.Count(); i++)
            {
                MemorySlotDictionary[i] = dataToWrite[i - startAddress];
            }

            return(new DefaultQueryResult()
            {
                IsSuccessful = true
            });
        }
Example #3
0
 protected virtual void LogQuery(bool isSuccessful, string dataTitle, string queryDescription,
                                 string queryResult = "", Exception exception = null)
 {
     _lastQuerySucceed = isSuccessful;
     TransactionCompleteSubscription?.Execute();
 }