Exemplo n.º 1
3
        /* Summary
           Event handler (callback function) for new device attach
       */
        void USBdevList_DeviceAttached(object sender, EventArgs e)
        {
            USBEventArgs usbEvent = e as USBEventArgs;


            if ((usbEvent.ProductID == PIDCypress) && (usbEvent.VendorID == VIDCypress))
            {
                //PID_String = "0x8613";
                //VID_String = "0x04B4";
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                LogTextLine += "INFO: Cypress device is attached: " + (DateTime.Today).ToString() + "\r\n";               
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                
            }
            else if ((usbEvent.ProductID == PIDTrenzElectronic) && (usbEvent.VendorID == VIDTrenzElectronic))
            {

                if ((bResultLoadExternalRam == true) )
                {
                    bResultLoadExternalRam = false;
                    if (bVerboseLogText == true)
                    {
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                        LogTextLine += "INFO: Trenz Electronic device is attached: " + (DateTime.Today).ToString() + "\r\n";
                        LogTextLine += "INFO: It is a side effect of programming FX2 microcontroller RAM with Trenz Electronic firmware v3.02: the device is seen as removed even if it is not phisically removed" + "\r\n";
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    }
                }
                else
                {
                    if (bVerboseLogText == true)
                    {
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                        LogTextLine += "INFO: Trenz Electronic device is attached: " + (DateTime.Today).ToString() + "\r\n";
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    }
                }
                
            }
            else
            {
                if (bVerboseLogText == true)
                {
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "ERROR: Insertion of an Unspecified Electronic device " + "\r\n";
                    LogTextLine += "Insetion happens " + (DateTime.Today).ToString() + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                }
            }

            //A new USB device list is created
            backgroundWakeEvent.WaitOne(500);
            USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
            backgroundWakeEvent.WaitOne(500);
 
            //Refresh the information displayed on the GUI (Form1) about the Device inserted
            RefreshInformationUIThread();           
        }
Exemplo n.º 2
1
    /// <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;
      }
    }
