示例#1
0
        public void USBinit()
        {
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();

            var buzzersFound = devices.Where((hiddev) => (((hiddev.PID.ToString("X4") == "1000") ||
                                                           (hiddev.PID.ToString("X4") == "0002")) &&
                                                          (hiddev.VID.ToString("X4") == "054C"))).ToList();

            buzzersBuffersLastIn[0] = new byte[6];
            buzzersBuffersOut[0]    = new byte[8];
            buzzersBuffersLastIn[1] = new byte[6];
            buzzersBuffersOut[1]    = new byte[8];

            if (buzzersFound.Count > 0)
            {
                buzzers[0]           = new HIDDevice(buzzersFound[0].devicePath, false);
                buzzersBuffersOut[0] = new byte[buzzers[0].productInfo.OUT_reportByteLength];
                irqstat[0]           = IrqState.check;
                Thread readOne = new Thread(this.ReadThread0);
                readOne.Start();
                if (buzzersFound.Count > 1)
                {
                    buzzers[1]           = new HIDDevice(buzzersFound[1].devicePath, false);
                    buzzersBuffersOut[1] = new byte[buzzers[1].productInfo.OUT_reportByteLength];
                    irqstat[1]           = IrqState.check;
                    Thread readTwo = new Thread(this.ReadThread1);
                    readTwo.Start();
                }
            }
        }
示例#2
0
        // Apologies for the repeated code, however i feel it provides a better demonstration
        // of the functionality of this code.
        public void useSynchronousOperation()
        {
            //Get the details of all connected USB HID devices
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();

            //Arbitrarily select one of the devices which we found in the previous step
            //record the details of this device to be used in the class constructor
            int    selectedDeviceIndex = 0;
            ushort VID        = devices[selectedDeviceIndex].VID;
            ushort PID        = devices[selectedDeviceIndex].PID;
            int    SN         = devices[selectedDeviceIndex].serialNumber;
            string devicePath = devices[selectedDeviceIndex].devicePath;

            //create a handle to the device by calling the constructor of the HID class
            //This can be done using either the VID/PID/Serialnumber, or the device path (string)
            //all of these details are available from the HIDDevice.interfaceDetails[] struct array created above
            //The "false" boolean in the constructor tells the class we only want synchronous operation
            HIDDevice device = new HIDDevice(devicePath, false);

            //OR, the normal usage when you know the VID and PID of the device
            //HIDDevice device = new HIDDevice(VID, PID, (ushort)SN, false);

            //Write some data to the device (the write method throws an exception if the data is longer than the report length
            //specified by the device, this length can be found in the HIDDevice.interfaceDetails struct)
            byte[] writeData = { 0x00, 0x01, 0x02, 0x03, 0x04 };
            device.write(writeData);    //Its that easy!!

            //Read some data synchronously from the device. This method blocks the calling thread until the data
            //is returned. This takes 1-20ms for most HID devices
            byte[] readData = device.read();    //again, that easy!

            //close the device to release all handles etc
            device.close();
        }
示例#3
0
        // Connect the microcontroller
        public bool Connect(ushort PID)
        {
            // Check if the MCU is already connected
            if (bMCUConnected)
            {
                return(true);
            }

            // Get all the connected devices
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();


            // List all available device paths in the listbox
            if (devices.Length > 0)
            {
                for (int i = 0; i < devices.Length; i++)
                {
                    // Search for the needed device
                    if (devices[i].VID == 0x0483 && devices[i].PID == PID)
                    {
                        // MCU found => connect it
                        device = new HIDDevice(devices[i].VID, devices[i].PID, (ushort)devices[i].serialNumber, false);
                    }
                }
                if (device != null)
                {
                    bMCUConnected = true;
                }
            }
            return(bMCUConnected);
        }
