private void buttonI2Cprogram_Click(object sender, EventArgs e) { listBoxProgramMessages.Items.Clear(); USB_I2C_Flash i2cflash = null; switch (comboBoxI2CFlashType.Text) { case "Microchip 24FC256": i2cflash = new USB_24FC256(); break; } if (i2cflash == null) { postMessage("No flash type selected"); return; } List <string> msgs = new List <string>(); bool connected = i2cflash.connect(msgs); postMessages(msgs); if (!connected) { postMessage("Programmer: connection failed"); return; } postMessage("Programmer: connected"); int flashsiz = i2cflash.FlashSize(); postMessage("Flash chip info: " + flashsiz.ToString() + " bytes flash memory"); postMessage("Reading binary file"); RawBinaryfile rbf = new RawBinaryfile(textBoxI2CFlashHEXFile.Text); byte[] hexdata = rbf.GetData(); postMessage("File info: " + hexdata.Length + " bytes data"); bool fastWrite = checkBoxI2CfastFlash.Checked; int address = 0; long tick2 = System.DateTime.Now.Ticks; while ((address < flashsiz) && (address < hexdata.Length)) { int pagesiz = i2cflash.PageSize(address); byte[] buff = new byte[pagesiz]; int copysiz = Math.Min(pagesiz, hexdata.Length - address); Array.Copy(hexdata, address, buff, 0, copysiz); //postMessage("Writing data at " + address.ToString()); i2cflash.PageWrite(address, buff, fastWrite); address += pagesiz; } double tock2 = (System.DateTime.Now.Ticks - tick2) / 10000000.0; postMessage("Writing took " + tock2.ToString() + "s"); i2cflash.condition_STOP(); }