コード例 #1
0
        /**********************************************************************
         * NAME: GetDevice
         *
         * DESCRIPTION: Function checks to see if a matching USB device is attached
         * based on the VID and PID provided in the application. When a device is
         * found, it is assigned a handler (myHidDevice) and the GUI is updated to
         * reflect the connection. Additionally, if the device is not connected,
         * the function will update the GUI to reflect the disconnection.
         *
         ***********************************************************************/
        public void GetDevice()
        {
            //Look for device matching VID/PID
            myHidDevice = usbDevices[Vendor_ID, Product_ID_FW] as CyHidDevice;

            if (myHidDevice != null)                //Check to see if device is already connected
            {
                myHidDevice    = null;
                myHidDevice_FW = usbDevices[Vendor_ID, Product_ID_FW] as CyHidDevice;
            }
            else
            {
                // check if it is the bootloader
                myHidDevice = usbDevices[Vendor_ID, Product_ID_BL] as CyHidDevice;
                if (myHidDevice != null)
                {
                    myHidDevice    = null;
                    myHidDevice_BL = usbDevices[Vendor_ID, Product_ID_BL] as CyHidDevice;
                }
                else
                {
                    ;
                }
            }
        }
コード例 #2
0
ファイル: CyHidDeviceList.cs プロジェクト: congeevaramp/QtPrj
        public CyHidDevice this[int VID, int PID]
        {
            get
            {
                for (byte i = 0; i < Count; i++)
                {
                    CyHidDevice tmp = (CyHidDevice)Items[i];
                    if ((VID == tmp.VendorID) && (PID == tmp.ProductID))
                    {
                        return(tmp);
                    }
                }

                return(null);
            }
        }
コード例 #3
0
ファイル: CyHidDeviceList.cs プロジェクト: congeevaramp/QtPrj
        public CyHidDevice this[string sMfg, string sProd]
        {
            get
            {
                for (byte i = 0; i < Count; i++)
                {
                    CyHidDevice tmp = (CyHidDevice)Items[i];
                    if (sMfg.Equals(tmp.Manufacturer) && sProd.Equals(tmp.Product))
                    {
                        return(tmp);
                    }
                }

                return(null);
            }
        }
コード例 #4
0
        //USB COMMS Event Callback FUNCTIONS
        #region //USB COMMS Event Callback FUNCTIONS

        /**********************************************************************
         * NAME: usbDevices_DeviceRemoved
         *
         * DESCRIPTION: Event handler for the removal of a USB device. When the removal
         * of a USB device is detected, this function will be called which will check to
         * see if the device removed was the device we were using. If so, then reset
         * device handler (myHidDevice), disable the timer, and update the GUI.
         *
         ***********************************************************************/

        public void usbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            USBEventArgs usbEvent = e as USBEventArgs;

            // Handle FW ID
            if ((usbEvent.ProductID == Product_ID_FW) && (usbEvent.VendorID == Vendor_ID))
            {
                myHidDevice_FW = null;
                GetDevice();                        // Process device status
            }
            // Handle BL ID
            if ((usbEvent.ProductID == Product_ID_BL) && (usbEvent.VendorID == Vendor_ID))
            {
                myHidDevice_BL = null;
                GetDevice();                        // Process device status
            }
        }
コード例 #5
0
ファイル: CyHidDeviceList.cs プロジェクト: arnofan/tesis
        public CyHidDeviceList()
        {
            hDevNotification = IntPtr.Zero;

            RegisterForPnpEvents(MsgWin.Handle);

            CyHidDevice tmpDev = new CyHidDevice();
            int devs = tmpDev.DeviceCount;

            Items = new ArrayList(devs);

            for (int i = 0; i < devs; i++)
            {
                CyHidDevice tmp = new CyHidDevice();
                if (tmp.Open((byte)i)) Items.Add(tmp);
            }
        }
コード例 #6
0
ファイル: CyHidDeviceList.cs プロジェクト: congeevaramp/QtPrj
        public CyHidDeviceList()
        {
            hDevNotification = IntPtr.Zero;

            RegisterForPnpEvents(MsgWin.Handle);

            CyHidDevice tmpDev = new CyHidDevice();
            int         devs   = tmpDev.DeviceCount;

            Items = new ArrayList(devs);

            for (int i = 0; i < devs; i++)
            {
                CyHidDevice tmp = new CyHidDevice();
                if (tmp.Open((byte)i))
                {
                    Items.Add(tmp);
                }
            }
        }
