public byte[] ReceiveResponsePacket() { int start = Environment.TickCount; int myTimeout = RECEIVE_RESPONSE_TIMEOUT; if (!_masterMode) { myTimeout = Timeout.Infinite; } while (NetworkTpdu.CreateFromBuffer(_receiveBuffer, false) == null && (!_masterMode || Environment.TickCount - start < myTimeout)) { _receiveBuffer.WaitForByte(myTimeout, false); } NetworkTpdu responseTpdu = NetworkTpdu.CreateFromBuffer(_receiveBuffer, true); if (responseTpdu != null) { _log.Debug("Received TPDU: {0}", ByteHelpers.ByteToString(responseTpdu.GetTPDUData())); } if (responseTpdu == null) { return(null); } else { return(responseTpdu.GetAPDUData()); } }
public byte[] ReceiveResponsePacket() { int start = Environment.TickCount; int myTimeout = RECEIVE_RESPONSE_TIMEOUT; if (!_masterMode) { myTimeout = MASTER_RESPONES_TIMEOUT; } int waitTimeLeft = -1; while (NetworkTpdu.CreateFromBuffer(_receiveBuffer, false) == null && (Environment.TickCount - start < myTimeout)) { if (waitTimeLeft < 1) { _receiveBuffer.WaitForByte(myTimeout, false); } else { _receiveBuffer.WaitForByte(waitTimeLeft, false); } /* * the waitTimeLeft variable is used if one waitForByte call does not wait for the full timeout duration * Without the waitTimeLeft variable the system would try to wait another full timeout duration instead of * the time left. */ waitTimeLeft = myTimeout - (Environment.TickCount - start); } NetworkTpdu responseTpdu = NetworkTpdu.CreateFromBuffer(_receiveBuffer, true); if (responseTpdu != null) { _log.Debug("Received TPDU: {0}", ByteHelpers.ByteToString(responseTpdu.GetTPDUData())); } if (responseTpdu == null) { throw new ConnectionTimeOutException(); } else { return(responseTpdu.GetAPDUData()); } }