예제 #1
0
        private void btnRd_Click(object sender, EventArgs e)
        {
            byte[] buf = new byte[4];

            if (hdev != IntPtr.Zero)
            {
                OZY.Read_SPI(hdev, 0, 0x02, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), ref buf);
            }

            for (int i = 0; i < buf.Length; i++)
            {
                listBox1.Items.Add(buf[i]);
            }
        }
예제 #2
0
        int readStatusSPI(IntPtr usb_dev_handle)
        {
            int rc;

            byte[] buf = new byte[1];

            buf[0] = 0x00;
            byte addr = 0x43;

            if ((OZY.Read_SPI(usb_dev_handle, 0, addr, OZY.SPI_EN_FPGA, OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1, ref buf)))
            {
                Console.WriteLine("Read from address " + addr.ToString("X") + " : " + buf[0].ToString("X"));
                Console.WriteLine("");
                rc = buf[0];
            }
            else
            {
                Console.WriteLine("Failed to read address " + addr);
                rc = -1;
            }
            return(rc);
        }
예제 #3
0
        static void Main(string[] args)
        {
            if ((args.Length != 3) || (args.Length == 0))
            {
                Console.WriteLine("usage: read_SPI <VID> <PID> <address 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 addr in Hex (0x0)");
                    return;
                }
                else
                {
                    args[2] = args[2].Substring(2);
                }
            }
            else
            {
                Console.WriteLine("You must specify addr in Hex (0x0)");
                return;
            }

            int addr = int.Parse(args[2], 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] = 0x00;
            addr   = addr | 0x40;

            if ((OZY.Read_SPI(usb_dev_handle, 0, (byte)addr, OZY.SPI_EN_FPGA, OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1, ref buf)))
            {
                Console.WriteLine("Read from address " + addr.ToString("X") + " : " + buf[0].ToString("X"));
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Failed to read address " + addr);
            }

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