private void readCrumButton_Click(object sender, EventArgs e) { this.FormClosing += AT88DumpForm_FormClosing; if (_programmer.IsBusy || (_programmer == null)) { return; } List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 }, new MemoryRegionInfo() { Address = 256, Size = 256, Type = 1 } }; Action <ProgrammingCompleteInfo, List <MemoryRegion> > completed = delegate(ProgrammingCompleteInfo pcInfo, List <MemoryRegion> regions) { if (pcInfo.error != null) { infoPanel.SetErrorState(pcInfo.error.Message); } else { _userDataBytes = new ByteCollection(regions[0].Data); userDataHexBox.ByteProvider = new DynamicByteProvider(_userDataBytes); userDataHexBox.ByteProvider.Changed += HexBoxChanged; _configDataBytes = new ByteCollection(regions[1].Data); configDataHexBox.ByteProvider = new DynamicByteProvider(_configDataBytes); foreach (TabPage tp in dumpTabControl.TabPages) { sptext[tp] = "AT88 DUMP It is read from CRUM"; } Text = "AT88 DUMP " + "It is read from CRUM"; infoPanel.SetOkState("Read complete"); } this.FormClosing -= AT88DumpForm_FormClosing; }; infoPanel.SetProgressState("Reading"); _programmer.ReadChip(passwordSelectComboBox.SelectedItem.ToString(), regionsInfo, completed, infoPanel.GetProgressDelegate()); }
public void AT88Read(string subtype, string name) { if ((_programmer == null) || !(_programmer is IAT88Programmer)) { SetAlarmText("Connect the compatible resetter"); return; } IAT88Programmer prog = _programmer as IAT88Programmer; if (prog.IsBusy) { SetInfoText("Resetter is busy"); return; } this.FormClosing += AutoForm_FormClosing; thisBusy = true; MemoryRegionInfo regionInfo = new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 }; Action <ProgrammingCompleteInfo, List <MemoryRegion> > completed = delegate(ProgrammingCompleteInfo pcInfo, List <MemoryRegion> regions) { progressBar.Value = progressBar.Minimum; if (pcInfo.error == null) { Encoding enc = Encoding.GetEncoding(1251); TextBox textBox = new TextBox(); textBox.Multiline = true; textBox.ReadOnly = true; textBox.BackColor = Color.WhiteSmoke; textBox.ScrollBars = ScrollBars.Vertical; textBox.Size = new Size(150, 100); List <string> strings = new List <string>(); for (int i = 0; i < regions[0].Size; i += 16) { byte[] data = new byte[16]; for (int j = 0; j < 16; j++) { data[j] = regions[0].Data[i + j] < (byte)0x20 ? (byte)0x2E : regions[0].Data[i + j]; } strings.Add(enc.GetString(data)); } if (regions.Count == 2) { strings.Add(""); strings.Add("Configuration data"); strings.Add(""); for (int i = 0; i < regions[1].Size; i += 16) { byte[] data = new byte[16]; for (int j = 0; j < 16; j++) { data[j] = regions[1].Data[i + j] < (byte)0x20 ? (byte)0x2E : regions[1].Data[i + j]; } strings.Add(enc.GetString(data)); } } textBox.Lines = strings.ToArray(); infoLayoutPanel.Controls.Add(textBox); infoLayoutPanel.Controls.SetChildIndex(textBox, 0); SetOkText("Read OK"); } else { try { SetAlarmText(_messages[pcInfo.error.Message]); } catch (KeyNotFoundException) { SetAlarmText(pcInfo.error.Message); } } thisBusy = false; this.FormClosing -= AutoForm_FormClosing; }; prog.ReadChip(subtype, new List <MemoryRegionInfo>() { regionInfo }, completed, Progress); }