10 Replies Latest reply on Nov 17, 2016 7:00 AM by sitesv_1495066

    Host FX3 C++ API : multiple devices management

    yoan.marin
              Hello, I have read the "Cypress CyAPI Programmer's reference", and I still wonder how to manage multiple devices concurrently (in separate threads) in the running host application. The problem is that the CCyUSBDevice object is used to enumerate devices, but is also the only instance on which you can call Open(). Let's say that CCyUSBDevice reports me 2 devices (let's say 0 and 1). Is it allowed to clone the CCyUSBDevice instance in two threads A and B and call ->Open(0) in thread 1 and ->Open(1) in thread B ? I was expecting Open() to return an kind of "entry point" to a device instance, rather than modifying the internal state of the object used for enumeration ! How is it to be used ? Regards   
        • 1. Re: Host FX3 C++ API : multiple devices management
          anand.srinivasan.asokan

           Calling Open() gives you a handle to the device. You'll have handle to that irrespective of disconnect/connect of other devices to the bus. So I'm not sure what you mean when you say change the internal state. Please elaborate.

             

          Thanks,

             

          Anand

          • 2. Re: Host FX3 C++ API : multiple devices management
            yoan.marin
                    Hello, I mean, let's say I have my instance "d" of CCyUSBDevice. if I call successively d->Open(0); d->Open(1); According to the doc, I think the connexion to 0 is lost, and that I cannot communicate with 0 and 1 at the same time. "When Open( ) is called, it first checks to see if the CCyUSBDevice object is already opened to one of the attached devices. If so, it calls Close( ), then proceed" When you say "Open() gives you a handle to the device", it's rather "Open(0) configures d to be internally linked to 0, so its internal state has a handle to 0. Thus, it cannot represent a connexion to 1 at the same time" My goal is to enumerate the devices, create one thread per device, and establish a connexion within each thread to make parallel I/Os.   
            • 3. Re: Host FX3 C++ API : multiple devices management
              anand.srinivasan.asokan

              Hi,

                 

              The API uses HANDLE in DeviceIOControl to get talk to the device. That handle is mapped to the device and is not going to change (from the OS side) irrespective of how many devices you connect/disconnect. 

                 

              If device 0 is disconnected and then you call Open(0) it would get you the handle of what used to be device 1 but this won't happen given that you've the disconnect notification to handle this scenario properly.

                 

              You can use streamer/control center or any of our example host application to test your scenario. Please test it and let me know if you still have concerns.

                 

              Thanks,

                 

              Anand

              • 4. Re: Host FX3 C++ API : multiple devices management
                yoan.marin

                 I am not sure that we are talking about the same thing.

                   

                Here is some pseudo-code to explain my scenario.

                   

                The problem is that each time the devices are enumerated, the HANDLE values DO change. Since each Open() performs a Close() before, the HANDLE is not a reliable and persitent pointer to "represent" the device and perform background communications with it.

                   

                For instance, I have 2 devices connected. The first time "refreshDevices" is called, the handles are 0x2D0 and 0x2F4, and the next time it becomes 0x2FC abd 0x2F8. So, 0x2D0 and 0x2F4 became invalid. What I am supposed to do ?

                   

                 

                   
                CCyUSBDevice* fx3DeviceManager = new CCyUSBDevice(some handle);   void Wndproc(...)//Called on PNP event (device arrival/removal) {   refreshDevices(); }  void refreshDevices(void) {   for(int deviceIndex = 0 ; deviceIndex < fx3DeviceManager->DeviceCount() ; ++deviceIndex)   {     fx3DeviceManager->Open(deviceIndex);     HANDLE deviceHandle = fx3DeviceManager->DeviceHandle();     if (deviceHandle not already used in my background threads)       createSomeBackgroundThreadToCommunicateWith(deviceHandle);   }   for(each thread using a handle that does not exists any more)    closeThatThread(); }
                • 5. Re: Host FX3 C++ API : multiple devices management
                  anand.srinivasan.asokan

                  That is strange. I apologize for the confusion. My bad. I understand the point you're making. 

                     

                  Our host application is also handling it the same way. Please create a tech support case with the details as this needs a proper investigation and discussion.

                     

                   

                     

                  Note: Having a way to distinguish between the devices like difference in PID or serial number etc is a way to workaround this.

                  • 6. Re: Host FX3 C++ API : multiple devices management
                    yoan.marin

                     How do I create a tech  case for such a "pure software" problem ? The online tech case submission seems related to schematic boards only

                    • 7. Re: Host FX3 C++ API : multiple devices management
                      anand.srinivasan.asokan

                       Our tech support is not just for schematic review. You can create a case using "Create a MyCase" in http://www.cypress.com/?id=4 .You will find "CY software tools" in Inquiry type you can use that to file tech support case for software issues. You can see the various other categories as well.

                      • 8. Re: Host FX3 C++ API : multiple devices management
                        yoan.marin

                        Test case open.

                           

                        Thanks a lot.

                        • 9. Re: Host FX3 C++ API : multiple devices management
                          viktor.khachtchanski

                          Hi,

                             

                          I have a similar question - is there a safe way to enumerate devices when some of them are in use? Calling CCyUSBDevice::Open() interrupts data transfer in active instances of CCyUSBDevice object.

                             

                          Thank you

                          • 10. Re: Host FX3 C++ API : multiple devices management
                            sitesv_1495066

                            Hello!

                               

                            I have the same Q.

                               

                            How to work with multiple devices simultaneously? How to use HANDLE?

                               

                            c++