Exemplo n.º 1
0
        public override bool Run(IInTaskManager <double> taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.WriteFlashPage : Mode.WriteEepromPage;

            var txProtocol = new ProtocolWritePageTx(serialPortSettings.HeaderTX, mode);
            var rxProtocol = new ProtocolWritePageRx(serialPortSettings.HeaderRX, mode);
            var bufferRx   = new IOBufferWritePageRx();

            using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate,
                                                  serialPortSettings.Parity, serialPortSettings.StopBits, 50, SerialPort.InfiniteTimeout))
            {
                var nonEmptyPages = GetNonEmptyPagesWithNumber();

                Stopwatch stopWatch = new Stopwatch();
                int       pageCount = 0;
                foreach (var page in nonEmptyPages)
                {
                    for (int pageLineNumber = 0; pageLineNumber < Page.NumberOfLines; pageLineNumber++)
                    {
                        txProtocol.PageNumber     = page.Key;
                        txProtocol.PageLineNumber = pageLineNumber;
                        txProtocol.Line           = page.Value.GetLine(pageLineNumber);
                        for (;;)
                        {
                            Transmit(sp, txProtocol, taskManager.SynchronizationContext);
                            RestartReceiv();
                            stopWatch.Restart();
                            while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(100))
                            {
                                taskManager.IfCancellation();
                                if (IfReceived(sp, rxProtocol, bufferRx, taskManager.SynchronizationContext))
                                {
                                    if (rxProtocol.PageNumber == page.Key)
                                    {
                                        if (rxProtocol.PageLineNumber == pageLineNumber)
                                        {
                                            goto label1;
                                        }
                                        else
                                        {
                                            RestartReceiv();
                                        }
                                    }
                                    else
                                    {
                                        RestartReceiv();
                                    }
                                }
                            }
                        }
                        label1 :;
                    }
                    taskManager.OnProgress((double)pageCount++ / (nonEmptyPages.Count - 1) * 100.00);
                }
                Thread.Sleep(1000);
                return(true);
            }
        }
Exemplo n.º 2
0
        public override IOBuffer Pack()
        {
            var buffer = new IOBufferWritePageRx();

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

            buffer[3] = (byte)(PageNumber & 0x7F);
            buffer[4] = (byte)((PageNumber >> 7) & 0x7F);
            buffer[5] = (byte)((PageNumber >> 14) & 0x7F);
            buffer[6] = (byte)((PageNumber >> 21) & 0x07);
            buffer[7] = (byte)(PageLineNumber & 0x7F);

            checkSumManager.Calculate(buffer);

            return(buffer);
        }