public static async Task <byte[]> ExecuteFunction12Async(byte moduleNum, string requestName, byte innerFunctionId) { // TcpMbReadResponse tcpMbResponse; byte[] resultBytes = null; try { await _semaphoreSlim.WaitAsync(); //TransactionCompleteAction?.Invoke(); var receivedBytes = await _modbusMaster.ExecuteFunction12Async(1, moduleNum, innerFunctionId, 0); byte moduleByte = receivedBytes[0]; byte innerFunByte = receivedBytes[1]; byte numberOfBytesByte = receivedBytes[2]; if ((moduleByte != moduleNum) || (innerFunByte != innerFunctionId)) { throw new Exception(); } resultBytes = receivedBytes.Skip(3).ToArray(); _semaphoreSlim.Release(1); } catch (Exception j) { _semaphoreSlim.Release(1); //AddErrorInList(j, requestName); //LastTransactionSucceed = false; } return(resultBytes); }