void ReadDataSPIThread() //ReadSerial/ParSPI { if (selectedIC == "93C66") { IC.EEPROM_93C66 ic; if (selectedPorts == Ports[1]) { ic = new MemoryProgrammer.IC.EEPROM_93C66(portAddress, 500000, this); } else if (selectedPorts == Ports[2]) { ic = new MemoryProgrammer.IC.EEPROM_93C66(portName, 50, this); } else { return; } timer1.Enabled = true; try { ic.StartTransfer(); } catch (Exception err) { MessageBox.Show(err.Message); return; } hex = ""; for (int x = 0; x < 256; x++) { UInt32 val = ic.EEPROM_93C66_spi_read_data(x); hex += val.ToString("X4"); progress = x / 256 * 100; } ic.StopTransfer(); this.BeginInvoke(new SetTextDeleg(tampilkanData), new object[] { hex }); byteviewer.SetBytes(StringToByteArray(hex)); progress = 100; } }
void KirimSPI() { if (selectedIC == "93C66") { IC.EEPROM_93C66 ic; if (selectedPorts == Ports[1]) { ic = new MemoryProgrammer.IC.EEPROM_93C66(portAddress, 500000, this); } else if (selectedPorts == Ports[2]) { ic = new MemoryProgrammer.IC.EEPROM_93C66(portName, 50, this); } else { return; } //string[] split = new string[hex.Length / 2 + (hex.Length % 2 == 0 ? 0 : 1)]; //for (int i = 0; i < split.Length; i++) //{ // split[i] = hex.Substring(i * 2, i * 2 + 2 > hex.Length ? 1 : 2); //} try { ic.StartTransfer(); } catch (Exception err) { MessageBox.Show(err.Message); return; } timer1.Enabled = true; ic.EEPROM_93C66_spi_ewen(); Thread.Sleep(1); //write all //ic.EEPROM_93C66_writeAll(ref split); byte[] bytes = byteviewer.GetBytes(); for (int x = 0; x < bytes.Length; x += 2) { int data = 0; data = data | bytes[x]; data = data << 8; data = data | bytes[x + 1]; ic.EEPROM_93C66_spi_send_data(x, data); progress = x * 100 / bytes.Length; } ic.StopTransfer(); progress = 100; } }