CyUSB.dll in MATLAB: problems at indexing a device_list

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 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

12 Replies
Anonymous
Not applicable
        Hi. I have a similar problem. Have you been able to fix your Problem? Regards, Alex   
0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

 I meant link to Cyusb.dll.

   

-Garima

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

 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))    

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

 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....

Anonymous
Not applicable

Hi, I have the same problem (devList.Item(0)) in Matlab and download latest version of CyUSB.dll under Cypress Suite USB 3.4.7 . The result is same. Also i see the c# sample code in CyUSB.NET.pdf. It uses an access method using VID/PID. I can't find this method in Matlab. It mat Prevent crashing. Do you have any idea? Are you tested CyUSB.dll in Matlab?
Thanks.

0 Likes
Anonymous
Not applicable

I had the same problem trying to talk to a Terasic DE2-115 board. I can confirm that using the CyUSB.dll from the latest version of the EZ-USB FX3 SDK fixes the problem. Thank you!

0 Likes