public I2CReadPacketsFactory(MemoryRegionInfo reginfo) { region = new MemoryRegion(reginfo); lastPacketSize = reginfo.Size % bytesPerPacket; numberOfPackets = reginfo.Size / bytesPerPacket + (uint)(lastPacketSize == 0 ? 0 : 1); addressSize = reginfo.Size > 2048 ? 3 : 2; }
public MemoryRegionInfo GetRegionInfo() { MemoryRegionInfo info = new MemoryRegionInfo(); info.Address = _address; info.Size = _size; info.Type = _type; return(info); }
public MemoryRegion(MemoryRegionInfo regInfo) { _address = regInfo.Address; _size = regInfo.Size; _type = regInfo.Type; _data = new byte[_size]; for (uint i = 0; i < _size; i++) { _data[i] = 0xFF; } }
QueryResultsResp(byte[] response) { BytesPerPacket = response[2]; int regTypePos = 4; while (response[regTypePos] != 0xFF) { MemoryRegionInfo mr = new MemoryRegionInfo(); mr.Address = ConvertToUint(response, regTypePos + 1); mr.Size = ConvertToUint(response, regTypePos + 5); mr.Type = response[regTypePos]; MemoryRegionsInfo.Add(mr); regTypePos += 9; } }
int IM24CXXProgrammer.ReadChip(string chip, MemoryRegionInfo regionInfo, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress) { _isBusy = true; AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid()); Action <int, int> progressAct = delegate(int val, int max) { asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null); }; ThreadStart start = delegate() { asyncOp.Post(delegate(object args) { OnBusy(); }, null); //MemoryRegion region = null; ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo(); I2CReadPacketsFactory pf = new I2CReadPacketsFactory(regionInfo); try { ExchangeWithDevice(pf, progressAct); } catch (Exception e) { pcInfo.error = e; } pcInfo.Message = "Read complete"; asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null); asyncOp.Post(delegate(object args) { completed(pcInfo, pf.GetRegion()); }, null); _isBusy = false; asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null); }; (new Thread(start)).Start(); return(0); }
private void readChipStripButton_Click(object sender, EventArgs e) { this.FormClosing += Xerox0190Form_FormClosing; if (_programmer.IsBusy || (_programmer == null)) { return; } MemoryRegionInfo regionInfo = new MemoryRegionInfo(); regionInfo.Address = 0; regionInfo.Type = 1; regionInfo.Size = 256; Action <ProgrammingCompleteInfo, MemoryRegion> completed = delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region) { if (pcInfo.error != null) { infoPanel.SetErrorState(pcInfo.error.Message); } else { _dataBytes = new ByteCollection(region.Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); hexBox.ByteProvider.Changed += HexBoxChanged; Text = "XEROX 01/90 DUMP " + "It is read from CRUM"; infoPanel.SetOkState("Read complete"); } this.FormClosing -= Xerox0190Form_FormClosing; }; infoPanel.SetProgressState("Reading"); _programmer.ReadChip("Mode 0", regionInfo, completed, infoPanel.GetProgressDelegate()); }
public override void ReadEEPROM(Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress) { MemoryRegionInfo regionInfo = new MemoryRegionInfo() { Address = 0xF00000, Size = 256, Type = 2 }; AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid()); Action <int, int> progressAct = delegate(int val, int max) { asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null); }; ThreadStart start = delegate() { asyncOp.Post(delegate(object args) { OnBusy(); }, null); MemoryRegion region = null; ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo(); try { SafeFileHandle handle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE | Win32HardwareIOSupport.GENERIC_READ, Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero); if (handle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } using (FileStream harwareStream = new FileStream(handle, FileAccess.ReadWrite, 65)) { UpdateCurrentMemRegConfig(harwareStream); if (_currentMemoryRegionsConfig.Count != 4) { Exception e1 = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(4319) | 0x80070000))); Exception e2 = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(1784) | 0x80070000))); string message = e1.Message.Substring(0, e1.Message.IndexOf("(")) + e2.Message.Substring(0, e2.Message.IndexOf("(")); throw new Exception(message); } region = new MemoryRegion(regionInfo); asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Read")); }, null); asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null); ReadRegion(harwareStream, region, progressAct); } } catch (Exception e) { pcInfo.error = e; } pcInfo.Message = "Read complete"; asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null); asyncOp.PostOperationCompleted(delegate(object args) { completed(pcInfo, region); }, null); }; (new Thread(start)).Start(); }
int IM24CXXProgrammer.ReadChip(string chip, MemoryRegionInfo regionInfo, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress) { _isBusy = true; regionInfo.Address = 0; regionInfo.Size = 512; AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid()); Action <int, int> progressAct = delegate(int val, int max) { asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null); }; ThreadStart start = delegate() { asyncOp.Post(delegate(object args) { OnBusy(); }, null); MemoryRegion region = null; ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo(); try { SafeFileHandle handle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE | Win32HardwareIOSupport.GENERIC_READ, Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero); if (handle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } using (FileStream harwareStream = new FileStream(handle, FileAccess.ReadWrite, 65)) { SetTaskNumber(harwareStream, _m24CXXChipSet[chip]); UpdateCurrentMemRegConfig(harwareStream); if ((_currentMemoryRegionsConfig.Count != 1) || (_currentMemoryRegionsConfig[0] != regionInfo)) { Exception e1 = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(4319) | 0x80070000))); Exception e2 = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(1784) | 0x80070000))); string message = e1.Message.Substring(0, e1.Message.IndexOf("(")) + e2.Message.Substring(0, e2.Message.IndexOf("(")); throw new Exception(message); } region = new MemoryRegion(_currentMemoryRegionsConfig[0]); asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Read")); }, null); ReadRegion(harwareStream, region, progressAct); } } catch (Exception e) { pcInfo.error = e; } pcInfo.Message = "Read complete"; asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null); if (chip == "24C02") { byte[] datablock = new byte[256]; region.ReadData(0, datablock); region = new MemoryRegion(0, 256, 1); region.WriteData(0, datablock); } asyncOp.Post(delegate(object args) { completed(pcInfo, region); }, null); _isBusy = false; asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null); }; (new Thread(start)).Start(); return(0); }
public void AT88Write(string subtype, string name, string serialnumtype, string templatefile) { 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; List <MemoryRegion> regions = null; Action <ProgrammingCompleteInfo> programmComplete = delegate(ProgrammingCompleteInfo pcInfo) { progressBar.Value = progressBar.Minimum; if (pcInfo.error != null) { if (pcInfo.error is VerificationException) { VerificationException ve = pcInfo.error as VerificationException; SetAlarmText( "Verification error At address: " + ve.ErrorAddress.ToString() + " write: " + ve.WrittenByte.ToString() + " read: " + ve.ReadByte.ToString()); } else { SetAlarmText(pcInfo.error.Message); } thisBusy = false; this.FormClosing -= AutoForm_FormClosing; } else if (serialnumtype == "No") { thisBusy = false; this.FormClosing -= AutoForm_FormClosing; SetOkText(pcInfo.Message); } else { Action <FileWorkerIOCompleteInfo> writeComplete = delegate(FileWorkerIOCompleteInfo fwiocInfo) { SetOkText(pcInfo.Message); thisBusy = false; this.FormClosing -= AutoForm_FormClosing; }; _dumpCoprrectors[serialnumtype](regions[0].Data); _fileWorker.Write(templatefile, regions, writeComplete); } }; Action <FileWorkerIOCompleteInfo> readFileComplete = delegate(FileWorkerIOCompleteInfo fwiocInfo) { if (fwiocInfo.Error != null) { thisBusy = false; this.FormClosing -= AutoForm_FormClosing; SetAlarmText(fwiocInfo.Error.Message); } else { if (prog.IsBusy) { thisBusy = false; this.FormClosing -= AutoForm_FormClosing; SetInfoText("Resetter is busy"); return; } regions = fwiocInfo.Regions; prog.ProgramChip(subtype, fwiocInfo.Regions, programmComplete, Progress); } }; MemoryRegionInfo regionInfo = new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 }; _fileWorker.Read(templatefile, new List <MemoryRegionInfo>() { regionInfo }, readFileComplete); }
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); }
private void M24CXXRead(string subtype, string name) { if ((_programmer == null) || !(_programmer is IM24CXXProgrammer)) { SetAlarmText("Connect the compatible resetter"); return; } IM24CXXProgrammer prog = _programmer as IM24CXXProgrammer; if (prog.IsBusy) { SetInfoText("Resetter is busy"); return; } this.FormClosing += AutoForm_FormClosing; thisBusy = true; MemoryRegionInfo regionInfo = new MemoryRegionInfo(); regionInfo.Address = 0; regionInfo.Type = 1; regionInfo.Size = (uint)s02512[subtype]; Action <ProgrammingCompleteInfo, MemoryRegion> completed = delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region) { 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 < region.Size; i += 16) { byte[] data = new byte[16]; for (int j = 0; j < 16; j++) { data[j] = region.Data[i + j] < (byte)0x20 ? (byte)0x2E : region.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 { SetAlarmText(pcInfo.error.Message); } thisBusy = false; this.FormClosing -= AutoForm_FormClosing; }; prog.ReadChip(subtype, regionInfo, completed, Progress); }
int I921Programmer.ReadChip(string mode, MemoryRegionInfo regionInfo, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress) { _isBusy = true; AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid()); string infoString = ""; string errString = ""; DataReceivedEventHandler processOutput = delegate(Object sender, DataReceivedEventArgs drea) { if ((drea.Data != null) && drea.Data.Contains(_readingSequense[_readingStep])) { if (drea.Data.Contains("Done")) { if (infoString == "") { infoString += (_readingSequense[_readingStep] + " Ok"); } else { infoString += ("\r\n" + _readingSequense[_readingStep] + " Ok"); } _readingStep++; asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(infoString)); }, null); } else { errString = _readingSequense[_readingStep] + " Error"; } } }; ThreadStart start = delegate() { asyncOp.Post(delegate(object args) { OnBusy(); }, null); MemoryRegion region = new MemoryRegion(regionInfo); ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo(); _readingStep = 0; try { string path = Application.ExecutablePath; path = path.Substring(0, path.LastIndexOf("\\")); Directory.SetCurrentDirectory(path); Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "ps3cc921.exe"; p.StartInfo.CreateNoWindow = true; p.OutputDataReceived += processOutput; p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); p.Close(); if (errString != "") { throw new Exception(errString); } else { pcInfo.Message = "Reading Ok"; using (BinaryReader file = new BinaryReader(File.OpenRead("RS3CC921.BIN"))) { file.BaseStream.Position = 0; for (int i = 0; i < region.Data.Length; i++) { region.Data[i] = file.ReadByte(); } } } } catch (Exception e) { pcInfo.error = e; } asyncOp.Post(delegate(object args) { completed(pcInfo, region); }, null); _isBusy = false; asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null); }; (new Thread(start)).Start(); return(0); }