コード例 #7
0
        public CyHidDevice this[string sMfg, string sProd]
        {
            get
            {
                if (_alreadyDisposed)
                {
                    throw new ObjectDisposedException("");
                }

                foreach (USBDevice dev in Items)
                {
                    CyHidDevice tmp = dev as CyHidDevice;
                    if ((tmp != null) && sMfg.Equals(tmp.Manufacturer) && sProd.Equals(tmp.Product))
                    {
                        return(tmp);
                    }
                }

                return(null);
            }
        }
コード例 #8
0
        public CyHidDevice this[int VID, int PID, int UsagePg, int Usage]
        {
            get
            {
                if (_alreadyDisposed)
                {
                    throw new ObjectDisposedException("");
                }

                foreach (USBDevice dev in Items)
                {
                    CyHidDevice tmp = dev as CyHidDevice;
                    if ((tmp != null) && (VID == tmp.VendorID) && (PID == tmp.ProductID) &&
                        (UsagePg == tmp.UsagePage) && (Usage == tmp.Usage))
                    {
                        return(tmp);
                    }
                }

                return(null);
            }
        }
コード例 #9
0
ファイル: USBDeviceList.cs プロジェクト: secretan/QtPrj
        public USBDevice Add()
        {
            if (_alreadyDisposed) throw new ObjectDisposedException("");

            USBDevice tmp, tmpDev;

            foreach (Guid guid in USBDriverGuids)
            {
                // tmpDev is just used for the DeviceCount functionality
                if (guid.Equals(CyConst.StorGuid))
                    tmpDev = new CyUSBStorDevice(guid);
                else if (guid.Equals(HidGuid))
                    tmpDev = new CyHidDevice(guid);
                else
                    tmpDev = new CyFX2Device(guid);

                // The number of devices now connected to this GUID
                int connectedDevs = tmpDev.DeviceCount;
                tmpDev.Dispose();

                // Find out how many items have this guid
                int listedDevs = 0;
                foreach (USBDevice dev in Items)
                    if (guid.Equals(CyConst.StorGuid) && (dev._drvGuid.Equals(CyConst.CdGuid) || dev._drvGuid.Equals(CyConst.DiskGuid)))
                        listedDevs++;
                    else if (dev._drvGuid.Equals(guid))
                        listedDevs++;

                // If greater, add
                if (connectedDevs > listedDevs)
                {
                    for (byte d = 0; d < connectedDevs; d++)
                    {
                        // Create the new USBDevice object of the correct type, based on guid
                        if (guid.Equals(CyConst.StorGuid))
                            tmp = new CyUSBStorDevice(guid);
                        else if (guid.Equals(HidGuid))
                            tmp = new CyHidDevice(guid);
                        else
                        {
                            tmp = new CyFX2Device(guid);
                            if (tmp.Open((byte)d))
                            {// open handle to check device type
                                CyUSBDevice t = tmp as CyUSBDevice;
                                if (!t.CheckDeviceTypeFX3FX2())
                                {//FX3
                                    tmp.Close();
                                    tmp = new CyFX3Device(guid);
                                }
                                else
                                    tmp.Close();
                            }

                        }

                        // If this device not already in the list
                        if (tmp.Open(d) && (DeviceIndex(tmp) == 0xFF))
                        {
                            Items.Add(tmp);
                            tmp.RegisterForPnPEvents(MsgWin.Handle);
                            if (connectedDevs == 1 && d == 0) return tmp;
                        }
                    }

                }
            }

            return null;
        }
