public override bool Run(IInTaskManager taskManager) { var protocolTx = new ProtocolResetTx(serialPortSettings.HeaderTX); var protocolRx = new ProtocolResetRx(serialPortSettings.HeaderRX); var bufferRx = new IOBufferResetRx(); using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate, serialPortSettings.Parity, serialPortSettings.StopBits, 50, SerialPort.InfiniteTimeout)) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (;;) { Transmit(sp, protocolTx, taskManager.SynchronizationContext); RestartReceiv(); stopWatch.Restart(); while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(100)) { taskManager.IfCancellation(); if (IfReceived(sp, protocolRx, bufferRx, taskManager.SynchronizationContext)) { stopWatch.Stop(); return(true); } } } } }
public override bool Run(IInTaskManager taskManager) { var protocolTx = new ProtocolResetTx(serialPortSettings.HeaderTX); var protocolRx = new ProtocolResetRx(serialPortSettings.HeaderRX); var bufferTx = new IOBufferResetTx(); using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate, serialPortSettings.Parity, serialPortSettings.StopBits, 50, SerialPort.InfiniteTimeout)) { for (;;) { taskManager.IfCancellation(); if (IfReceived(sp, protocolTx, bufferTx, taskManager.SynchronizationContext)) { Transmit(sp, protocolRx, taskManager.SynchronizationContext); RestartReceiv(); } } } }