示例#1
0
        public override IOBuffer Pack()
        {
            var buffer = new IOBufferReadLockTx();

            buffer[0] = Header;
            buffer[1] = Confirmation;
            buffer[2] = (byte)Regim;

            checkSumManager.Calculate(buffer);

            return(buffer);
        }
示例#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();
                    }
                }
            }
        }