Ejemplo n.º 1
0
        /// <summary>
        /// //This class contain all the function used as C# DLL
        /// //In the application you can call these functions in the following way
        /// //TE_USB_FX2.TE_USB_FX2.FunctionName()
        /// </summary>
        /// <returns></returns>

        /// <summary>
        /// 3.1   TE_USB_FX2_ScanCards()
        ///
        ///3.1.1   Declaration
        ///public static int TE_USB_FX2_ScanCards(ref USBDeviceList USBdevList)
        ///
        ///3.1.2   Function Call
        ///Your application program shall call this function like this:
        ///TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_ScanCards( ref USBdevList);
        ///
        ///3.1.3   Description
        ///This function takes (a null initialized or an already initialized) USB device list, (re-)creates a USB device list,
        ///searches for Trenz Electronic USB FX2 devices (Cypress driver derivative and VID = 0xbd0, PID=0x0300) devices and counts them.
        ///This function returns the number of Trenz Electronic USB FX2 devices attached to the USB bus of the host computer.
        ///
        ///3.1.4   Parameters
        ///1. ref USBDeviceList USBdevList
        ///USBDeviceList is a type defined in CyUSB.dll.
        ///USBdevList is the list of devices served by the CyUSB.sys driver (or a derivative like TE_USB_FX2.sys). This parameter is
        ///passed by reference (ref). See page 139-140 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference).
        ///
        ///3.1.5   Return Value
        ///1. int : integer type.
        ///This function returns the number of USB devices attached to the host computer USB bus.
        /// </summary>
        /// <param name="USBdevList"></param>
        /// <returns = int></returns>

        public static int TE_USB_FX2_ScanCards(ref USBDeviceList USBdevList)
        {
            int    CardCount = 0;
            UInt16 PID       = 0x0000;
            UInt16 VID       = 0x0000;

            //Creation of a list of USB device that use the CYUSB.SYS driver
            USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //USBdevList.Count : this parameter give the number of card that use CyUSB.sys and its derivative
            //(like TE_USB_FX2_64.sys and TE_USB_FX2_32.sys used by Trenz Electronic)

            //If exist at least an USB device that use the CYUSB.SYS driver,
            //I search and count the number of these devices that are of Trenz Electronic
            if (USBdevList.Count != 0)
            {
                // Look for a device having VID = 0bd0, PID = 0300
                foreach (USBDevice dev in USBdevList)
                {
                    PID = dev.ProductID;
                    VID = dev.VendorID;
                    if ((((PID == 0x0300) && (VID == 0x0bd0)) == true))
                    {
                        CardCount++;
                    }
                }
                USBdevList.Dispose();
                return(CardCount);
            }
            else
            {
                USBdevList.Dispose();
                return(0);
            }
        }
Ejemplo n.º 2
0
 /*Summary
  * Executes on clicking close button
  */
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (usbDevices != null)
     {
         usbDevices.Dispose();
     }
 }
Ejemplo n.º 3
0
 // According to the CyUSB help USBDeviceList implements the IDisposable
 // interface and thus we should call the following function to dispose
 // it
 private void MainGUI_FormClosing_1(object sender, FormClosingEventArgs e)
 {
     if (deviceList != null)
     {
         deviceList.Dispose();
     }
 }
Ejemplo n.º 4
0
        public override bool Recover()
        {
            try
            {
                if (loopDevice != null)
                {
                    loopDevice.Dispose();
                    loopDevice = null;
                }

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


            inEndpoint  = null;
            outEndpoint = null;

            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            usbDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            return(intDevice());
        }
Ejemplo n.º 5
0
 } // end private void mUSBDevList_Attached(Object sender, EventArgs e)
 /// <summary>
 /// detected the usb is removing
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mUSBDevList_Removed(Object sender, EventArgs e)
 {
     mCyUSBDev.Dispose();
     mUSBDevList.Dispose();
     mUSBDevList.DeviceAttached -= mUSBDevList_Attached;
     mUSBDevList.DeviceRemoved -= mUSBDevList_Removed;
 } // end private void mUSBDevList_Removed(Object sender, EventArgs e)