Exemplo n.º 3
1
        /******Cypress USB EEPROM Programming****/
        //# USB Lg EEPROM programming 
        //This is the method that does the actual work.
        bool I2CEEPROM_Programming(BackgroundWorker worker, DoWorkEventArgs e)
        {
            // USBDeviceList USBdevList,
            // ref CyUSBDevice TE_USB_FX2_USBDevice
            // The parameter n must be >= 0 and <= 91.
            // Fib(n), with n > 91, overflows a long.  

            if (bClearLogTextBeforeEveryProgrammingOperation == true)
                LogTextLine = String.Empty;

            if (USBdevList == null)
            {
                throw new ArgumentException(
                    "At least one TE USB FX2 module must be attached");
            }

            bool result = false;
            bool opened = false;

            // Abort the operation if the user has canceled.
            // Note that a call to CancelAsync may have set 
            // CancellationPending to true just after the
            // last invocation of this method exits, so this 
            // code will not have the opportunity to set the 
            // DoWorkEventArgs.Cancel flag to true. This means
            // that RunWorkerCompletedEventArgs.Cancelled will
            // not be set to true in your RunWorkerCompleted
            // event handler. This is a race condition.

            if (worker.CancellationPending)
            {
                //TextLine = "line 1063";
                e.Cancel = true;
                return result;
            }
            else if (bFileUSB_Selected)
            {
                //TextLine = "line 1069";
                //timeout_ms = c_ulong(1000)		  # Timeout 1s
                //CardNumber = c_int(0)			   # Card Number 0
                //DriverBufferSize = c_int(132072)	# Driver Buffer Size 132072
                uint timeout_ms = 1000;
                //int CardNumber = 0;
                //int DriverBufferSizeWrite = 131072;
                //int DriverBufferSizeRead = 131072;

                byte[] Command = new byte[64];
                byte[] Reply = new byte[64];
                int CmdLength = 64;
                int ReplyLength = 64;

                UInt16 PID = 0;
                UInt16 VID = 0;

                op_error = 0;

                //Stopwatch stopWatch = new Stopwatch();
                //stopWatch.Start();
                //printlog("Programming EEPROM")
                //fpga_bitstream_size = len(usb_bitstream)			 # Calculate size
                //printlog("Firmware size " + str(fpga_bitstream_size))
                if (bVerboseLogText == true)
                {
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "Programming FX2 microcontroller EEPROM and RAM using I2C" + "\r\n";
                    LogTextLine += "INFO: The operation STARTS " + (DateTime.Today).ToString() + "\r\n";
                    LogTextLine += "INFO: OpenFutNET version running on the host: " + OpenFutNETversion  + "\r\n";
                    LogTextLine += "INFO: Operating system of the host:" + GetOSFriendlyName() + "\r\n";
                    LogTextLine += "INFO: .NET version running on the host: " + Environment.Version.ToString() + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n";
                }
                
                if (bVerboseLogText == false)
                    //LogTextLine += "\r\n" + "-----------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "FX2 microcontroller EEPROM programming: START.....";
                else
                    LogTextLine += "FX2 microcontroller EEPROM programming: START" + "\r\n";

                if (bVerboseLogText == true)
                    LogTextLine += "Firmware size " + usb_bitstream_size.ToString() + " bytes" + "\r\n";

                if (USBFile_FilePath.Length > 0)
                    bFileUSB_Selected = true;

                USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);

                if (USBdevList.Count != 0)
                {
                    fx2 = USBdevList[0] as CyFX2Device;
                    PID = fx2.ProductID;
                    VID = fx2.VendorID;
                    if (USBdevList.Count > 1)
                    {
                        MessageBox.Show("In this version the program must be used with a single Trenz Electronic or Cypress module attached. You must remove Cypress and/or Trenz Electronic micromodule(s) until only one module remains. This must be the module that you desire to write.");
                    }
                }

                if (((USBdevList.Count == 1) && (PID == PIDCypress) && (VID == VIDCypress) && bEEPROMSwitchSetToOn) || (((USBdevList.Count == 1) && (PID == PIDTrenzElectronic) && (VID == VIDTrenzElectronic))))
                {
                    if (bVerboseLogText == true)
                    {
                        LogTextLine += "INFO: VID and PID identify a Cypress Device: therefore EEPROM will be programmed using Cypress DLL 'CyUSB.dll'" + "\r\n";
                        LogTextLine += "INFO: Found " + (USBdevList.Count).ToString() + " card(s)" + "\r\n";
                        LogTextLine += "INFO: Connected to card 1" + "\r\n";
                    }

                    if ((USBdevList.Count == 1) && (PID == PIDCypress) && (VID == VIDCypress) && bEEPROMSwitchSetToOn)
                    {
                        PID_String = "0x8613";
                        VID_String = "0x04B4";
                    }
                    else
                    {
                        //PID and VID of Trenz Electronic device     
                        PID_String = "0x0300";
                        VID_String = "0x0BD0";         
                    }

                    opened = true;
 
                    if ((op_error == 0) && (opened == true))  //# No errors in past
                    {
                        StatusTextLine = "Programming FX2 microcontroller EEPROM";
                        if (bVerboseLogText == true)
                            LogTextLine += "Writing firmware to EEPROM: START" + "\r\n";
                        bResultLoadEEPROM = fx2.LoadEEPROM(USBFile_FilePath, true);

                        worker.ReportProgress(percentComplete_USB_EEPROMWrite);
                        if (bResultLoadEEPROM == false)
                        {
                            StatusTextLine = "Error: it is not possible to write EEPROM.";

                            if (bVerboseLogText == true)
                            {
                                LogTextLine += "ERROR: Can't call API function TE_USB_FX2_SendCommand + CMD_FX2_EEPROM_WRITE" + "\r\n";
                                LogTextLine += "INFO/WARNING: probably, you should move the EEPROM switch to ON" + "\r\n";
                            }
                            else
                                LogTextLine += " STOP. " + "ERROR: it is not possible to write the EEPROM. Probably, you should move the EEPROM switch to ON" + "\r\n";
                            op_error = 5;
                            LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                            worker.ReportProgress(percentComplete_USB_EEPROMWrite);                          
                            return false;
                        }
                        else
                        {
                            backgroundWakeEvent.WaitOne(750);
                            percentComplete_USB_EEPROMWrite = 100;
                            backgroundWakeEvent.WaitOne(750);
                            if (bVerboseLogText == true)
                                LogTextLine += "Writing firmware to EEPROM: STOP" + "\r\n";
                            else
                                LogTextLine += " STOP. " + "SUCCESS: FX2 microcontroller EEPROM programmed." + "\r\n";
                            StatusTextLine = "SUCCESS: FX2 microcontroller EEPROM programmed.";
                            worker.ReportProgress(percentComplete_USB_EEPROMWrite);
                            //break;
                        }
                    }
                }

               
            }             
            else          
            {
                StatusTextLine = "Error: file not selected";
                if (bVerboseLogText == true)
                    LogTextLine += "ERROR: File not selected" + "\r\n";
                op_error = 6;
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                return false;
                //op.set("Error")
                //printlog("ERROR: File not selected")          
            }

              
            if ((op_error == 0) || (bResultLoadEEPROM))           
            {
            
                //backgroundWakeEvent.WaitOne(5000);
                    
                if (bVerboseLogText == true)
                    LogTextLine += "FX2 microcontroller RAM Programming: START" + "\r\n";
                else
                    LogTextLine += "FX2 microcontroller RAM Programming: START.....";

                bResultLoadExternalRam = fx2.LoadExternalRam(USBFile_FilePath);
                    
                if (bResultLoadExternalRam == true)
                {
                    StatusTextLine = "SUCCESS: FX2 microcontroller EEPROM and RAM programmed";
                        
                    if (bVerboseLogText == true)
                    {                        
                        LogTextLine += "FX2 microcontroller RAM Programming: STOP" + "\r\n";
                        LogTextLine += "INFO: Programming FX2 microcontroller RAM with TE FX2 firmware v3.02 it is equivalent to remove and insert the module." + "\r\n";
                        LogTextLine += "INFO: Programming FX2 microcontroller RAM with TE FX2 firmware version earlier than v3.02 it is NOT equivalent to remove and inssert the module:" +"\r\n" 
                                        +"in this case you should click the button 'Refresh information about FPGA and FX2 microcontroller' to obtain the last value of firmware version" + "\r\n";
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n";
                        LogTextLine += "Programming EEPROM and RAM of FX2 microcontroller using I2C" + "\r\n";
                        LogTextLine += "INFO: The operation STOPS " + (DateTime.Today).ToString() + "\r\n";
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";                
                    }
                    else
                    {
                        LogTextLine += " STOP. " + "SUCCESS: FX2 microcontroller RAM programmed" + "\r\n";
                        LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                        //LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                        
                    }
                }
                else
                {
                    StatusTextLine = "Warning: RAM has not been written";
                    if (bVerboseLogText == true)
                        LogTextLine += "Warning: RAM has not been written" + "\r\n";
                    else
                        LogTextLine += " STOP. " + "Warning: it is not possible to write the RAM. You should power off/on cycle the TE USB FX2 module to load the RAM with EEPROM firmware." + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                    worker.ReportProgress(percentComplete_USB_EEPROMWrite);           
                }
         
                if (USBdevList != null)
                {
                        USBdevList.DeviceRemoved -= USBdevList_DeviceRemoved;
                        USBdevList.DeviceAttached -= USBdevList_DeviceAttached;
                        USBdevList.Dispose();           
                }

                //backgroundWakeEvent.WaitOne(6000);
                backgroundWakeEvent.WaitOne(500);
                USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
                USBdevList.DeviceAttached += new EventHandler(USBdevList_DeviceAttached);
                USBdevList.DeviceRemoved += new EventHandler(USBdevList_DeviceRemoved);
                TE_USB_FX2_USBDevice = USBdevList[0] as CyUSBDevice;
                //FX2MicronctrollerRamProgrammed = true;
                
                backgroundWakeEvent.WaitOne(500);

                //IF Trenz Electronic, non Cypress o DEWESoft
                /*
                while (bResultLoadExternalRam == true  ) 
                {
                    textBox_PID.Text = PID_String;
                    textBox_VID.Text = VID_String;



                    backgroundWakeEvent.WaitOne(1000);
                    Command1[0] = (byte)FX2_Commands.CMD_FX2_READ_VERSION;
                    //bSendCommand = false;
                    //if TE_USB_FX2_USBDevice.
                    bSendCommand = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command1, ref CmdLength1, ref Reply1, ref ReplyLength1, TIMEOUT_MS);
                    backgroundWakeEvent.WaitOne(1000);
                    if ( bSendCommand )
                    {                  
                        if (ReplyLength1 >= 4)             
                        {
                            bResultLoadExternalRam = false;
                            break;
                        }                 
                        else                    
                        {                  
                    
                        }     
                    }
                }
                */
                       
                worker.ReportProgress(percentComplete_USB_EEPROMWrite);
                backgroundWakeEvent.WaitOne(1000);
                worker.ReportProgress(percentComplete_USB_EEPROMWrite);                 
                backgroundWakeEvent.WaitOne(1000);                

                //LogTextLine += "Programming RAM of FX2 microcontroller: STOP" + "\r\n";
                worker.ReportProgress(percentComplete_USB_EEPROMWrite);

                return bResultLoadEEPROM;
                       
            }
            else
            {
                StatusTextLine = "Error: EEPROM has not been written";               
                if (bVerboseLogText == true)
                    LogTextLine += "ERROR: EEPROM has not been written" + "\r\n";
                else
                    LogTextLine += " STOP. " + "ERROR: it is not possible to write the EEPROM." + "\r\n";
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                worker.ReportProgress(percentComplete_USB_EEPROMWrite);
                result = false;
                return result;
            }    

            //return result;
        }
