4 Replies Latest reply on Jun 15, 2017 7:02 AM by anii

    getting all packets when using CyUSB.net

    drahmlow_2010456

      Hi-

         

        I'm new to using the Cypress chips (FX2), and I'm looking for some pointers on getting started with CyUSB.net ...

         

        I have the FX2LP set up in FIFO mode, bulk endpoint (IN) on EP6, which is connected to an FPGA that generates packets to send.  This is based on the AN61345 slave FIFO app note, but modified so it puts a data packet in the FIFO every 0.5 ms.  I can read this data using the Streamer C# application (AN4053), or the Control Center.  I can make a simple C# program of my own that reads packets, based on these examples.

         

         To this point, I've usually used RS232 (or CDC device class), for which the process typically is:

         

      1. open a handle to the port (CreateHandle)

         

      2. this causes the operating system to buffer data until read by the application; also, it grants exclusive access

         

      3. read data

         

      4. close the port when done

         

      5. if the operating system's buffer overflowed, an error flag is set that the program can see

         

         Using CyUSB.net...

         

      1. Is there an equivalent of "opening the endpoint"?  I don't see an equivalent way to signal to CyUSB, "hey, direct all incoming packets to my application!"

         

      2. How do I guarantee that I get all packets in order, with none lost?

         

      3. How do I guarantee exclusive access for my program?

         

      For example, I can run 2 instances of the Streamer example side-by-side, and neither knows that it is losing half the data to the other program!

         

       

         

      Thanks!

        • 1. Re: getting all packets when using CyUSB.net
          anii

          Hi,

             

          You need not open the com port as it can be done in c# as follows:

             

          USBDeviceList usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
          CyUSBDevice MyDevice = usbDevices[0x04B4,0x1003] as CyUSBDevice;
          if (MyDevice != null)
          if (MyDevice.BulkOutEndPt != null)
          {
          int len = 512;
          byte [] buf = new byte[len];
          MyDevice.BulkOutEndPt.XferData(ref buf, ref len);
          }
          Please go through the section 4.13.7 in the attached CyUSB.NET.pdf for more details.

             

          Please look into the source files at the following location after installing 'CY3684 EZ-USB FX2LP DVK Setup'.

             

          C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Windows Applications\Application Source files

             

           

             

          Regards,

             

          Anil

          • 2. Re: getting all packets when using CyUSB.net
            drahmlow_2010456

            Hi Anil-

               

               Thanks; that's the call I've been using.

               

               What I'm confused by is that this call does not seem to say anything about how data is buffered by the system.  My device sends data at a regular rate (1 packet every 0.5 ms).  If I do something like:

               

            MyDevice.BulkOutEndPt.XferData(ref buf, ref len);

               

            Sleep(1 second);

               

            MyDevice.BulkOutEndPt.XferData(ref buf, ref len);

               

            Am I guaranteed not to lose data?  What happens to the 2000 packets that were sent during the 1 second delay?

            • 3. Re: getting all packets when using CyUSB.net
              drahmlow_2010456

              Hi Anil-

                 

                 I had a chance to do a bit more investigation.

                 

                 My device generates data to send every 0.5 ms (an ADC set to sample at 2000 sps), and each bulk transfer packet [high speed] contains a unique sequence number.  So, I can tell if a packet is lost.

                 

                 With the XferData() call as outlined above, I find that I miss about 20% of the packets.  It seems to be somewhat Windows-dependent; for some computers, it may be only 10% of the packets that go missing.

                 

                 If I run my ADC more slowly (300 sps), then it is less likely to lose a packet - but it still happens.  I typically lose about 1 out of 10,000 packets.

                 

                 How do I make sure that the incoming data is properly buffered, and not lost?

                 

                 Thanks!

              • 4. Re: getting all packets when using CyUSB.net
                anii

                Hi,

                   

                XferData() is a synchronous data transfer. If the data is available continuously then the asynchronous data transfer is a better option. You can refer to the "BeginDataXfer(), WaitForXfer(), FinishDataXfer" in the CyUSB.Net.pdf that is shared previously. Also, you can refer to streamer source code available in 

                   

                C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Windows Applications\Application Source files\c_sharp\streamer

                   

                where asynchronous transfer is implemented.

                   

                Regards,

                   

                Anil