示例#1
0
        public override Tuple <int, DateTime> Run(IInTaskManager taskManager)
        {
            var protocolTx = new ProtocolConnectionTx(serialPortSettings.HeaderTX);
            var protocolRx = new ProtocolConnectionRx(serialPortSettings.HeaderRX);
            var bufferRx   = new IOBufferConnectionRx();

            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(new Tuple <int, DateTime>(protocolRx.Version, protocolRx.Date));
                        }
                    }
                }
            }
        }
示例#2
0
        public void Connection()
        {
            ProtocolConnectionTx ctx = new ProtocolConnectionTx(0x80);
            ProtocolConnectionRx crx = new ProtocolConnectionRx(0x81);

            var buf = ctx.Pack();

            Assert.IsTrue(ctx.UnPack(buf));
            Console.WriteLine(buf.ToString());

            buf = crx.Pack();
            Assert.IsTrue(crx.UnPack(buf));
            Console.WriteLine(buf.ToString());
        }
示例#3
0
        public override bool Run(IInTaskManager taskManager)
        {
            var protocolTx = new ProtocolConnectionTx(serialPortSettings.HeaderTX);
            var protocolRx = new ProtocolConnectionRx(serialPortSettings.HeaderRX);
            var bufferTx   = new IOBufferConnectionTx();

            protocolRx.Version = version;
            protocolRx.Date    = date;

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