Ejemplo n.º 6
0
 public void CloseDevice()
 {
     if (IsRunning)
     {
         StopReceiving();
     }
     usbDevices?.Dispose();
 }
Ejemplo n.º 7
0
        /*
         * 3.3   TE_USB_FX2_Close()
         *
         * 3.3.1   Declaration
         * public static bool TE_USB_FX2_Close(ref USBDeviceList USBdevList)
         *
         * 3.3.2   Function Call
         * Your application program shall call this function like this:
         * TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close(ref USBdevList);
         *
         * 3.3.3   Description
         * This function takes an already initialized USB device list and disposes it.
         * Due to the fact that we are coding C# here, the device list can or cannot be erased; this is in the scope of the garbage
         * collector and it cannot be forced by the user. Sometimes it is erased instantly, some other times it is never erased,
         * until the user closes the application program that uses this data.
         * Use of TE_USB_FX2_Close() function is NOT recommended for new software projects. Users may use this function only just before
         * exiting their applications. If users use this function anywhere else, they shall
         * manage System.ObjectDisposedException exceptions (try – catch) or
         * avoid using disposed resources.
         * Note: USBdevList is disposed, not set to null.
         * try
         * {
         *   Application Code
         * }
         * catch (System.ObjectDisposedException)
         * {
         *   Console.WriteLine("TE_USB_FX2_USBDevice disposed: you have used the wrong procedure!");
         * }
         *
         * If you want to close the current USB device (card) without opening another one, you shall use TE_USB_FX2_Open() with a device
         * number (CardNumber) that certainly does not exist (e.g. CardNumber = 200, because there can be a maximum of 127 USB devices
         * connected to a single host controller). The reason of this behavior is due to the CyUSB.dll as explained by Cypress document
         * CyUSB.NET.pdf, pages 132-133 and pages 139-140: “You should never invoke the Dispose method of a USBDevice directly. Rather,
         * the appropriate technique is to call the Dispose method of the USBDeviceList object that contains the USBDevice objects”
         * This function differs from its homonym of the previous TE0300DLL.dll in that it does not close a Handle but disposes (erases)
         * all USB devices in the list.
         * A more intuitive name for this function would have been TE_USB_FX2_CloseAll or TE_USB_FX2_Dispose.
         *
         * 3.3.4   Parameters
         * 1. ref USBDeviceList USBdevList
         * USBDeviceList is a type defined in CyUSB.dll. USBdevList is the list of Trenz Electronic USB FX2 devices attached to the USB bus
         * host computer. This parameter is passed by reference (ref). See page 139-140 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's
         * Reference).
         * 3.3.5   Return Value
         * 1. bool : logical type
         * This function returns true if it is able to dispose the list. If unable to do so, it returns false.
         */

        /// <summary>
        /// //////
        /// </summary>
        /// <param name="USBdevList"></param>
        /// <returns></returns>

        public static bool TE_USB_FX2_Close(ref USBDeviceList USBdevList)
        {
            if (USBdevList != null)
            {
                USBdevList.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        /* Summary
         *  closing the open form
         */
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // If close was selected while running the loopback, shut it down.
            if (bRunning)
            {
                StartBtn_Click(this, null);
            }

            if (usbDevices != null)
            {
                usbDevices.Dispose();
            }
        }
Ejemplo n.º 9
0
        /*Summary
         * Executes on clicking close button
         */
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            bRunning = false;
            if (tListen != null && tListen.IsAlive == true)
            {
                tListen.Abort();
                tListen.Join();
                tListen = null;
            }


            if (usbDevices != null)
            {
                usbDevices.Dispose();
            }
        }
Ejemplo n.º 10
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    foreach (var fx2Device in fx2Devices)
                    {
                        fx2Device.Dispose();
                    }

                    if (usbDeviceList != null)
                    {
                        usbDeviceList.Dispose();
                    }
                }

                disposed = true;
            }
        }