You are here

CyUSB.dll in MATLAB: problems at indexing a device_list | Cypress Semiconductor

CyUSB.dll in MATLAB: problems at indexing a device_list

Summary: 10 Replies, Latest post by Sholva on 22 Mar 2015 06:05 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
alealer's picture
14 posts

 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 ( but I don't know if he managed to get it working.

Thank you very much for your help!


alexgerka's picture
4 posts

I have a similar problem. Have you been able to fix your Problem?



Gari's picture
Cypress Employee
21 posts



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 

If possible add the Matlab project here?




Gari's picture
Cypress Employee
21 posts

 I meant link to Cyusb.dll.


locsong's picture
2 posts


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:


  CyUSBdll = NET.addAssembly('C:\......\CyUSB.dll');
catch error
        disp('CyUSB.dll already loaded');

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

FirstProj's picture
8 posts

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

zy26's picture
3 posts

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


VAVC's picture
Cypress Employee
506 posts



We haven't tested CYUSB in matlab.


For importing any dll into matlab please refer the link




ilw's picture
1 post


 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



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






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

JoBlack's picture
1 post

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.

Sholva's picture
1 post

 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 Under UsbSuite driver....


Log in to post new comments.