Exemplo n.º 4
0
 public JLusb()
 {
     mUSBDevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
     mUSBDevList.DeviceAttached += new EventHandler(mUSBDevList_Attached);
     mUSBDevList.DeviceRemoved += new EventHandler(mUSBDevList_Removed);
     if (mUSBDevList.Count > 0)
     {
         USBDetected();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// The main Form
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            //
            usbHIDDevices = new USBDeviceList(CyConst.DEVICES_HID);

            //Adding event handlers for device attachment and device removal
            usbHIDDevices.DeviceAttached += new EventHandler(usbHIDDevices_DeviceAttached);
            usbHIDDevices.DeviceRemoved += new EventHandler(usbHIDDevices_DeviceRemoved);
            GetHidDevice();
        }
Exemplo n.º 6
0
        public void setupUSBComms()
        {
            // Create a list of CYUSB devices for this application
            usbDevices = new CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_HID);

            //Add event handlers for device attachment and device removal
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);

            //Connect to the USB device
            GetDevice();
        }
Exemplo n.º 7
0
        /*the first part of the code configures the USB connection to the Psoc5lp
           * based on the driver cyusb.sys and inf configuration file cyusb.inf
           * cyusb.inf sets a VID of 0x04b4 and PID of 0x0010 which are configured
           * in the psoc USB device.  these drivers files are in the psoc project folder.
        *
        * All the USB code uses the CyUSB.DLL file which this program includes
           */
        public Form1()
        {
            InitializeComponent();

            // Create a list of CYUSB devices
            usbDevices  = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //Adding event handlers for device attachment and device removal
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);

            //The below function sets the device with particular VID and PId and searches for the device with the same VID and PID.
            setDevice();
        }
Exemplo n.º 8
0
        public Form1()
        {
            InitializeComponent();

            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            USBDevice dev = usbDevices[0];

            if (dev != null)
            {
                MyDevice = (CyUSBDevice)dev;

                GetEndPoint(MyDevice.Tree);
            }

            foreach (CyUSBEndPoint ep in EndPointList)
            {
                if (ep.Address == 0x86)
                    inEndPoint = ep;
                if (ep.Address == 0x2)
                    outEndPoint = ep;
            }
        }
Exemplo n.º 9
0
        public CypressDataAcq()
        {
            PPX = 64;
            QueueSz = 64;

            // Setup the callback routine for updating the UI
            updateUI = new UpdateUICallback(StatusUpdate);

            // Setup the callback routine for NullReference exception handling
            handleException = new ExceptionCallback(ThreadException);

            // Create the list of USB devices attached to the CyUSB.sys driver.
            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //Assign event handlers for device attachment and device removal.
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);

            //Set and search the device with VID-PID 04b4-1003 and if found, selects the end point
            SetDevice();

            TransferStatusText = "Acquisition Not Active";
        }
Exemplo n.º 10
0
    /*
     * 3.2   TE_USB_FX2_Open()   
     * 
     * 3.2.1   Declaration
     * public static bool TE_USB_FX2_Open(ref CyUSBDevice TE_USB_FX2_USBDevice, ref USBDeviceList USBdevList, int CardNumber)
     * 
     * 3.2.2   Function Call
     * Your application program shall call this function like this:
     * TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open( ref TE_USB_FX2_USBDevice, ref USBdevList, CardNumber);
     * 
     * 3.2.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) and counts them. 
     * If no device is attached, TE_USB_FX2_USB_device (CyUSBDevice type) is initialized to null.
     * If one or more devices are attached and
     * 1) if 0 <= CardNumber <= (number of attached devices – 1), then 
     * TE_USB_FX2_USBDevice (CyUSBDevice type) will point to and will be initialized according to the selected device.
     * 2) if CardNumber >= number of attached devices, then 
     * TE_USB_FX2_USBDevice (CyUSBDevice type) is initialized to null.
     * 
     * A more intuitive name for this function would have been TE_USB_FX2_SelectCard().
     * 
     * 3.2.4   Parameters
     * 1. ref CyUSBDevice TE_USB_FX2_USBDevice
     * TE_USB_FX2_USBDevice is the module selected by this function. This is the most useful value returned by this function. This parameter is passed by reference (ref). See pages 70-93 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference).
     * 2. 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. int CardNumber
     * This is the number of the selected Trenz Electronic USB FX2 device.
     * 
     * 3.2.5   Return Value
     * 1. bool : logical type
     * This function returns true if it is able to find the module selected by CardNumber. If unable to do so, it returns false.
     * 
     */ 
    
    /// <summary>
    /// //////
    /// </summary>
    /// <param name="TE_USB_FX2_USBDevice"></param>
    /// <param name="USBdevList"></param>
    /// <param name="CardNumber"></param>
    /// <returns=bool></returns>

    public static bool TE_USB_FX2_Open(ref CyUSBDevice TE_USB_FX2_USBDevice, ref USBDeviceList USBdevList, int CardNumber)
    {

      int CardCounted = 0;   // Trenz Device
      //int DeviceNumber = 0;  // Cypress Device ( number >= TrenzDevice)

      //Number of Cypress Device (Trenz Electronic or not)
      int CypressDeviceNumber = 0;
      //Number of Trenz Device
      int TrenzDeviceNumber = 0;
      //Position of Trenz Device desired in the USBDeviceList
      int DeviceNumber = 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);
      //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)
      {
        foreach (USBDevice USBdev in USBdevList)
        {
          PID = USBdev.ProductID;
          VID = USBdev.VendorID;
          //Number of Cypress Card augmented by one
          CypressDeviceNumber++;
          if ((((PID == 0x0300) && (VID == 0x0bd0)) == true))
          {
            //Number of Trenz Card (a subcategory of Cypress Card) augmented by one
            //CardCount++;
            TrenzDeviceNumber++;
            //Console.WriteLine("PID e VID: {0}, {1}", PID, VID);
            // CardNumber=TrenzDeviceNumber-1 by definition.
            if ((TrenzDeviceNumber - 1) == CardNumber)
            {
              //I store the DeviceNumber that identify the Trenz Card (CardNumber) requested
              //Memorize this number for later use
              //This is the position of Trenz Device desired in the USBDeviceList
              DeviceNumber = CypressDeviceNumber - 1;
              //Console.WriteLine("DeviceNumber: {0}", DeviceNumber);
            }
          }
        }
      }

      //At this point I memorize the Cards Counted and zeroed the variable that I have used in the counting.
      CardCounted = TrenzDeviceNumber;
      //Console.WriteLine("CardCounted: {0}", CardCount);
      TrenzDeviceNumber = 0;

      //Now I search the Trenz USB Device with the Card Number (CardNo) specified
      if (((CardNumber >= 0) && (CardNumber < CardCounted)) == true)  //CardCounted
      {
        USBDevice USBdev = USBdevList[DeviceNumber];
        PID = USBdev.ProductID;
        VID = USBdev.VendorID;
        if ((((PID == 0x0300) && (VID == 0x0bd0)) == true))
        {
          TE_USB_FX2_USBDevice = USBdev as CyUSBDevice;
          //Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
          return true;
        }
        else
        {
          TE_USB_FX2_USBDevice = null;
          return false;
        }
      }
      else
      {
        TE_USB_FX2_USBDevice = null;
        return false;
      }
    }