コード例 #10
0
        public USBDeviceList(byte DeviceMask, App_PnP_Callback fnCallBack)
        {
            Items             = new ArrayList();
            hDevNotifications = new ArrayList();
            USBDriverGuids    = new ArrayList();

            EventCallBack = new App_PnP_Callback(PnP_Event_Handler);

            MsgWin.AppCallback = EventCallBack;
            AppCallBack        = fnCallBack;

            // Get the HID GUID
            PInvoke.HidD_GetHidGuid(ref HidGuid);

            // Create list of driver GUIDs for this instance
            FillDriverGuids(DeviceMask);

            USBDevice tmpDev, tmp;
            int       devs = 0;

            foreach (Guid guid in USBDriverGuids)
            {
                // tmpDev is just used for the DeviceCount functionality
                if (guid.Equals(CyConst.StorGuid))
                {
                    tmpDev = new CyUSBStorDevice(guid);
                }
                else if (guid.Equals(HidGuid))
                {
                    tmpDev = new CyHidDevice(HidGuid);
                }
                else
                {
                    tmpDev = new CyFX2Device(guid);
                }

                // DeviceCount is IO intensive. Don't use it as for loop limit
                devs = tmpDev.DeviceCount;

                for (int d = 0; d < devs; d++)
                {
                    // Create the new USBDevice objects of the correct type, based on guid
                    if (guid.Equals(CyConst.StorGuid))
                    {
                        tmp = new CyUSBStorDevice(guid);
                    }
                    else if (guid.Equals(HidGuid))
                    {
                        tmp = new CyHidDevice(HidGuid);
                    }
                    else
                    {
                        tmp = new CyFX2Device(guid);
                        if (tmp.Open((byte)d))
                        {// open handle to check device type
                            CyUSBDevice t = tmp as CyUSBDevice;
                            if (!t.CheckDeviceTypeFX3FX2())
                            {//FX3
                                tmp.Close();
                                tmp = new CyFX3Device(guid);
                            }
                            else
                            {
                                tmp.Close();
                            }
                        }
                    }

                    if (tmp.Open((byte)d))
                    {
                        Items.Add(tmp); // This creates new reference to tmp in Items
                        tmp.RegisterForPnPEvents(MsgWin.Handle);
                    }
                }

                if (guid.Equals(CyConst.StorGuid))   // We're not sure which drivers were identified, so setup PnP with both
                {
                    RegisterForPnpEvents(MsgWin.Handle, CyConst.DiskGuid);
                    RegisterForPnpEvents(MsgWin.Handle, CyConst.CdGuid);
                }
                else
                {
                    RegisterForPnpEvents(MsgWin.Handle, guid);
                }
            } // foreach guid
        }
コード例 #11
0
        public USBDevice Add()
        {
            if (_alreadyDisposed)
            {
                throw new ObjectDisposedException("");
            }

            USBDevice tmp, tmpDev;

            foreach (Guid guid in USBDriverGuids)
            {
                // tmpDev is just used for the DeviceCount functionality
                if (guid.Equals(CyConst.StorGuid))
                {
                    tmpDev = new CyUSBStorDevice(guid);
                }
                else if (guid.Equals(HidGuid))
                {
                    tmpDev = new CyHidDevice(guid);
                }
                else
                {
                    tmpDev = new CyFX2Device(guid);
                }

                // The number of devices now connected to this GUID
                int connectedDevs = tmpDev.DeviceCount;
                tmpDev.Dispose();

                // Find out how many items have this guid
                int listedDevs = 0;
                foreach (USBDevice dev in Items)
                {
                    if (guid.Equals(CyConst.StorGuid) && (dev._drvGuid.Equals(CyConst.CdGuid) || dev._drvGuid.Equals(CyConst.DiskGuid)))
                    {
                        listedDevs++;
                    }
                    else if (dev._drvGuid.Equals(guid))
                    {
                        listedDevs++;
                    }
                }

                // If greater, add
                if (connectedDevs > listedDevs)
                {
                    for (byte d = 0; d < connectedDevs; d++)
                    {
                        // Create the new USBDevice object of the correct type, based on guid
                        if (guid.Equals(CyConst.StorGuid))
                        {
                            tmp = new CyUSBStorDevice(guid);
                        }
                        else if (guid.Equals(HidGuid))
                        {
                            tmp = new CyHidDevice(guid);
                        }
                        else
                        {
                            tmp = new CyFX2Device(guid);
                            if (tmp.Open((byte)d))
                            {// open handle to check device type
                                CyUSBDevice t = tmp as CyUSBDevice;
                                if (!t.CheckDeviceTypeFX3FX2())
                                {//FX3
                                    tmp.Close();
                                    tmp = new CyFX3Device(guid);
                                }
                                else
                                {
                                    tmp.Close();
                                }
                            }
                        }


                        // If this device not already in the list
                        if (tmp.Open(d) && (DeviceIndex(tmp) == 0xFF))
                        {
                            Items.Add(tmp);
                            tmp.RegisterForPnPEvents(MsgWin.Handle);
                            return(tmp);
                        }
                        else
                        {
                            tmp.Dispose();
                        }
                    }
                }
            }

            return(null);
        }
