Exemple #1
0
        static void Main(string[] args)
        {
            if ((args.Length != 2) || (args.Length == 0))
            {
                Console.WriteLine("usage: read_EEPROM <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);

            IntPtr usb_dev_handle = USB.InitFindAndOpenDevice(vid, pid);

            if ((OZY.Read_I2C_Speed(usb_dev_handle) == 1))
            {
                Console.WriteLine("I2C speed is 400kHz");
            }
            else
            {
                Console.WriteLine("I2C speed is 100kHz");
            }

            Console.WriteLine("Closing device...");
            libUSB_Interface.usb_close(usb_dev_handle);
            Console.WriteLine("done...");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if ((args.Length != 3) || (args.Length == 0))
            {
                Console.WriteLine("usage: read_EEPROM <VID> <PID> <value in hex {0x00=100kHz, 0x01=400kHz}> ");
                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 value in Hex (0x0)");
                    return;
                }
                else
                {
                    args[2] = args[2].Substring(2);
                }
            }
            else
            {
                Console.WriteLine("You must specify value in Hex (0x0)");
                return;
            }

            int value = int.Parse(args[2], NumberStyles.HexNumber);

            IntPtr usb_dev_handle = USB.InitFindAndOpenDevice(vid, pid);

            if ((OZY.Set_I2C_Speed(usb_dev_handle, value)))
            {
                Console.WriteLine("Set I2C speed successful");
            }
            else
            {
                Console.WriteLine("Failed to set I2C speed");
            }

            Console.WriteLine("I2C SPEED: " + OZY.Read_I2C_Speed(usb_dev_handle).ToString());

            Console.WriteLine("Closing device...");
            libUSB_Interface.usb_close(usb_dev_handle);
            Console.WriteLine("done...");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            if ((args.Length != 5) || (args.Length == 0))
            {
                Console.WriteLine("usage: read_EEPROM <VID> <PID> <i2c_address in hex> <start_pos in hex> <length 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 length in Hex (0x0)");
                    return;
                }
                else
                {
                    args[4] = args[4].Substring(2);
                }
            }
            else
            {
                Console.WriteLine("You must specify length in Hex (0x0)");
                return;
            }

            int length = 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[length];

            if ((OZY.Read_EEPROM(usb_dev_handle, i2c_addr, start, ref buf)))
            {
                Console.WriteLine("Read from address " + i2c_addr + ":");
                for (int i = 0; i < buf.Length; i++)
                {
                    Console.Write(buf[i].ToString("X"));
                    if (i < buf.Length - 1)
                    {
                        Console.Write(":");
                    }
                }
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Failed to read address " + i2c_addr);
            }

            Console.WriteLine("EEPROM TYPE: " + OZY.Read_EEPROM_Type(usb_dev_handle).ToString());
            Console.WriteLine("I2C SPEED: " + OZY.Read_I2C_Speed(usb_dev_handle).ToString());

            Console.WriteLine("Closing device...");
            libUSB_Interface.usb_close(usb_dev_handle);
            Console.WriteLine("done...");
        }