public override byte Run(IInTaskManager taskManager) { var protocolTx = new ProtocolReadLockTx(serialPortSettings.HeaderTX); var protocolRx = new ProtocolReadLockRx(serialPortSettings.HeaderRX); var bufferRx = new IOBufferReadLockRx(); 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(protocolRx.Lock); } } } } }
public override IOBuffer Pack() { var buffer = new IOBufferReadLockRx(); buffer[0] = Header; buffer[1] = Confirmation; buffer[2] = (byte)Regim; buffer[3] = (byte)(Lock & 0x7F); buffer[4] = (byte)((Lock >> 7) & 0x01); checkSumManager.Calculate(buffer); return(buffer); }