public async Task <IQueryResult <ushort[]> > ReadHoldingResgistersAsync(ushort startAddress, ushort numberOfPoints, string dataTitle) { IQueryResult <ushort[]> queryResult = _queryResultFactory.CreateDefaultQueryResult <ushort[]>(); if (!CheckConnection(queryResult)) { return(queryResult); } try { queryResult.Result = await _currentModbusMaster.ReadHoldingRegistersAsync(_slaveId, startAddress, numberOfPoints); List <string> results = queryResult.Result.Select((arg => arg.ToString())).ToList(); string resStr = ""; foreach (var res in results) { resStr += res; resStr += " "; } queryResult.IsSuccessful = true; } catch (Exception e) { queryResult.IsSuccessful = false; } return(queryResult); }
public async Task <IQueryResult <ushort[]> > ReadHoldingResgistersAsync(ushort startAddress, ushort numberOfPoints, string dataTitle) { await _semaphoreSlim.WaitAsync(); IQueryResult <ushort[]> queryResult = _queryResultFactory.CreateDefaultQueryResult <ushort[]>(); if (!CheckConnection(queryResult)) { return(queryResult); } try { queryResult.Result = await _currentModbusMaster.ReadHoldingRegistersAsync(_slaveId, startAddress, numberOfPoints); List <string> results = queryResult.Result.Select((arg => arg.ToString())).ToList(); string resStr = ""; foreach (string res in results) { resStr += res; resStr += " "; } LogQuery(true, dataTitle, "Fun:3" + " Addr:" + startAddress + " Num:" + numberOfPoints + " Data:" + resStr); queryResult.IsSuccessful = true; } catch (Exception e) { LogQuery(false, dataTitle, "Fun:3" + " Addr:" + startAddress + " Num:" + numberOfPoints, exception: e); queryResult.IsSuccessful = false; queryResult.AddExeption(e); } _semaphoreSlim.Release(1); return(queryResult); }