9 Replies Latest reply on Oct 1, 2013 2:09 PM by raphael.mall

    CyUSB.dll in MATLAB: problems at indexing a device_list

    alessandro.angelino

       Hi everybody, and thank you again for your help.

         

      I managed loading the .NET CyUSB.dll library in MATLAB with the command NET.addAssembly.

         

      Then, I also managed creating a list of devices, with:

         

      devList = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);

         

      which is something like a MATLAB transposition of the C# code provided in the reference guide for the .dll.

         

      The output demonstrates that a device has been found ( devList.Count outputs '1'), but I cannot access the first element of the list.

         

      devList(0) is simply not allowed, and MATLAB itself suggests using an "Item" method. So if I use:

         

      devList.Item(0) MATLAB crashes.

         

      I'm pretty sure that this should be the procedure: devList.Item(1), for example, outputs an error saying that I went out of range. devList(1204, 4100), makes MATLAB crash again (note: those numbers are the decimal value of VID and PID of the connected device), while devList(whatever other couple of numbers) just outputs an empty string.

         

      I didn't manage getting an error log from MATLAB.

         

      Is there anything wrong with my approach? Is there a way to solve this issue? Somebody, a few time ago, posted a problem quite similar to mine, here in this forum (http://www.cypress.com/?app=forum&id=167&rID=48607) but I don't know if he managed to get it working.

         

      Thank you very much for your help!

         

      Alessandro

        • 1. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
          alex.gerka
                  Hi. I have a similar problem. Have you been able to fix your Problem? Regards, Alex   
          • 2. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
            garima.gupta

            Hi Alermto,

               

             

               

            I remember seeing the same problem. But I do remember that something inexplicable happened and it started to work. 

               

            I assumed it was some library linking magic (that is still inexplicable).

               

            I know this is ambiguous and might not help much, nor am I a MATLAB expert. Can you try placing the .NET function in the Control Panel and link it to CyUSB.net? 

               

            If possible add the Matlab project here?

               

             

               

            Regards,

               

            Garima

            • 3. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
              garima.gupta

               I meant link to Cyusb.dll.

                 

              -Garima

              • 4. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                aobo.song

                 Hi!

                   

                Has anyone figured this out yet? I am currently stuck at the same step. I put CyUSB.dll in the same directory as my matlab .m file:

                   

                 

                   

                try 
                  CyUSBdll = NET.addAssembly('C:\......\CyUSB.dll');
                catch error
                     error.message
                     if(isa(error,'NET.NetException')) 
                        e.ExceptionObject
                     else
                        disp('CyUSB.dll already loaded');
                     return;
                     end
                end

                   

                % Create a list of USB devices
                usbDevices = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);

                   

                % USB Device Count
                num_usbDevices = usbDevices.Count;  % <=== returned 1 when the device is plugged in, 0 when it's not. 

                   

                usbDevice = usbDevices.Item(0)      % <===== matlab crashes here.

                • 5. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                  raphael.mall

                  did you manage to figure it out ? I need to develop a similar application

                  • 6. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                    zi.yang

                     Does anyone here has idea about how to interface Matlab to cyusb driver? I am working on building communication between Matlab and CY7C68013, but haven't got any good idea...

                       

                    Thanks.

                    • 7. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                      vavc

                       Hi,

                         

                       

                         

                      We haven't tested CYUSB in matlab.

                         

                       

                         

                      For importing any dll into matlab please refer the link http://www.mathworks.in/help/matlab/ref/loadlibrary.html

                         

                       

                         

                      Regards,

                         

                      Vikas.

                      • 8. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                        ian.w

                         cyusb_lib = NET.addAssembly('d:\Matlab\FX3\CyUSB.dll')   %Load the dll from wherever it is on your computer

                           

                            

                         

                           

                            

                                  

                           

                        devList = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);    % Fill a USBdeviceList object with all the details of the devices using the cypress driver    

                         

                           

                            

                                  

                           

                        %you probably need to create callback functions for usb events (I called mine FX3_attach and FX3_detach). I haven’t made them useful yet but mine just looked like    

                         

                           

                         

                           

                        function ret = FX3_detach(sender, args )     

                         

                           

                        'detach callback called'      

                         

                           

                        args.FriendlyName  % prints the name of the device that was detached     

                         

                           

                        end     

                         

                           

                         

                           

                        then you can attach the listener using:    

                         

                           

                        hAttached = addlistener(devList,'DeviceAttached', @FX3_attach);              

                         

                           

                        hDetached = addlistener(devList,'DeviceRemoved', @FX3_detach);    

                         

                           

                            

                                  

                           

                        % You can test the callbacks by pressing the reconnect button on the Cypress Control Centre    

                         

                           

                            

                                  

                           

                        %loop through all the devices to find the one you want    

                         

                           

                        for i=0: (devList.Count -1)    

                         

                           

                        if ( devList.Item(i).FriendlyName == ‘Cypress FX3 USB BootLoader Device’);    % or whatever you set the name to, could alternatively check Item(i).ProductID == 243    

                         

                           

                                        myDev = handle(devList.Item(i));    

                         

                           

                        break;    

                         

                           

                        end    

                         

                           

                        end    

                         

                           

                            

                                  

                           

                            

                                  

                           

                        myEndpts = handle(myDev.Endpoints);  % seems to be much easier if you create a handle to the endpoints as only the first of each type is automatically listed. while with a handle you can select any of them    

                         

                           

                        myEndpts.Length   %tells you how many you have    

                         

                           

                            

                                  

                           

                        % myEndpts(1) should be the control endpoint    

                         

                           

                            

                                  

                           

                        %for my code endpoints 3 and 4 are setup as bulk out and bulk in. they are also set to loopback data. So to send in data    

                         

                           

                            

                                  

                           

                        myEndpts(3).XferData(data, length(data));    

                         

                           

                            

                                  

                           

                        %to receive data you need to set up a byte array first    

                         

                           

                            

                                  

                           

                        rxBuffer = NET.createArray('System.Byte',  length(data));    % fine as long as the length of the buffer is >=  length of data returned    

                         

                           

                            

                                  

                           

                        myEndpts (4).XferData(rxBuffer,length(data))    

                        • 9. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                          pozdniakov.dimitry

                          Hello Everybody
                          I have problem,
                          Why when I write in matlab devList.Item(0), matlab works no longer?

                             

                          Without this feature you can not continue to work.

                             

                          Does anyone have a solution for this?

                             

                          I thank you in advance.

                          • 10. Re: CyUSB.dll in MATLAB: problems at indexing a device_list
                            petr.ourednik

                             Thank you very much ilw.

                               

                             

                               

                            JoBlack you have to download new CyUSB.dll. It is the one for FX3 (FX2LP is suported). It can be found here http://www.cypress.com/?rID=57990. Under UsbSuite driver....