Exemple #1
0
        private byte[] prepareProgramVerifyFlash(ushort task)
        {
            Structures.FlashReadWrite buffer = new Structures.FlashReadWrite();
            buffer.ToNetAddress   = NetAddressDevice;
            buffer.FromNetAddress = NetAddressPc;
            buffer.LengthMessage  = StructConvert.LengthStruct(buffer);
            buffer.Command        = Enums.Commands.ProgramVerifyFlash;

            if (task == 0 || task == 1)             // Новые данные
            {
                Device.AddressOffset += Device.LengthSend;

                int delta = (int)Device.DataToWrite.Count - (int)Device.AddressOffset;
                if (delta > 230)
                {
                    Device.LengthSend = 230;
                }
                else if (delta != 0)
                {
                    Device.LengthSend = (uint)delta;
                }
                else                 // Переданы все данные
                {
                    Device.LengthSend = 0;
                }

                byte[] data = Device.DataToWrite.GetRange((int)Device.AddressOffset, (int)Device.LengthSend).ToArray();
                if (data.Length < 230)
                {
                    Array.Resize(ref data, 230);
                }
                Device.DataArray = data;
            }
            else if (task == 3)             // Ошибка
            {
            }
            else             // task = 2, Повтор данных
            {
            }


            buffer.AddressBegin  = Device.AddressBegin;
            buffer.AddressOffset = Device.AddressOffset;
            buffer.LengthData    = Device.LengthSend / 2;
            buffer.Data          = Device.DataArray;
            buffer.rsrv          = 0;

            buffer.Crc = CalculateCrc.CreateCRC(buffer);
            byte[] array = StructConvert.StructureToByteArray(buffer);
            return(array);
        }
Exemple #2
0
        private void readReadFlash(byte[] array)
        {
            Structures.FlashReadWrite buffer = new Structures.FlashReadWrite();
            object obj = new Structures.FlashReadWrite();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashReadWrite)obj;

            if (Function == Enums.FunctionalMode.ReadEeprom)
            {
                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение EEPROM завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }

                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.EepromData.Add(buffer.Data[i]);
                }
            }
            else if (Function == Enums.FunctionalMode.ReadFlash)
            {
                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.FlashData.Add(buffer.Data[i]);
                }

                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение Flash завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }
            }
            else if (Function == Enums.FunctionalMode.ReadRegion)
            {
                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.RegionData.Add(buffer.Data[i]);
                }

                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение области завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }
            }

            if (buffer.LengthData != 0)
            {
                Device.StatusProgress = Enums.StatusProgress.Inderterminate;
            }

            if (TaskToProcess == 1)
            {
                TaskToProcess = 0;
            }
        }