Example #1
0
        public void IsEmptyPageFlash()
        {
            var ctx1 = new ProtocolIsEmptyPageTx(0x80, Mode.IsEmptyFlashPage);

            ctx1.PageNumber = 0xFFFFFF;
            var ctx2 = new ProtocolIsEmptyPageTx(0x80, Mode.IsEmptyFlashPage);

            var buf = ctx1.Pack();

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

            var crx1 = new ProtocolIsEmptyPageRx(0x81, Mode.IsEmptyFlashPage);

            crx1.PageNumber = 0x7FFF;
            crx1.IsEmpty    = true;
            var crx2 = new ProtocolIsEmptyPageRx(0x81, Mode.IsEmptyFlashPage);

            buf = crx1.Pack();
            Assert.IsTrue(crx2.UnPack(buf));
            Assert.AreEqual(0x7FFF, crx2.PageNumber);
            Assert.IsTrue(crx2.IsEmpty);
            Console.WriteLine(buf.ToString());
        }
        public override List <int> Run(IInTaskManager <double> taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.IsEmptyFlashPage : Mode.IsEmptyEepromPage;

            var txProtocol = new ProtocolIsEmptyPageTx(serialPortSettings.HeaderTX, mode);
            var rxProtocol = new ProtocolIsEmptyPageRx(serialPortSettings.HeaderRX, mode);
            var bufferRx   = new IOBufferIsEmptyPageRx();

            using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate,
                                                  serialPortSettings.Parity, serialPortSettings.StopBits,
                                                  50, SerialPort.InfiniteTimeout))
            {
                List <int> notEmptyPages = new List <int>();
                int        numberOfPages = GetNumberOfPages();
                int        pageCounter   = 0;

                Stopwatch stopWatch = new Stopwatch();
                for (;;)
                {
label1:
                    if (pageCounter == numberOfPages)
                    {
                        return(notEmptyPages);
                    }

                    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)
                            {
                                if (!rxProtocol.IsEmpty)
                                {
                                    notEmptyPages.Add(rxProtocol.PageNumber);
                                }
                                pageCounter++;
                                taskManager.OnProgress((double)pageCounter / numberOfPages * 100.00);
                                goto label1;
                            }
                            else
                            {
                                RestartReceiv();
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public override bool Run(IInTaskManager taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.IsEmptyFlashPage : Mode.IsEmptyEepromPage;

            var protocolTx = new ProtocolIsEmptyPageTx(serialPortSettings.HeaderTX, mode);
            var protocolRx = new ProtocolIsEmptyPageRx(serialPortSettings.HeaderRX, mode);
            var bufferTx   = new IOBufferIsEmptyPageTx();

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