コード例 #1
0
        public void WriteDataflash(Dataflash dataflash, BackgroundWorker worker = null)
        {
            var checksumBytes = BitConverter.GetBytes(dataflash.Data.Sum(x => x));
            var rawData       = new byte[dataflash.Data.Length + checksumBytes.Length];

            Buffer.BlockCopy(checksumBytes, 0, rawData, 0, checksumBytes.Length);
            Buffer.BlockCopy(dataflash.Data, 0, rawData, checksumBytes.Length, dataflash.Data.Length);

            using (var stream = OpenDeviceStream())
            {
                Write(stream, CreateCommand(Commands.WriteDataflash, 0, DataflashLength));
                Write(stream, rawData, worker);
            }
        }
コード例 #2
0
        public Dataflash Read(byte[] dataflashBytes)
        {
            if (dataflashBytes == null)
            {
                throw new ArgumentNullException("dataflashBytes");
            }

            using (var br = new BinaryReader(new MemoryStream(dataflashBytes)))
            {
                var result = new Dataflash();
                RecursiveRead(result, br);
                return(result);
            }
        }
コード例 #3
0
        public void Write(Dataflash dataflash, byte[] dataflashBytes)
        {
            if (dataflash == null)
            {
                throw new ArgumentNullException("dataflash");
            }
            if (dataflashBytes == null)
            {
                throw new ArgumentNullException("dataflashBytes");
            }

            using (var bw = new BinaryWriter(new MemoryStream(dataflashBytes)))
            {
                RecursiveWrite(dataflash, bw);
            }
        }
コード例 #4
0
        private void WriteDataflashButton_Click(object sender, EventArgs e)
        {
            string fileName;
            using (var op = new OpenFileDialog { Title = @"Select dataflash file ...", Filter = Consts.DataFlashFilter })
            {
                if (op.ShowDialog() != DialogResult.OK) return;
                fileName = op.FileName;
            }

            try
            {
                var data = File.ReadAllBytes(fileName);
                if (data.Length != 2044)
                {
                    InfoBox.Show("Seems that the dataflash file has the wrong format.");
                    return;
                }

                var dataflash = new Dataflash { Data = data };
                m_worker.RunWorkerAsync(new AsyncProcessWrapper(worker => WriteDataflashAsyncWorker(worker, dataflash)));
            }
            catch (Exception ex)
            {
                InfoBox.Show("An error occured during dataflash reading.\n" + ex.Message);
            }
        }
コード例 #5
0
 private void WriteDataflashAsyncWorker(BackgroundWorker worker, Dataflash dataflash)
 {
     try
     {
         UpdateUI(() => UpdateStatusLabel.Text = @"Writing dataflash...");
         m_updater.WriteDataflash(dataflash, worker);
         UpdateUI(() =>
         {
             UpdateStatusLabel.Text = @"Dataflash was successfully written.";
             worker.ReportProgress(0);
         });
     }
     catch (Exception ex)
     {
         InfoBox.Show("An exception occured during dataflash reading.\n" + ex.Message);
     }
 }
コード例 #6
0
        public void WriteDataflash(Dataflash dataflash, BackgroundWorker worker = null)
        {
            var checksumBytes = BitConverter.GetBytes(dataflash.Data.Sum(x => x));
            var rawData = new byte[dataflash.Data.Length + checksumBytes.Length];

            Buffer.BlockCopy(checksumBytes, 0, rawData, 0, checksumBytes.Length);
            Buffer.BlockCopy(dataflash.Data, 0, rawData, checksumBytes.Length, dataflash.Data.Length);

            using (var stream = OpenDeviceStream())
            {
                Write(stream, CreateCommand(Commands.WriteDataflash, 0, DataflashLength));
                Write(stream, rawData, worker);
            }
        }