Exemplo n.º 11
0
        //Function called when the event "Form1 is loading" happens.
        private void Form1_Load(object sender, EventArgs e)
        {
            //"Trick that is used to preserve the default log text that exists at initialization time.
            LogTextLine += "Info, warnings and errors are reported in this log." + "\r\n" + "\r\n" +
                           "This program is a C# evolution of the program Python OpenFut for 3rd Generation Firmware." + "\r\n" + "\r\n";
            // textBox_LogText.Text + "\r\n";

            //This is a group of code written inside two using statements 
            //It checks if a DEWESoft device is already attached when the Form1 
            //(OpenFutNet programm) is loaded.
            //If it is loaded, it inform the user that he/she should detach the TE USB FX2 module
            //and follow a Recovery Procedure
            // TO DO: at this moment, the code doesn't show the message because the Verbose Flag (bVerboseLogText) is false when the progam starts.
            // TO DO: Verbose Flag should be transformed in a varible that can mantains its own status when the program is closed
            using (System.Management.ManagementClass PnPClass = new ManagementClass("Win32_PnPEntity"))
            //Win32_USBController no because DEWESoft device is not seen as a Windows USBdevice (at least if DEWESoft driver is not installed)
            //With  Win32_PnPEntity the DEWESoft device can be found even if DEWESoft driver is not installed
            {             
                using (System.Management.ManagementObjectCollection PnPCollection = PnPClass.GetInstances())               
                {
                    foreach (System.Management.ManagementObject usb in PnPCollection)
                    {

                        string deviceId = usb["deviceid"].ToString();
                        
                        int vidIndex = deviceId.IndexOf("VID_");
                        string startingAtVid = deviceId.Substring(vidIndex + 4); // + 4 to remove "VID_"                    
                        string vid = startingAtVid.Substring(0, 4); // vid is four characters long
                        
                        if (vid.Equals("0547"))
                        {
                            textBox_VID.Text = "0x" + vid;
                            bVID_DEWESoft = true;
                        }

                        /*
                        if (vid.Equals("0BD0"))
                        {
                            textBox_VID.Text = "0x" + vid;
                            bVID_TE_PnP = true;
                        }

                        if (vid.Equals("04B4"))
                        {
                            textBox_VID.Text = "0x" + vid;
                            bVID_Cy_PnP = true;
                        }
                        */
                        int pidIndex = deviceId.IndexOf("PID_");
                        string startingAtPid = deviceId.Substring(pidIndex + 4); // + 4 to remove "PID_"                    
                        string pid = startingAtPid.Substring(0, 4); // pid is four characters long
                        
                        if (pid.Equals("1002"))
                        {
                            textBox_PID.Text = "0x" + pid;
                            //bVID_DEWESoft = true;
                        }                 
                    }                   
                }
            }

            textBox_LogText.Text = LogTextLine;
            LogTextScrollDown();
            textBox_LogText.Update();

            if (bVID_DEWESoft || bPID_DEWESoft)
            {
                DriverType_TextBox.Text = "DEWESoft device";
                FirmwareTypeUSB.Text = "Trenz Electronic Gen2";
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                LogTextLine += "---A DEWESoft device is already inserted when OpenFut starts to run--" + "\r\n";
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                LogTextLine += "INFO: The TE USB FX2 module starts as a DEWESoft Device: this happens when EEPROM switch is set to ON when the TE USB FX2 module is attached to USB port (or more generally when the TE USB FX2 module is powered on with EEPROM switch ON)." + "\r\n";
                LogTextLine += "INFO: The TE USB FX2 module runs the 2nd generation firmware (TE_USB_FX2 Gen 2)" + "\r\n";
                LogTextLine += "WARNING: You can't write a new firmware inside the EEPROM (even if EEPROM switch is set to ON)" + "\r\n";
                LogTextLine += "WARNING: You can't write a new FPGA bitstream inside SPI Flash." + "\r\n";
                LogTextLine += "WARNING: You should start a Recovery Procedure Boot to change the firmware of FX2 microcontroller" + "\r\n";
                LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                FirmwareTypeUSB.Text = "TE_USB_FX2 Gen2";
                DriverType_TextBox.Text = "It couldn't be retieved";
                LatestMajorVersionFW_String = "It couldn't be retieved";
                LatestMinorVersionFW_String = "It couldn't be retieved";
                if (bVerboseLogText == true)
                {
                    LogTextLine += DEWESoftDeviceAttached_String + "\r\n" + "\r\n";
                    MessageBox.Show(DEWESoftDeviceAttached_String);
                }
            }
            textBox_LogText.Text = LogTextLine;
            LogTextScrollDown();
            textBox_LogText.Update();
            /*
            textBox_LogText.SelectionStart = textBox_LogText.Text.Length;
            textBox_LogText.ScrollToCaret();
            textBox_LogText.Refresh();
            */

            //FUNDAMENTAL: without these 3 instructions, it doesn't seems to work  
            //A new USB device list is created
            backgroundWakeEvent.WaitOne(200);          
            USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
            backgroundWakeEvent.WaitOne(200);

            UInt16 PID = 0;
            UInt16 VID = 0;

            //If the number of Cypress/Trenz Electronic device are more than one
            if (USBdevList.Count != 0)
            {
                //Create a single device instance
                CyFX2Device fx2test = USBdevList[0] as CyFX2Device;
                PID = fx2test.ProductID;
                VID = fx2test.VendorID;

                //If more than one Trenz Electronic and/or Cypress Device
                if (USBdevList.Count > 1)
                {
                    MessageBox.Show("In this version the program must be used with a single Trenz Electronic or Cypress module attached. You must remove Cypress and/or Trenz micromodule(s) until only one module remains. This must be the module that you desire to write.");
                }

                //If a single Trenz Electronic Device is attached
                else if ((USBdevList.Count == 1) && (PID == PIDCypress) && (VID == VIDCypress))
                {
                    PID_String = "0x8613";
                    VID_String = "0x04B4";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "---A Cypress device is already inserted when OpenFut start to run--" + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "INFO: The TE USB FX2 module starts as a Cypress Device: this happens when EEPROM switch is set to OFF when the TE USB FX2 module is attached to USB port (or more generally when the TE USB FX2 module is powered on with EEPROM switch OFF)." + "\r\n";
                    LogTextLine += "INFO: Generic Cypress USB Driver used for the recovery of Trenz Electronic Firmware (TE_USB_FX2 Gen3) for FX2 microcontroller" + "\r\n";
                    LogTextLine += "INFO: RECOVERY PROCEDURE: you can write a new firmware inside the EEPROM (if EEPROM switch is set to ON)" + "\r\n";
                    LogTextLine += "INFO: RECOVERY PROCEDURE: you can't write a new FPGA bitstream inside SPI Flash." + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n" + "\r\n";
                    FirmwareTypeUSB.Text = "Cypress used for Recovery Procedure";
                    DriverType_TextBox.Text = "Generic Cypress USB Driver";
                    //MessageBox.Show("The VID and PID used are for normal Cypress device; if you are starting a recovery procedure, it is correct. Otherwise, you should use a power off/on cycle with EEPROM switch to ON to start with VID and PID of a Trenz Electronic device. If the computer does't see the Trenz Electronic device you must install the 'Trenz Electronic USB FX2' driver." );
                    //bEEPROMSwitchSetToOn = true;                     
                    //LogTextLine += "Minor version: " + Reply1[1].ToString() + "\r\n";
                    //LatestMajorVersionFW_textBox.Text = Reply[0].ToString();
                    //LatestMinorVersionFW_textBox.Text = Reply[1].ToString();
                    LatestMajorVersionFW_String = "Recovery Procedure";
                    LatestMinorVersionFW_String = "Recovery Procedure";
                    LogTextScrollDown();

                }
                // if a single Cypress Device is attached
                else if ((USBdevList.Count == 1) && (PID == PIDTrenzElectronic) && (VID == VIDTrenzElectronic))
                {
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "---A Trenz Electronic device is already inserted when OpenFut start to run--" + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    LogTextLine += "INFO: The TE USB FX2 module starts as a Trenz Electronic Device: this happens when EEPROM switch is set to ON when the TE USB FX2 module is attached to USB port (or more generally when the TE USB FX2 module is powered on with EEPROM switch ON)." + "\r\n";
                    LogTextLine += "INFO: Trenz Electronic TE_USB_FX2 driver used for normal work with TE USB FX2 module" + "\r\n";
                    LogTextLine += "INFO: You can write a new firmware inside the EEPROM (if EEPROM switch is set to ON)" + "\r\n";
                    LogTextLine += "INFO: You can write a new FPGA bitstream inside SPI Flash." + "\r\n";
                    LogTextLine += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\r\n";
                    FirmwareTypeUSB.Text = "TE_USB_FX2 Generation 3";
                    DriverType_TextBox.Text = "TE USB FX2 Driver Gen 3";
                    LatestMajorVersionFW_String = "To be retrieved";
                    LatestMinorVersionFW_String = "To be retrieved";
                    LogTextScrollDown();
                }

                //bVID_DEWESoft = false;
                //bPID_DEWESoft = false;

                //A new device list is created: it is moved outside of RefreshInformationUIThread() 
                backgroundWakeEvent.WaitOne(500);
                USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
                backgroundWakeEvent.WaitOne(500);

                //This function refresh the information in the GUI about the SINGLE device attached.
                RefreshInformationUIThread();
                textBox_LogText.Update();
                LogTextScrollDown();
            }

            //Query used to search a PlugAndPlay (PnP) event every 1 second:
            //it is used with OnPnPWMIEvent() callback function to check if a 
            //DEWESoft device has been attached. 
            /**///const string QUERY = @"select * from __InstanceOperationEvent within 1 where TargetInstance isa 'Win32_PnPEntity'";  // and TargetInstance.HardwareID isa 'USB\\VID_0547&PID_1002\\000' "; //and (TargetInstance.DriveType=2)";
            //"Select * from Win32_PnPEntity where Availability = 12 or Availability = 11" has been also considered           
            //Use of the query string QUERY created above
            /**///ManagementEventWatcher watcherDEWESoft = new ManagementEventWatcher(new WqlEventQuery(QUERY));

            //The two lines of code (commented out) (below) are moved at class level because 
            //watcherDEWESoft should be disposed using watcherDEWESoft.Dispose() when Form1 close (OpenFunNet program exit).
            /*Code commented out *///const string QUERY = @"select * from __InstanceOperationEvent within 1 where TargetInstance isa 'Win32_PnPEntity'";  // and TargetInstance.HardwareID isa 'USB\\VID_0547&PID_1002\\000' "; //and (TargetInstance.DriveType=2)";
            /*Code commented out*///ManagementEventWatcher watcherDEWESoft = new ManagementEventWatcher(new WqlEventQuery(QUERY));
            
            //The two lines of code below are used to start the repeating query (every 1 second) and 
            //to capture only DEWESoft PnP event: attachment and removing
            watcherDEWESoft.EventArrived += new EventArrivedEventHandler(OnPnPWMIEvent);
            watcherDEWESoft.Start();


            //SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode <> 0
            //const string QUERY_Unknow_Device = @"SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode <> 0";  // and TargetInstance.HardwareID isa 'USB\\VID_0547&PID_1002\\000' "; //and (TargetInstance.DriveType=2)";
            /*Code commented out*/
            //ManagementEventWatcher watcherDEWESoft = new ManagementEventWatcher(new WqlEventQuery(QUERY_Unknow_Device));
            //watcher_TE_USB_FX2Gen3_or_GenericCypress_NotInstalled.EventArrived += new EventArrivedEventHandler(OnPnPWMIEvent);
            //watcher_TE_USB_FX2Gen3_or_GenericCypress_NotInstalled.Start();

            //App_PnP_Callback evHandler = new App_PnP_Callback(PnP_Event_Handler);

            //Trenz Electronic/Cypress device attached event is elaborated 
            //by callback function USBdevList_DeviceAttached
            //USBdevList.DeviceAttached.Start() is not required
            USBdevList.DeviceAttached += new EventHandler(USBdevList_DeviceAttached);

            //Trenz Electronic/Cypress device removed event is elaborated 
            //by callback function USBdevList_DeviceRemoved
            //USBdevList.DeviceRemoved.Start() is not required
            USBdevList.DeviceRemoved += new EventHandler(USBdevList_DeviceRemoved);

            textBox_LogText.Update();
            //Scroll down Logtext
            LogTextScrollDown();
            RefreshInformationUIThread();
            /* TEST CODE, TO COMMENT OUT unless you need for test purpose
            String regstryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (Microsoft.Win32.RegistryKey keyName = Registry.LocalMachine.OpenSubKey(regstryKey))
            {
                foreach (string subKey in keyName.GetSubKeyNames())
                {
                    using (RegistryKey subKey1 = keyName.OpenSubKey(subKey))
                    {
                        LogTextLine += ((subKey1.GetValue("DisplayName")) );
                        //Response.Write(subKey1.GetValue("DisplayName"));
                        
                        textBox_LogText.Update();
                        LogTextScrollDown();     
                    }
                }
            }
            RefreshInformationUIThread();
            */

        }
