Esempio n. 1
0
        /// <summary>
        /// Used if only one device is connected, finds the serial number automatically
        /// Throws an exception if more than one device is found
        /// </summary>
        public HU320()
        {
            HIDInterface.interfaceDetails[] devices = HIDInterface.getConnectedDevices();
            int numExpectedDevices = 0;
            int deviceIndex        = 0;

            for (int i = 0; i < devices.Length; i++)
            {
                if ((devices[i].VID == DEFAULT_VID) && (devices[i].PID == DEFAULT_PID))
                {
                    numExpectedDevices++;
                    deviceIndex = i;
                }
            }

            if (numExpectedDevices == 0)
            {
                throw new Exception("No HU320 devices could be found!");
            }
            else if (numExpectedDevices > 1)
            {
                throw new Exception("Only one HU320 may be connected, " + numExpectedDevices.ToString() + " found.");
            }

            init(devices[deviceIndex].VID, devices[deviceIndex].PID, (ushort)devices[deviceIndex].serialNumber);
        }
Esempio n. 2
0
        /// <summary>
        /// Queries the operating system for the serial numbers of the devices conneced with the specified VID/PID
        /// </summary>
        /// <param name="VID">VID to search for</param>
        /// <param name="PID">PID to search for</param>
        /// <returns>Array of the connected device's serial numbers</returns>
        public static int[] getConnectedDevices(ushort VID, ushort PID)
        {
            HIDInterface.interfaceDetails[] devs = HIDInterface.getConnectedDevices();

            //find how many devices fit the expected type
            int numExpectedDevices = 0;

            foreach (HIDInterface.interfaceDetails D in devs)
            {
                if ((D.VID == VID) && (D.PID == PID))
                {
                    numExpectedDevices++;
                }
            }

            //create an array of the matching serial numbers
            int[] SNs        = new int[numExpectedDevices];
            int   matchIndex = 0;

            for (int i = 0; i < devs.Length; i++)
            {
                if ((devs[i].VID == VID) && (devs[i].PID == PID))
                {
                    SNs[matchIndex] = devs[i].serialNumber;
                    matchIndex++;
                }
            }
            return(SNs);
        }
Esempio n. 3
0
        //sets up the USB interface
        private void init(ushort VID, ushort PID, ushort serialNumber)
        {
            //Initialise globals
            this.clockSpeed_Hz         = 8000000; //8MHz
            this.UART_rxBytesThreshold = 10;
            this.SPI_rxBytesThreshold  = 1;
            //this.I2C_rxBytesThreshold = 1;
            this.UART_RXbuffer = new byte[0];
            this.SPI_RXbuffer  = new byte[0];


            usbI = new HIDInterface(VID, PID, serialNumber, true);    //create an interface to a specific unit
            usbI.dataReceived += new HIDInterface.dataReceivedEvent(usbI_dataReceived);


            //this eventwaithandle is used to flag when data has been received from a read
            waitReply = new EventWaitHandle(false, EventResetMode.AutoReset);
        }
 public HIDInterface GetHID()
 {
     hid = hid ?? new HIDInterface(this);
     return(hid);
 }
Esempio n. 5
0
 public SPIStream(NintendoController controller)
 {
     this.controller = controller;
     command         = controller.GetCommands();
     hid             = controller.GetHID();
 }