public override bool Run(IInTaskManager <double> taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.EraseFlashPage : Mode.EraseEepromPage;

            var txProtocol = new ProtocolErasePageTx(serialPortSettings.HeaderTX, mode);
            var rxProtocol = new ProtocolErasePageRx(serialPortSettings.HeaderRX, mode);
            var bufferRx   = new IOBufferErasePageRx();

            using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate,
                                                  serialPortSettings.Parity, serialPortSettings.StopBits, 50, SerialPort.InfiniteTimeout))
            {
                int       numberOfPages = GetNumberOfPages();
                int       pageCounter   = 0;
                Stopwatch stopWatch     = new Stopwatch();
                for (;;)
                {
label1:
                    if (pageCounter == numberOfPages)
                    {
                        Thread.Sleep(1000);
                        return(true);
                    }

                    txProtocol.PageNumber = pageCounter;
                    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 == pageCounter)
                            {
                                pageCounter++;
                                taskManager.OnProgress((double)pageCounter / numberOfPages * 100.00);
                                goto label1;
                            }
                            else
                            {
                                RestartReceiv();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void EraseFlash()
        {
            var ctx1 = new ProtocolErasePageTx(0x80, Mode.EraseFlashPage);
            ctx1.PageNumber = 0xFFFFFF;
            var ctx2 = new ProtocolErasePageTx(0x80, Mode.EraseFlashPage);

            var buf = ctx1.Pack();
            Assert.IsTrue(ctx2.UnPack(buf));
            Assert.AreEqual(0xFFFFFF, ctx2.PageNumber);
            Console.WriteLine(buf.ToString());

            var crx1 = new ProtocolErasePageRx(0x81, Mode.EraseFlashPage);
            crx1.PageNumber = 0x7FFF;
            var crx2 = new ProtocolErasePageRx(0x81, Mode.EraseFlashPage);

            buf = crx1.Pack();
            Assert.IsTrue(crx2.UnPack(buf));
            Assert.AreEqual(0x7FFF, crx2.PageNumber);
            Console.WriteLine(buf.ToString());
        }
Exemple #3
0
        public void EraseFlash()
        {
            var ctx1 = new ProtocolErasePageTx(0x80, Mode.EraseFlashPage);

            ctx1.PageNumber = 0xFFFFFF;
            var ctx2 = new ProtocolErasePageTx(0x80, Mode.EraseFlashPage);

            var buf = ctx1.Pack();

            Assert.IsTrue(ctx2.UnPack(buf));
            Assert.AreEqual(0xFFFFFF, ctx2.PageNumber);
            Console.WriteLine(buf.ToString());

            var crx1 = new ProtocolErasePageRx(0x81, Mode.EraseFlashPage);

            crx1.PageNumber = 0x7FFF;
            var crx2 = new ProtocolErasePageRx(0x81, Mode.EraseFlashPage);

            buf = crx1.Pack();
            Assert.IsTrue(crx2.UnPack(buf));
            Assert.AreEqual(0x7FFF, crx2.PageNumber);
            Console.WriteLine(buf.ToString());
        }
        public override bool Run(IInTaskManager taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.EraseFlashPage : Mode.EraseEepromPage;

            var protocolTx = new ProtocolErasePageTx(serialPortSettings.HeaderTX, mode);
            var protocolRx = new ProtocolErasePageRx(serialPortSettings.HeaderRX, mode);
            var bufferTx   = new IOBufferErasePageTx();

            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))
                    {
                        protocolRx.PageNumber = protocolTx.PageNumber;
                        memory.SetPage(protocolTx.PageNumber, new Page());
                        Transmit(sp, protocolRx, taskManager.SynchronizationContext);
                        RestartReceiv();
                    }
                }
            }
        }