Exemplo n.º 12
0
        //This function is called when the form Form1 is closed aka when Program OpenFutNet is closed.
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            //The resources of PnpQuery used to search PnP connection/disconnection of DEWESoft device(s) 
            //are disposed
            //ManagementEventWatcher watcherDEWESoft = new ManagementEventWatcher(new WqlEventQuery(QUERY));
            watcherDEWESoft.Stop();
            watcherDEWESoft.EventArrived -= new EventArrivedEventHandler(OnPnPWMIEvent);
            watcherDEWESoft.Dispose();

            //watcher_TE_USB_FX2Gen3_or_GenericCypress_NotInstalled.Stop();
            //watcher_TE_USB_FX2Gen3_or_GenericCypress_NotInstalled.EventArrived -= new EventArrivedEventHandler(OnPnPWMIEvent);
            //watcher_TE_USB_FX2Gen3_or_GenericCypress_NotInstalled.Dispose();

            //The resource used by Trenz Electronic/Cypress device(s) are disposed
            USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
            if (USBdevList != null)
            {
                USBdevList.DeviceRemoved -= USBdevList_DeviceRemoved;
                USBdevList.DeviceAttached -= USBdevList_DeviceAttached;
                USBdevList.Dispose();
            }

            //The BackGroundWorker BW1_FPGA_SPIFlash used for FPGA and SPI Flash is disposed
            //Maybe is necessary to add -new Events
            BW1_FPGA_SPIFlash.Dispose();

            //The BackGroundWorker  BW2_CypressUSB_I2CEEPROM used for FX2 microcontroller EEPROM is disposed
            //Maybe is necessary to add -new Events
            BW2_CypressUSB_I2CEEPROM.Dispose();         
        }