コード例 #12
0
ファイル: USBDeviceList.cs プロジェクト: secretan/QtPrj
        public USBDeviceList(byte DeviceMask, App_PnP_Callback fnCallBack)
        {
            Items = new ArrayList();
            hDevNotifications = new ArrayList();
            USBDriverGuids = new ArrayList();

            EventCallBack = new App_PnP_Callback(PnP_Event_Handler);

            MsgWin.AppCallback = EventCallBack;
            AppCallBack = fnCallBack;

            // Get the HID GUID
            PInvoke.HidD_GetHidGuid(ref HidGuid);

            // Create list of driver GUIDs for this instance
            FillDriverGuids(DeviceMask);

            USBDevice tmpDev, tmp;
            int devs = 0;

            foreach (Guid guid in USBDriverGuids)
            {
                // tmpDev is just used for the DeviceCount functionality
                if (guid.Equals(CyConst.StorGuid))
                    tmpDev = new CyUSBStorDevice(guid);
                else if (guid.Equals(HidGuid))
                    tmpDev = new CyHidDevice(HidGuid);
                else
                    tmpDev = new CyFX2Device(guid);

                // DeviceCount is IO intensive. Don't use it as for loop limit
                devs = tmpDev.DeviceCount;

                for (int d = 0; d < devs; d++)
                {
                    // Create the new USBDevice objects of the correct type, based on guid
                    if (guid.Equals(CyConst.StorGuid))
                        tmp = new CyUSBStorDevice(guid);
                    else if (guid.Equals(HidGuid))
                        tmp = new CyHidDevice(HidGuid);
                    else
                    {
                        tmp = new CyFX2Device(guid);
                        if (tmp.Open((byte)d))
                        {// open handle to check device type
                            CyUSBDevice t = tmp as CyUSBDevice;
                            if (!t.CheckDeviceTypeFX3FX2())
                            {//FX3
                                tmp.Close();
                                tmp = new CyFX3Device(guid);
                            }
                            else
                                tmp.Close();
                        }

                    }

                    if (tmp.Open((byte)d))
                    {
                        Items.Add(tmp); // This creates new reference to tmp in Items
                        tmp.RegisterForPnPEvents(MsgWin.Handle);
                    }
                }

                if (guid.Equals(CyConst.StorGuid))   // We're not sure which drivers were identified, so setup PnP with both
                {
                    RegisterForPnpEvents(MsgWin.Handle, CyConst.DiskGuid);
                    RegisterForPnpEvents(MsgWin.Handle, CyConst.CdGuid);
                }
                else
                    RegisterForPnpEvents(MsgWin.Handle, guid);

            } // foreach guid
        }
