Exemple #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));
                        }
                    }
                }
            }
        }
        public override IOBuffer Pack()
        {
            var buffer = new IOBufferConnectionRx();

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

            for (int i = 0; i < ConfirmationString.Length; i++)
            {
                buffer[3 + i] = (byte)ConfirmationString[i];
            }

            string ver = Version.ToString("00");

            buffer[15] = (byte)ver[0];
            buffer[16] = (byte)ver[1];

            string day = Date.Day.ToString("00");

            buffer[17] = (byte)day[0];
            buffer[18] = (byte)day[1];

            string month = Date.Month.ToString("00");

            buffer[19] = (byte)month[0];
            buffer[20] = (byte)month[1];

            string year = Date.Year.ToString("0000");

            buffer[21] = (byte)year[2];
            buffer[22] = (byte)year[3];

            checkSumManager.Calculate(buffer);

            return(buffer);
        }