示例#4
0
        public bool startAsyncOperation(ushort MyDevVID, ushort MyDevPID)
        {
            //Get the details of all connected USB HID devices
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();


            //Arbitrarily select one of the devices which we found in the previous step
            //record the details of this device to be used in the class constructor
            int selectedDeviceIndex = -1;

            for (int i = 0; i < devices.Length; i++)
            {
                if ((devices[i].VID == MyDevVID) && (devices[i].PID == MyDevPID))
                {
                    selectedDeviceIndex = i;
                }
            }

            if (selectedDeviceIndex == -1)
            {
                return(false);
            }

            ushort VID        = devices[selectedDeviceIndex].VID;
            ushort PID        = devices[selectedDeviceIndex].PID;
            int    SN         = devices[selectedDeviceIndex].serialNumber;
            string devicePath = devices[selectedDeviceIndex].devicePath;

            //create a handle to the device by calling the constructor of the HID class
            //This can be done using either the VID/PID/Serialnumber, or the device path (string)
            //all of these details are available from the HIDDevice.interfaceDetails[] struct array created above
            //The "true" boolean in the constructor tells the class we want asynchronous operation this time
            device = new HIDDevice(devicePath, true);

            //OR, the normal usage when you know the VID and PID of the device
            //HIDDevice device = new HIDDevice(VID, PID, (ushort)SN, true);

            //next create the event handler for the incoming reports
            device.dataReceived += new HIDDevice.dataReceivedEvent(device_dataReceived);

            //Write some data to the device (the write method throws an exception if the data is longer than the report length
            //specified by the device, this length can be found in the HIDDevice.interfaceDetails struct)
            //The write method is identical to the synchronous mode of operation
            byte[] writeData = new byte[64];
            for (int i = 0; i < writeData.Length; i++)
            {
                writeData[i] = Convert.ToByte(i + 100);
            }

            device.write(writeData);    //Its that easy!!

            //Send your program off to do other stuff here, wait for UI events etc
            //When a report occurs, the device_dataReceived(byte[] message) method will be called
            //System.Threading.Thread.Sleep(100);

            //close the device to release all handles etc
            //device.close();
            return(true);
        }