Exemplo n.º 13
0
 //Refresh Information
 private void button_RefereshInformation_Click(object sender, EventArgs e)
 {
     backgroundWakeEvent.WaitOne(500);
     USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
     backgroundWakeEvent.WaitOne(500);
     bResultLoadEEPROM = false;
     RefreshInformationUIThread();
 }
Exemplo n.º 14
0
        public Form1()
        {
            bVista = (Environment.OSVersion.Version.Major == 6);

            // Required for Windows Form Designer support
            InitializeComponent();

            // Late setup of the CPU monitor - (Bails-out if in Vista)
            InitializePeformanceMonitor();

            // Hide the CPU load monitor if running in Windows Vista
            // Detecting the CPU load is a security violation in Vista
            CPULoadBox.Visible = !bVista;

            // Setup the callback routine for updating the UI
            updateUI = new UpdateUICallback(StatusUpdate);

            // Setup the callback routine for NullReference exception handling
            handleException = new ExceptionCallback(ThreadException);

            // Create the list of USB devices attached to the CyUSB3.sys driver.
            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //Assign event handlers for device attachment and device removal.
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);

            //Set and search the device with VID-PID 04b4-1003 and if found, selects the end point
            SetDevice();
        }
Exemplo n.º 15
0
        /* BW1_FPGA_SPIFlash background worker STOP */

        /* BW2_CypressUSB_I2CEEPROM bacground worker START */

        //Event handler (callback function) for Click of button "Start IIC programming"
        private void button_ProgrUSBStart_Click(object sender, EventArgs e)
        {
            
            UInt16 PID = 0;
            UInt16 VID = 0;

            //Reset of flags
            bFileFpga_Selected = false;
            bFileFpga_PreProcessed = false;
            bFLASH_FPGA_AlreadyWritten = false;

            bMCSXilinxFlash = false;
            bEEPROMSwitchSetToOn = false;

            // Disable the Start button until 
            // the asynchronous operation is done.
            button_ProgFpgaStart.Enabled = false;
            button_ProgFpgaFilePathSelection.Enabled = false;
            button_ProgrUSBStart.Enabled = false;
            button_ProgUSBFilePathSelection.Enabled = false;
            button_RefereshInformation.Enabled = false;
            checkBox_VerboseLogText.Enabled = false;
            checkBox_Retrieve_Flash_ID.Enabled = false;
            checkBox_ClearLogText4everyProgrammingOperation.Enabled = false;

            //If file path is not null, a .iic file is cosidered selected.
            if (USBFile_FilePath.Length > 0)
                bFileUSB_Selected = true;

            //Create a list of Cypress or Trenz Electronic device
            USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //If at least a Cypress or Trenz Electronic device is attached
            if (USBdevList.Count != 0)
            {
                //cast the first device
                CyFX2Device fx2test = USBdevList[0] as CyFX2Device;
                PID = fx2test.ProductID;
                VID = fx2test.VendorID;
                //If more than one Cypress or Trenz Electronic device is used you should remove all device except one
                if (USBdevList.Count > 1)
                {
                    MessageBox.Show("In this version the program must be used with a single Trenz Electronic or Cypress module attached. You must remove Cypress and or Trenz Electronic micromodule(s) until only one module remains. This must be the module that you desire to write.");
                }
                FirmwareTypeUSB_Text = "No Cypress, Trenz Elecrtonic or DEWESoft device, maybe you are using an corrupted Firmware.";
                DriverType_TextBox_Text = "Undefined";
            }

            //If a Cypress device is attached a recovery procedure (boot) should be used
            if ((PID == PIDCypress) && (VID == VIDCypress) && (!bEEPROMSwitchSetToOn))
            {
                FirmwareTypeUSB_Text = "Cypress used for Recovery Procedure";
                DriverType_TextBox_Text = "Cypress USB Generic Driver";
                //MessageBox.Show("The VID and PID used are for normal Cypress device; you must move the EEPROM switch to ON (if the switch is not already ON) and click again the 'Program USB' button");

                PID_String = "0x8613";
                VID_String = "0x04B4";

                //A pop-up appears to remember to the user that EEPROM switch should be
                DialogResult rc = MessageBox.Show("The VID and PID used are for normal Cypress device; this is correct for a recovery procedure. For the current 3 TE USB FX2 modules the EEPROM switch is ENABLED when set to ON. You must move the EEPROM switch to ON (if the switch is not already ON) and click 'YES' button if you desire to continue with the Recovery Procedure", "EEPROM switch/check to ON", MessageBoxButtons.YesNo);
                if (rc == DialogResult.Yes)
                {
                    //Recovery boot is accepted by the user

                    //The Background worker BW2 (used to program the EEPROM with iic firmware file) starts 
                    InitializeAndStartBW2_CypressUSB_I2CEEPROM();

                    //Unlike Digilent Board it is not possible to test if EEPROM switch has been actually set to ON.
                    //This is a "fake" bool flag set to true when user confirms in a MessageBox that 
                    //the EEPROM switch has been set to ON.
                    bEEPROMSwitchSetToOn = true;
                }
                else if (rc == DialogResult.No)
                {
                    //Recovery boot is refused by the user

                    //Unlike Digilent Board it is not possible to test if EEPROM switch has been actually set to ON.
                    //This is a "fake" bool flag set to true when user confirms in a MessageBox that 
                    //the EEPROM switch has been set to ON.
                    bEEPROMSwitchSetToOn = false;
                }
                /*
                if (rc == DialogResult.Cancel)
                {
                    //e.Cancel = true;
                    bEEPROMSwitchSetToOn = false;
                }
                */

                //bEEPROMSwitchSetToOn = true;             
            }

            //If a TE device is attached it is possible to start the Background Worker BW2 to program the EEPROM with selected .iic firmware file
            else if (((PID == PIDTrenzElectronic) && (VID == VIDTrenzElectronic)) || bEEPROMSwitchSetToOn)
            {
                //The Background worker BW2 (used to program the EEPROM with iic firmware file) starts 
                InitializeAndStartBW2_CypressUSB_I2CEEPROM();        
            }
            //If is not a Cypress or TE device
            else
            {       
                MessageBox.Show("Error, wrong VID and PID. Move the EEPROM switch to OFF and use a power on/ power off cycle. After this, you will probably receive another message to move the EEPROM switch. After this, click again the USB Start Program Button and this time should run.");
                FirmwareTypeUSB_Text = "No Cypress, Trenz Elecrtonic or DEWESoft device, maybe you are using an corrupted Firmware.";
                DriverType_TextBox_Text = "Undefined"; 
            }
        }
 static void GetNumberOfCards(ref USBDeviceList USBdevList)
 {
   //cout << endl << TE0300_ScanCards() << endl;
   int NumberOfCardAttached = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_ScanCards(ref USBdevList);
   Console.WriteLine("The number of card is {0} ", NumberOfCardAttached);
 }
    static void Main(string[] args)
    {
      CyUSBDevice TE_USB_FX2_USBDevice = null;
      USBDeviceList USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
      int m_sel = 13;


      while (m_sel != 0)
      {
        DrawMenu();
        //cin >> m_sel;
       string line = Console.ReadLine(); // Read string from console
        int value;
        int.TryParse(line, out value); // Try to parse the string as an integer
        m_sel = value;
        try
        {
          switch (m_sel)
          {
          case 1:
            GetNumberOfCards(ref USBdevList);
            break;
          case 2:
            if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 0) == false)
              Console.WriteLine("Module is not connected!");
            //if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 0) == true)
            else
            {
              Console.WriteLine("Module is connected!");
              Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            }
            //TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_DisplayDriverInformation(ref TE_USB_FX2_USBDevice, ref USBdevList, 0);

            break;
          case 3:
            if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 1) == false)
              Console.WriteLine("Module is not connected!");
            //if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 1) == true)
            else
            {
              Console.WriteLine("Module is connected!");
              Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            }
            //TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_DisplayDriverInformation(ref TE_USB_FX2_USBDevice,ref USBdevList, 1);

            break;
          case 4:
            TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close(ref USBdevList);
            break;
          case 5:
            //Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            GetFX2version(TE_USB_FX2_USBDevice);
            //Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            break;
          case 6:
            //Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            GetFPGAversion(TE_USB_FX2_USBDevice);
            //Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
            break;
          case 7:
            GetFX2FifoStatus(TE_USB_FX2_USBDevice);
            break;
          case 8:
            ResetFX2FifoStatus(TE_USB_FX2_USBDevice);
            break;
          case 9:
            //ReadDataFPGAIntegrity(TE_USB_FX2_USBDevice);

            Console.WriteLine("Write the Buffer Size desired for EP6");
            Console.WriteLine("Value suggested is 102400, do not use 131072");

            string lineBufferSizeR = Console.ReadLine(); // Read string from console
            int BufferSizeR = 131072;
            int.TryParse(lineBufferSizeR, out BufferSizeR); // Try to parse the string as an integer

            Console.WriteLine("BufferSizeR {0} ", BufferSizeR);

            Console.WriteLine("Write the Packets Number desired");
            Console.WriteLine("Value suggested is 1200 if you are testing TE0320 or TE0630");
            Console.WriteLine("Value suggested is  600 if you are testing TE0300");

            string linePacketsNumberR = Console.ReadLine(); // Read string from console
            int PacketsNumberR = 5;
            int.TryParse(linePacketsNumberR, out PacketsNumberR); // Try to parse the string as an integer

            Console.WriteLine("PacketsNumberR {0} ", PacketsNumberR);

            Console.WriteLine("Write the Packet Length desired");
            Console.WriteLine("Value suggested is 102400");
            Console.WriteLine("if you are testing TE0320 or TE0630.");
            Console.WriteLine("Know issue: does not use 131072 or the test fail.");
            Console.WriteLine("Value suggested is  51200 if you are testing TE0300;");
            Console.WriteLine("if the value used is >51200 the test fails.");
            
            Console.WriteLine("In C# you are normally able to read even packet with length less than ");
            Console.WriteLine("512 byte AND it is what you implicitly do with point 5 (FX2 firmware version)");
            Console.WriteLine("6 (FPGA firmware version),7 (FX2 FIFO Status) BUT for this test ");
            Console.WriteLine("you must use 1024 or more for Packet Size value");

            string linePacketLengthR = Console.ReadLine(); // Read string from console
            int PacketLengthR = 51200;
            int.TryParse(linePacketLengthR, out PacketLengthR); // Try to parse the string as an integer

            Console.WriteLine("PacketLengthR {0} ", PacketLengthR);

            Console.WriteLine("Write the Timeout value desired, the integer is measured in milliseconds");
            Console.WriteLine("Value TimeOut (ms) > [PacketLength/DataThroughput ]+1 ms");
            Console.WriteLine("for high responsive computer");
            Console.WriteLine("DataThroughput value expected is >30 Mbyte/s, so with PacketLength=102400 byte,");
            Console.WriteLine("the value is 5-6 ms");
            Console.WriteLine("If the computer is not highly responsive you must set Timeout to large value :");
            Console.WriteLine("20,50,200,1000 ms (it depends on how much the computer lack real time behavior).");

            string lineTimeOutR = Console.ReadLine(); // Read string from console
            uint TimeOutR = 1000;
            uint.TryParse(lineTimeOutR, out TimeOutR); // Try to parse the string as an integer

            //Console.WriteLine("TimeOutR {0} ", TimeOutR);

            ReadDataFPGAIntegrity(TE_USB_FX2_USBDevice,BufferSizeR,PacketsNumberR,PacketLengthR,TimeOutR);

            break;
          case 10:
            //WriteDataFPGAIntegrity(TE_USB_FX2_USBDevice);

            Console.WriteLine("Write the Buffer Size desired for EP8");
            Console.WriteLine("Value suggested is 102400, do not use 131072");

            string lineBufferSizeW = Console.ReadLine(); // Read string from console
            int BufferSizeW = 131072;
            int.TryParse(lineBufferSizeW, out BufferSizeW); // Try to parse the string as an integer

            Console.WriteLine("Write the Packets Number desired");
            Console.WriteLine("Value suggested is 1200 if you are testing TE0320 or TE0630");
            Console.WriteLine("Value suggested is  600 if you are testing TE0300");

            string linePacketsNumberW = Console.ReadLine(); // Read string from console
            int PacketsNumberW = 5;
            int.TryParse(linePacketsNumberW, out PacketsNumberW); // Try to parse the string as an integer

            Console.WriteLine("Write the Packet Length desired");
            Console.WriteLine("Value suggested is 102400");
            Console.WriteLine("Know issue: does not use 131072 or the test fail.");
            Console.WriteLine("Value suggested is  51200 if you are testing TE0300;");
            Console.WriteLine("if the value used is >51200 the test fails.");
            Console.WriteLine("In C# you are able to write even packet with length less than");
            Console.WriteLine("512 byte AND in this case you can also do this BUT");
            Console.WriteLine("in this case you are only able to test write data integrity");
            Console.WriteLine("");

            string linePacketLengthW = Console.ReadLine(); // Read string from console
            int PacketLengthW = 51200;
            int.TryParse(linePacketLengthW, out PacketLengthW); // Try to parse the string as an integer

            Console.WriteLine("Write the Timeout value desired, the integer is measured in milliseconds");
            Console.WriteLine("Value TimeOut (ms) > [PacketLength/DataThroughput ]+1 ms");
            Console.WriteLine("for high responsive computer");
            Console.WriteLine("DataThroughput value expected is >20 Mbyte/s, so with PacketLength=102400 byte,");
            Console.WriteLine("the value is 5-6 ms");
            Console.WriteLine("If the computer is not highly responsive you must set Timeout to large value :");
            Console.WriteLine("20,50,200,1000 ms (it depends on how much the computer lack real time behavior).");

            string lineTimeOutW = Console.ReadLine(); // Read string from console
            uint TimeOutW = 1000;
            uint.TryParse(lineTimeOutW, out TimeOutW); // Try to parse the string as an integer

            Console.WriteLine("You want make an integrity test on data writen on FPGA?");
            Console.WriteLine("1 for YES, 0 for NO");

            string lineGetStatusFPGAyn = Console.ReadLine(); // Read string from console
            uint GetStatusFPGAyn = 1000;
            uint.TryParse(lineGetStatusFPGAyn, out GetStatusFPGAyn); // Try to parse the string as an integer

            WriteDataFPGAIntegrity(TE_USB_FX2_USBDevice, BufferSizeW, PacketsNumberW, PacketLengthW, TimeOutW, GetStatusFPGAyn);

            break;
          }
        }
        catch (System.ObjectDisposedException)
        {
          Console.WriteLine("TE_USB_FX2_USBDevice Disposed: you have used the wrong procedure!");
          m_sel = 1;
        }
      }



      if (TE_USB_FX2_USBDevice != null)
        TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close(ref USBdevList);

      return;
    }
