Beispiel #1
0
        public override bool Run(IInTaskManager taskManager)
        {
            var protocolTx = new ProtocolResetTx(serialPortSettings.HeaderTX);
            var protocolRx = new ProtocolResetRx(serialPortSettings.HeaderRX);
            var bufferRx   = new IOBufferResetRx();

            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(true);
                        }
                    }
                }
            }
        }
        public override bool Run(IInTaskManager taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.ReadFlashPage : Mode.ReadEepromPage;

            var protocolTx = new ProtocolReadPageTx(serialPortSettings.HeaderTX, mode);
            var protocolRx = new ProtocolReadPageRx(serialPortSettings.HeaderRX, mode);
            var bufferTx   = new IOBufferReadPageTx();

            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.PageLineNumber = protocolTx.PageLineNumber;
                        protocolRx.Line           = memory.GetPage(protocolTx.PageNumber).GetLine(protocolTx.PageLineNumber);
                        Transmit(sp, protocolRx, taskManager.SynchronizationContext);
                        RestartReceiv();
                    }
                }
            }
        }
        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);
            }
        }
        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();
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public override bool Run(IInTaskManager taskManager)
        {
            var protocolTx = new ProtocolResetTx(serialPortSettings.HeaderTX);
            var protocolRx = new ProtocolResetRx(serialPortSettings.HeaderRX);
            var bufferTx   = new IOBufferResetTx();


            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();
                    }
                }
            }
        }
Beispiel #6
0
        public override IMemory Run(IInTaskManager <double> taskManager)
        {
            Mode mode = (memoryType == MemoryType.FLASH) ? Mode.ReadFlashPage : Mode.ReadEepromPage;

            var txProtocol = new ProtocolReadPageTx(serialPortSettings.HeaderTX, mode);
            var rxProtocol = new ProtocolReadPageRx(serialPortSettings.HeaderRX, mode);
            var bufferRx   = new IOBufferReadPageRx();

            using (var sp = new SerialPortManager(portName, (int)serialPortSettings.BaudRate,
                                                  serialPortSettings.Parity, serialPortSettings.StopBits,
                                                  50, SerialPort.InfiniteTimeout))
            {
                IMemory   memory      = new Memory((memoryType == MemoryType.FLASH) ? processor.FlashSize : processor.EepromSize);
                Stopwatch stopWatch   = new Stopwatch();
                int       pageCounter = 0;
                foreach (var pageNumber in numberOfPages)
                {
                    Page page = new Page();
                    txProtocol.PageNumber = pageNumber;
                    for (int pageLineNumber = 0; pageLineNumber < Page.NumberOfLines; pageLineNumber++)
                    {
                        txProtocol.PageLineNumber = 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 == pageNumber)
                                    {
                                        if (rxProtocol.PageLineNumber == pageLineNumber)
                                        {
                                            goto label1;
                                        }
                                        else
                                        {
                                            RestartReceiv();
                                        }
                                    }
                                    else
                                    {
                                        RestartReceiv();
                                    }
                                }
                            }
                        }
label1:
                        page.SetLine(pageLineNumber, rxProtocol.Line);
                    }
                    memory.SetPage(pageNumber, page);
                    pageCounter++;
                    taskManager.OnProgress((double)pageCounter / numberOfPages.Count * 100.00);
                }
                Thread.Sleep(1000);
                return(memory);
            }
        }