예제 #1
0
        private void btnBackupEEPROM_Click(object sender, EventArgs e)
        {
            try
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.DefaultExt = "hex";
                    dlg.Filter = Resources.IntelHexFileDescriptor;
                    dlg.CheckFileExists = false;
                    dlg.CheckPathExists = false;
                    if (!Settings.Default.LastEEPromFile.IsNullOrEmpty() &&
                        File.Exists(Settings.Default.LastEEPromFile))
                    {
                        dlg.InitialDirectory = Path.GetDirectoryName(Settings.Default.LastEEPromFile);
                    }

                    if (dlg.ShowDialog() == DialogResult.Cancel)
                        return;

                    Settings.Default.LastEEPromFile = dlg.FileName;
                    Settings.Default.Save();
                }

                var eePROM = new BT_EEPROM {Address = 0, ByteCount = BT_EEPROM.EEPROM_SIZE};
                _btCom.GetEEPROM(eePROM);
                rtbEEPROM.Text = eePROM.HexDump().ToString();

                eePROM.SaveToFile(Settings.Default.LastEEPromFile);

            }
            catch (Exception ex)
            {
                DisplayComError(ex);
            }
        }
예제 #2
0
        private void btnRestoreEEPROM_Click(object sender, EventArgs e)
        {
            try
            {
                using (var dlg = new OpenFileDialog())
                {
                    dlg.DefaultExt = "hex";
                    dlg.Filter = Resources.IntelHexFileDescriptor;
                    dlg.CheckFileExists = false;
                    dlg.CheckPathExists = false;
                    if (!Settings.Default.LastEEPromFile.IsNullOrEmpty() &&
                        File.Exists(Settings.Default.LastEEPromFile))
                    {
                        dlg.InitialDirectory = Path.GetDirectoryName(Settings.Default.LastEEPromFile);
                    }

                    if (dlg.ShowDialog() == DialogResult.Cancel)
                        return;

                    Settings.Default.LastEEPromFile = dlg.FileName;
                    Settings.Default.Save();
                }

                var eeprom = new BT_EEPROM();
                eeprom.LoadFromIntelHexFile(Settings.Default.LastEEPromFile);

                for (UInt16 address = 0; address < 2048; address += 64)
                {
                    eeprom.Address = address;
                    eeprom.ByteCount = 64;
                    _btCom.SetEEPROM(eeprom);
                }

            }
            catch (Exception ex)
            {
                DisplayComError(ex);
            }
        }
예제 #3
0
        public void SetEEPROM(BT_EEPROM eePROM)
        {
            if (eePROM.Address < 0 || eePROM.Address > BT_EEPROM.EEPROM_SIZE - 1)
                throw new ArgumentOutOfRangeException("eePROM.Address");

            if (eePROM.ByteCount < 0 || eePROM.ByteCount > BT_EEPROM.EEPROM_SIZE)
                throw new ArgumentOutOfRangeException("eePROM.ByteCount");

            if (!(Version.ComType == BTComType.ASCII || Version.ComType == BTComType.Binary))
                throw new ArgumentOutOfRangeException(String.Format("The {0} protocol does not support GetEEPROM.", Version.ComType));

            if (eePROM.Address + eePROM.ByteCount > BT_EEPROM.EEPROM_SIZE)
                eePROM.ByteCount = (UInt16)(BT_EEPROM.EEPROM_SIZE - eePROM.Address);

            var orgAddress = eePROM.Address;
            var orgCount = eePROM.ByteCount;

            var length = (Version.ComType == BTComType.ASCII) ? 48 : 64;

            var curAddress = orgAddress;
            var curCount = orgCount;
            while (curCount > 0)
            {
                eePROM.Address = curAddress;
                eePROM.ByteCount = Math.Min(length, curCount);
                ProcessBTCommand(BTCommand.SetEEPROM, eePROM, null);
                curAddress += length;
                curCount -= length;
            }

            // restore address and byte count
            eePROM.Address = orgAddress;
            eePROM.ByteCount = orgCount;
        }