示例#1
0
        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);
                        }
                    }
                }
            }
        }
示例#2
0
        public override IOBuffer Pack()
        {
            var buffer = new IOBufferResetRx();

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

            checkSumManager.Calculate(buffer);

            return buffer;
        }
示例#3
0
        public override IOBuffer Pack()
        {
            var buffer = new IOBufferResetRx();

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

            checkSumManager.Calculate(buffer);

            return(buffer);
        }