static void Main(string[] args) { if ((args.Length != 5) || (args.Length == 0)) { Console.WriteLine("usage: write_EEPROM <VID> <PID> <i2c_address in hex> <start_pos in hex> <value in hex>"); return; } if (args[0].Length > 2) { if (args[0].Substring(0, 2) != "0x") { Console.WriteLine("You must specify VID in Hex (0x0)"); return; } else { args[0] = args[0].Substring(2); } } else { Console.WriteLine("You must specify VID in Hex (0x0)"); return; } int vid = int.Parse(args[0], NumberStyles.HexNumber); if (args[1].Length > 2) { if (args[1].Substring(0, 2) != "0x") { Console.WriteLine("You must specify PID in Hex (0x0)"); return; } else { args[1] = args[1].Substring(2); } } else { Console.WriteLine("You must specify PID in Hex (0x0)"); return; } int pid = int.Parse(args[1], NumberStyles.HexNumber); if (args[2].Length > 2) { if (args[2].Substring(0, 2) != "0x") { Console.WriteLine("You must specify i2c_addr in Hex (0x0)"); return; } else { args[2] = args[2].Substring(2); } } else { Console.WriteLine("You must specify i2c_addr in Hex (0x0)"); return; } int i2c_addr = int.Parse(args[2], NumberStyles.HexNumber); if (args[3].Length > 2) { if (args[3].Substring(0, 2) != "0x") { Console.WriteLine("You must specify start_pos in Hex (0x0)"); return; } else { args[3] = args[3].Substring(2); } } else { Console.WriteLine("You must specify start_pos in Hex (0x0)"); return; } int start = int.Parse(args[3], NumberStyles.HexNumber); if (args[4].Length > 2) { if (args[4].Substring(0, 2) != "0x") { Console.WriteLine("You must specify value in Hex (0x0)"); return; } else { args[4] = args[4].Substring(2); } } else { Console.WriteLine("You must specify value in Hex (0x0)"); return; } int value = int.Parse(args[4], NumberStyles.HexNumber); libUSB_Interface.usb_init(); Console.WriteLine("finding busses..."); libUSB_Interface.usb_find_busses(); Console.WriteLine("finding devices..."); libUSB_Interface.usb_find_devices(); Console.WriteLine("usb_get_busses..."); libUSB_Interface.usb_bus bus = libUSB_Interface.usb_get_busses(); Console.WriteLine("bus location: " + bus.location.ToString()); Console.WriteLine("Checking for VID PID..."); libUSB_Interface.usb_device fdev = USB.FindDevice(bus, vid, pid); if (fdev != null) { Console.WriteLine("Found VID PID: " + vid.ToString("x") + " " + pid.ToString("x")); } else { Console.WriteLine("did not find VID PID: " + vid.ToString("x") + " " + pid.ToString("x")); return; } Console.WriteLine("Trying to open device..."); IntPtr usb_dev_handle = libUSB_Interface.usb_open(fdev); Console.WriteLine("Device handle is: " + usb_dev_handle.ToString()); byte[] buf = new byte[1]; buf[0] = (byte)value; if ((OZY.Write_EEPROM(usb_dev_handle, i2c_addr, start, buf))) { Console.WriteLine("Writing address " + i2c_addr); } else { Console.WriteLine("Failed to write address " + i2c_addr); } Console.WriteLine("Closing device..."); libUSB_Interface.usb_close(usb_dev_handle); Console.WriteLine("done..."); }
static void Main(string[] args) { if ((args.Length != 2) || (args.Length == 0)) { Console.WriteLine("usage: program_OZYEEPROM <VID> <PID>"); return; } if (args[0].Length > 2) { if (args[0].Substring(0, 2) != "0x") { Console.WriteLine("You must specify VID in Hex (0x0)"); return; } else { args[0] = args[0].Substring(2); } } else { Console.WriteLine("You must specify VID in Hex (0x0)"); return; } int vid = int.Parse(args[0], NumberStyles.HexNumber); if (args[1].Length > 2) { if (args[1].Substring(0, 2) != "0x") { Console.WriteLine("You must specify PID in Hex (0x0)"); return; } else { args[1] = args[1].Substring(2); } } else { Console.WriteLine("You must specify PID in Hex (0x0)"); return; } int pid = int.Parse(args[1], NumberStyles.HexNumber); libUSB_Interface.usb_bus bus; try { libUSB_Interface.usb_init(); Console.WriteLine("finding busses..."); libUSB_Interface.usb_find_busses(); Console.WriteLine("finding devices..."); libUSB_Interface.usb_find_devices(); Console.WriteLine("usb_get_busses..."); bus = libUSB_Interface.usb_get_busses(); Console.WriteLine("bus location: " + bus.location.ToString()); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return; } Console.WriteLine("Checking for VID PID..."); libUSB_Interface.usb_device fdev = USB.FindDevice(bus, vid, pid); if (fdev != null) { Console.WriteLine("Found VID PID: " + vid.ToString("x") + " " + pid.ToString("x")); } else { Console.WriteLine("did not find VID PID: " + vid.ToString("x") + " " + pid.ToString("x")); return; } Console.WriteLine("Trying to open device..."); IntPtr usb_dev_handle; try { usb_dev_handle = libUSB_Interface.usb_open(fdev); Console.WriteLine("Device handle is: " + usb_dev_handle.ToString()); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return; } byte[] buf = new byte[8]; int i2c_addr = 0x51; // address of 24LC128 EEPROM buf[0] = 0xC0; // C0 load buf[1] = 0xFE; // low byte of VID buf[2] = 0xFF; // high byte of VID buf[3] = 0xFF; // low byte of PID buf[4] = 0x00; // high byte of PID buf[5] = 0x01; // low byte of DID <-- revision number buf[6] = 0x00; // high byte of DID buf[7] = 0x00; // configuration byte if ((OZY.Write_EEPROM(usb_dev_handle, i2c_addr, 0x00, buf))) { Console.WriteLine("Programming Successful!"); } else { Console.WriteLine("Failed to program EEPROM"); } Console.WriteLine("Closing device..."); libUSB_Interface.usb_close(usb_dev_handle); Console.WriteLine("done..."); }