示例#5
0
        public void find()
        {
            devices = HIDDevice.getConnectedDevices();

            //int selectedDeviceIndex = 0;

            /*ushort VID = devices[selectedDeviceIndex].VID;
             * ushort PID = devices[selectedDeviceIndex].PID;
             * int SN = devices[selectedDeviceIndex].serialNumber;*/
            // devicePath = devices[selectedDeviceIndex].devicePath;
            //devicePath = null;
            for (int i = 0; i <= devices.Length; i++)
            {
                try
                {
                    if (devices[i].VID == 9025 && devices[i].PID == 32822)
                    {
                        devicePath = devices[i].devicePath;
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }

            if (devicePath == null)
            {
                Console.WriteLine("Device not found");
                connected = false;
            }

            //create a handle to the device by calling the constructor of the HID class
            //This can be done using either the VID/PID/Serialnumber, or the device path (string)
            //all of these details are available from the HIDDevice.interfaceDetails[] struct array created above
            //The "true" boolean in the constructor tells the class we want asynchronous operation this time
            //device = new HIDDevice(devicePath, true);
            //OR, the normal usage when you know the VID and PID of the device
            //HIDDevice device = new HIDDevice(VID, PID, (ushort)SN, true);

            //next create the event handler for the incoming reports
            //device.dataReceived += new HIDDevice.dataReceivedEvent(device_dataReceived);

            //Write some data to the device (the write method throws an exception if the data is longer than the report length
            //specified by the device, this length can be found in the HIDDevice.interfaceDetails struct)
            //The write method is identical to the synchronous mode of operation
            //byte[] writeData = { 0x00, 0x01, 0x02, 0x03, 0x04 };
            //device.write(writeData);    //Its that easy!!

            //Send your program off to do other stuff here, wait for UI events etc
            //When a report occurs, the device_dataReceived(byte[] message) method will be called

            /*while(!receiveData)
             * System.Threading.Thread.Sleep(100);*/

            //close the device to release all handles etc
            //device.close();
        }
示例#6
0
        public bool FindDev()
        {
            bool result      = false;
            bool foundtarget = false;

            HIDDevice.interfaceDetails[]      devices      = HIDDevice.getConnectedDevices();
            List <HIDDevice.interfaceDetails> KingstonDevs = new List <HIDDevice.interfaceDetails>();

            for (int i = 0; i < devices.Length; i++)
            {
                // Alpha S
                if (devices[i].VID == TARGET_VID && devices[i].PID == TARGET_PID) //if (devices[i].VID == KTC_VID && devices[i].PID == ALPHAS_PID)
                {
                    label_vid.Text = devices[i].VID.ToString("X4");               //KTC_VID.ToString("X4");
                    label_pid.Text = devices[i].PID.ToString("X4");               //DART_PID1.ToString("X4");
                    //textBox_device.AppendText("\r\nProduct : " + devices[i].product.ToString());
                    //textBox_device.AppendText("\r\nRevision : " + "0x" + devices[i].versionNumber.ToString("X"));
                    label_manufacturer.Text = devices[i].manufacturer.ToString();
                    label_product.Text      = devices[i].product.ToString();
                    label_revision.Text     = devices[i].versionNumber.ToString("X");

                    label_status.Text = "Detected";

                    CheckDev();

                    foundtarget = true;

                    break;
                }

                if (!foundtarget)
                {
                    empty_fields();

                    if (button_detect.Text == "STOP")
                    {
                        label_status.Text = "Detecting...";
                    }
                    if (button_detect.Text == "START")
                    {
                        label_status.Text = "";
                    }
                }
                foundtarget = false;
            }

            return(result);
        }
示例#7
0
    public bool disconnectDeviceTryOpenThread()
    {
        string devicePath = "";
        bool   exist      = false;

        // 检查当前设备是否可用
        InterfaceDetails[] devices = HIDDevice.getConnectedDevices();
        int deviceCount            = devices.Length;

        if (mCurDeviceCount != deviceCount)
        {
            mCurDeviceCount = deviceCount;
            exist           = false;
            for (int i = 0; i < deviceCount; ++i)
            {
                if (devices[i].VID == VID && devices[i].PID == PID)
                {
                    devicePath = devices[i].devicePath;
                    exist      = true;
                    break;
                }
            }
            if (!exist)
            {
                closeDevice();
            }
        }
        // 有设备,并且设备数量未变化,则认为有设备连接
        else if (deviceCount > 0)
        {
            exist = true;
        }
        // 如果发现设备被关闭,并且设备存在,则一直尝试打开设备
        if (!isDeviceConnect() && exist)
        {
            openDevice(devicePath);
        }
        // 暂时不实现热插拔
        if (isDeviceConnect())
        {
            return(false);
        }
        return(true);
    }
示例#8
0
 /// <summary>
 /// Возвращает устройство для работы с кроватью (пути к нему для дальнейшей работы с ним)
 /// </summary>
 private static HIDDevice GetBedUsbDevice()
 {
     try
     {
         var    devices    = HIDDevice.getConnectedDevices();
         string devicePath = null;
         foreach (var listofDevice in devices)
         {
             if (listofDevice.product == "belmed_v1") //итоговое название всех прошивок - другое
             {
                 devicePath = listofDevice.devicePath;
                 break;
             }
         }
         var device = devicePath != null ? new HIDDevice(devicePath, false) : null;
         return(device);
     }
     catch (Exception)
     {
         return(null);
     }
 }
示例#9
0
        static void Main()
        {
            Console.Clear();


            Console.Title = Name + " [" + Version + "]";

            // Create a joystick object
            Gamepad = new vJoy();
            iReport = new vJoy.JoystickState();

            // Get list of all connected HID devices
            HIDDevice.interfaceDetails[] Devices = HIDDevice.getConnectedDevices();

            // Count HID Devices
            int ConnectedDevices = 0;

            // Print devices list
            Console.Write("Select DJHero USB Dongle\n-----------------------");

            foreach (HIDDevice.interfaceDetails Dev in Devices)
            {
                ConnectedDevices++;
                Console.Write("\n{0}.{1} (VID:{2} PID:{3})", ConnectedDevices, Dev.product, Dev.VID.ToString("X"), Dev.PID.ToString("X"));
            }

            Console.Write("\n-----------------------\n");

            /* Wait for user selection  */
            Console.Write("Selection: ");

            // Parse user input
            if (!int.TryParse(Console.ReadLine(), out int devnum))
            {
                Console.Clear();
                Console.Write("Invalid input data!");
                Thread.Sleep(1000);
                Program.Main();
            }
            else
            {
                devnum -= 1;
            }

            // Check if user selected listed device
            if (devnum > ConnectedDevices - 1 | devnum < 0)
            {
                Console.Clear();
                Console.Write("Selected invalid value! (out of range)");
                Thread.Sleep(1000);
                Program.Main();
            }
            else
            {
                Console.Clear();
                Console.Write("Selected: {0}", Devices[devnum].product);

                // Check vJoy status
                switch (Gamepad.GetVJDStatus(1))
                {
                case VjdStat.VJD_STAT_MISS:

                    Console.Write("\n vJoy is not installed or enabled!");
                    Thread.Sleep(1000);
                    Program.Main();
                    break;

                case VjdStat.VJD_STAT_BUSY:
                    Console.Write("\n vJoy device {0} is already owned by another feeder", 1);
                    Thread.Sleep(1000);
                    Program.Main();
                    break;

                case VjdStat.VJD_STAT_FREE:
                    Console.Write("\n vJoy device 1 is free");

                    // Acquire device
                    Gamepad.AcquireVJD(1);
                    Gamepad.ResetVJD(1);

                    Thread.Sleep(1000);
                    Console.Clear();

                    // Start reading DJH Bytes
                    ReadDJHDevice(Devices[devnum].devicePath);

                    break;
                }
            }
            Thread.Sleep(-1);
        }