コード例 #1
0
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public override bool Run(IInTaskManager taskManager)
        {
            var protocolTx = new ProtocolReadLockTx(serialPortSettings.HeaderTX);
            var protocolRx = new ProtocolReadLockRx(serialPortSettings.HeaderRX);
            var bufferTx   = new IOBufferReadLockTx();

            protocolRx.Lock = locks;

            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();
                    }
                }
            }
        }