コード例 #13
0
 public HIDCommunicationsChannel(CyHidDevice device)
 {
     this._device = device;
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: jmccall/3D-Immersion-Project
 /**********************************************************************
 * NAME: usbDevices_DeviceRemoved
 *
 * DESCRIPTION: Event handler for the removal of a USB device. When the removal
 * of a USB device is detected, this function will be called which will check to
 * see if the device removed was the device we were using. If so, then reset
 * device handler (myHidDevice), disable the timer, and update the GUI.
 *
 ***********************************************************************/
 public void usbDevices_DeviceRemoved(object sender, EventArgs e)
 {
     USBEventArgs usbEvent = e as USBEventArgs;
     if ((usbEvent.ProductID == Product_ID) && (usbEvent.VendorID == Vendor_ID))
     {
         InputTimer.Enabled = false;         // Disable interrupts for polling HID device
         myHidDevice = null;
         GetDevice();                        // Process device status
     }
 }
コード例 #15
0
ファイル: Form1.cs プロジェクト: jmccall/3D-Immersion-Project
        /**********************************************************************
        * NAME: GetDevice
        *
        * DESCRIPTION: Function checks to see if a matching USB device is attached
        * based on the VID and PID provided in the application. When a device is
        * found, it is assigned a handler (myHidDevice) and the GUI is updated to
        * reflect the connection. Additionally, if the device is not connected,
        * the function will update the GUI to reflect the disconnection.
        *
        ***********************************************************************/
        public void GetDevice()
        {
            //Look for device matching VID/PID
            myHidDevice = usbDevices[Vendor_ID, Product_ID] as CyHidDevice;

            if (myHidDevice != null)                //Check to see if device is already connected
            {

                Status.Text = "Connected";
                Status.ForeColor = Color.Green;
                SwStatus.Enabled = true;
                InputTimer.Enabled = true;          //Enable background timer

                Update_LED();                       //Initialize the LED based on current GUI configuration
                Update_PWMDutyCycle();              //Initialize the PWM based on current GUI configuration

            }

            else
            {
                Status.Text = "Disconnected";
                Status.ForeColor = Color.Red;
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: secretan/MyUsbPrj
        /* Summary
            Initialize global variables defined
        */
        private void Initialize()
        {
            scriptfile = "";
            playscriptfile = "";
            Resetreg = 0xE600;
            Maxaddr = 0x4000;
            Max_Ctlxfer_size = 0x1000;
            bRecording = false;
            Xaction = new TTransaction();
            list = new ArrayList();
            list1 = new ArrayList();

            curEndpt = null;
            curCyUsbDev = null;
            curHidDev = null;
            curHidReport = null;
        }
コード例 #17
0
ファイル: Form1.cs プロジェクト: secretan/MyUsbPrj
        /* Summary
            Any selection changes in the tree view will trigger this function "at start the first device is always selected leading into this function"
        */
        private void DeviceTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            XferTextBox.Text = "";
            XferDataBox.Text = "";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(">&&");
            for (int i = 1; i < this.XferTextBox.MaxLength; i++)
            {
                sb.Append(" &&");
            }

            this.XferDataBox.Mask = sb.ToString();

            TreeNode selNode = DeviceTreeView.SelectedNode;
            string nodeText = selNode.Text;

            CyUSBInterfaceContainer curIntfcContainer = selNode.Tag as CyUSBInterfaceContainer;
            CyUSBInterface curIntfc = selNode.Tag as CyUSBInterface;
            CyUSBConfig curConfig = selNode.Tag as CyUSBConfig;

            curEndpt = selNode.Tag as CyUSBEndPoint;
            curCyUsbDev = selNode.Tag as CyUSBDevice;

            curHidDev = null;
            curHidReport = null;

            if (curConfig != null)
            {
                curCyUsbDev = selNode.Parent.Tag as CyUSBDevice;
            }
            else if (curIntfcContainer != null)
            {
                curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice;
            }
            else if (curIntfc != null)
            {
                curCyUsbDev = selNode.Parent.Parent.Parent.Tag as CyUSBDevice;
                curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting;
            }
            else if (curEndpt != null)
            {

                int minXfer = curEndpt.MaxPktSize;

                if (curEndpt.Attributes == 1)
                    minXfer *= 8;

                NumBytesBox.Text = minXfer.ToString();

                // Set the AltSetting
                if (curEndpt.Address != 0) // Only if we're not on the Control Endpoint
                {
                    curCyUsbDev = selNode.Parent.Parent.Parent.Parent.Tag as CyUSBDevice;
                    curIntfc = selNode.Parent.Tag as CyUSBInterface;
                    curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting;
                }
                else
                {
                    curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice;
                }
            }
            else if ((selNode.Tag is CyHidButton) || (selNode.Tag is CyHidValue))
            {
                curHidDev = selNode.Parent.Parent.Tag as CyHidDevice;
                curHidReport = selNode.Parent.Tag as CyHidReport;

                NumBytesBox.Text = curHidReport.RptByteLen.ToString();
                nodeText = selNode.Parent.Text;
            }
            else if (selNode.Tag is CyHidReport)
            {
                curHidDev = selNode.Parent.Tag as CyHidDevice;
                curHidReport = selNode.Tag as CyHidReport;

                NumBytesBox.Text = curHidReport.RptByteLen.ToString();
            }
            else if (selNode.Tag is CyHidDevice)
                curHidDev = selNode.Tag as CyHidDevice;

            ConfigDataXferBtn(nodeText);

            DescText.Text = selNode.Tag.ToString();

            Sync_Form_Resize = 1;
            Form1_Resize(sender, null);
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: secretan/MyUsbPrj
        /* Summary
            Event handler to handle changes in Check box of Device Class Selection Tabpage and at Start
        */
        private void CyUSBDeviceBox_CheckedChanged(object sender, EventArgs e)
        {
            byte DeviceMask = 0;

            DeviceMask |= CyUSBDeviceBox.Checked ? CyConst.DEVICES_CYUSB : (byte)0;
            DeviceMask |= MSCDeviceBox.Checked ? CyConst.DEVICES_MSC : (byte)0;
            DeviceMask |= HIDDeviceBox.Checked ? CyConst.DEVICES_HID : (byte)0;

            if (usbDevices != null)
            {
                usbDevices.DeviceRemoved -= usbDevices_DeviceRemoved;
                usbDevices.DeviceAttached -= usbDevices_DeviceAttached;
                usbDevices.Dispose();
            }

            usbDevices = new USBDeviceList(DeviceMask);

            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);

            curEndpt = null;
            curCyUsbDev = null;
            curHidDev = null;
            curHidReport = null;
            RefreshDeviceTree();
        }