Пример #1
0
        private void btnSendSR_Click(object sender, EventArgs e)
        {
            int cmd = Convert.ToInt32(txtSR.Text);

            byte[] buf = BitConverter.GetBytes(cmd);

            byte[] tempbuf = new byte[4];

            if (buf.Length < 4)
            {
                return;
            }

            // put bytes in proper order MSB to LSB
            for (int i = 0; i < buf.Length; i++)
            {
                tempbuf[buf.Length - 1 - i] = buf[i];
            }

            for (int i = 0; i < buf.Length; i++)
            {
                listBox1.Items.Add(buf[i]);
            }

            buf = tempbuf;
            // send to OZY register 0x02, 32 bits
            if (hdev != IntPtr.Zero)
            {
                OZY.Write_SPI(hdev, 0, 0x02, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            }
        }
Пример #2
0
        private void hScrollBar2_Scroll(object sender, ScrollEventArgs e)
        {
            byte[] buf     = BitConverter.GetBytes(hScrollBar2.Value); // gets 4 bytes
            byte[] tempbuf = new byte[4];

            if (buf.Length < 4)
            {
                return;
            }

            // put bytes in proper order MSB to LSB
            for (int i = 0; i < buf.Length; i++)
            {
                tempbuf[buf.Length - 1 - i] = buf[i];
            }

            buf = tempbuf;

            textBox1.Text = ((((float)hScrollBar2.Value * (float)100)) / (float)Math.Pow(2, 32)).ToString();
            textBox2.Text = buf[0].ToString("X2")
                            + ":" + buf[1].ToString("X2")
                            + ":" + buf[2].ToString("X2")
                            + ":" + buf[3].ToString("X2");

            // send to OZY register 0x01, 32 bits
            if (hdev != IntPtr.Zero)
            {
                OZY.Write_SPI(hdev, 0, 0x01, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            }
        }
Пример #3
0
        // latch data into one of the PIO registers.
        // addr needs to be on of the PIO_xxx constants
        // returns true on success, false on failure
        private bool LatchRegister(byte addr, byte data)
        {
            bool rc;

            byte[] buf = new byte[1];
            buf[0] = data;
            rc     = OZY.Write_SPI(usb_dev_handle, 0, ADDR_DATA, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            if (!rc)
            {
                System.Console.WriteLine("Latch to ADDR_DATA failed\n");
                return(false);
            }
            buf[0] = addr;
            rc     = OZY.Write_SPI(usb_dev_handle, 0, ADDR_CTRL, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            if (!rc)
            {
                System.Console.WriteLine("Latch to ADDR_CTRL failed\n");
                return(false);
            }
            buf[0] = PIO_NONE;
            rc     = OZY.Write_SPI(usb_dev_handle, 0, ADDR_CTRL, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            if (!rc)
            {
                System.Console.WriteLine("Latch to ADDR_CTRL #2 failed\n");
                return(false);
            }
            return(true);
        }
Пример #4
0
        bool writeDataSPI(IntPtr hdev, byte val)
        {
            bool rc;

            byte[] buf = new byte[1];
            buf[0] = val;
            rc     = OZY.Write_SPI(usb_dev_handle, 0, ADDR_DATA, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf);
            Console.WriteLine("WriteSPI rc: " + rc);
            return(rc);
        }
Пример #5
0
        static void Main(string[] args)
        {
            if ((args.Length != 4) || (args.Length == 0))
            {
                Console.WriteLine("usage: write_SPI <VID> <PID> <address 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 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);

            if (args[3].Length > 2)
            {
                if (args[3].Substring(0, 2) != "0x")
                {
                    Console.WriteLine("You must specify value in Hex (0x0)");
                    return;
                }
                else
                {
                    args[3] = args[3].Substring(2);
                }
            }
            else
            {
                Console.WriteLine("You must specify value in Hex (0x0)");
                return;
            }

            int value = int.Parse(args[3], 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[1];
            addr = addr & 0x3F;

            buf[0] = (byte)value;

            if ((OZY.Write_SPI(usb_dev_handle, 0, (byte)addr, OZY.SPI_EN_FPGA, (OZY.SPI_FMT_MSB | OZY.SPI_FMT_HDR_1), buf)))
            {
                Console.WriteLine("Wrote to address: " + addr + " : " + value);
            }
            else
            {
                Console.WriteLine("Failed to write address: " + addr);
            }
            Console.WriteLine("Closing device...");
            libUSB_Interface.usb_close(usb_dev_handle);
            Console.WriteLine("done...");
        }