Exemplo n.º 18
0
        /* 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();
        }
Exemplo n.º 19
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;
    }
Exemplo n.º 20
0
 public MyThread(Form1 form, USBDeviceList Usb, FX3_FWDWNLOAD_MEDIA_TYPE enmMediaType)
 {
     fx = Usb;
     Fr = form;
     MediaType = enmMediaType;
 }
Exemplo n.º 21
0
        /**********************************************************************
        * NAME: GenericHIDForm
        *
        * DESCRIPTION: Main function called initalled upon the starting of the
        * application. Used to unitialize variables, the GUI application, register
        * the event handlers, and check for a connected device.
        *
        ***********************************************************************/
        public GenericHidForm()
        {
            //Initialize the main GUI
            InitializeComponent();

            //Set initial values
            DutyCycleUpDown = new NumericUpDown();
            DutyCycleUpDown.Value = 10;
            DutyCycleUpDown.Minimum = 0;
            DutyCycleUpDown.Maximum = 100;

            //Callback to set numeric updown box value
            DutyCycleUpDown.ValueChanged += new EventHandler(DutyCycleUpDown_OnValueChanged);

            // Create a list of CYUSB devices for this application
            usbDevices = new USBDeviceList(CyConst.DEVICES_HID);

            //Add event handlers for device attachment and device removal
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);

            //Connect to the USB device
            GetDevice();
        }