Reading data from an FX2LP into matlab

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

cross mob
vishwasd19
Level 1
Level 1
10 replies posted 10 sign-ins 5 replies posted

Hello,

I have USB-based EEG hardware, with an FX2LP controller. I am trying to read the data into MATLAB using the following code. 

Note: there are only two endpoints one control and one interrupt

CODE 1: for interrupt endpoint

try
 
    CyUSBdll = NET.addAssembly('C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\bin\CyUSB.dll');

   
catch error
   error.message
   if(isa(error,'NET.NetException'))
       e.ExceptionObject
   else
       disp('CyUSB.dll already loaded');
       return;
   end
end
%%USB Device Select
% Create a list of USB devices
usbDevices = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);
device=usbDevices.Item(0);


%For Interrupt  Endpoint

len=1024;

   
buf = zeros(1,len,'uint8');

a=device.InterruptInEndPt.XferData(buf,len)

OUTPUT:

a=1

  • But the Buf has all zeros, I don't know where the data is, if the transfer is successful where will the data be?

CODE 2: for control endpoint

try
 
    CyUSBdll = NET.addAssembly('C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\bin\CyUSB.dll');

   
catch error
   error.message
   if(isa(error,'NET.NetException'))
       e.ExceptionObject
   else
       disp('CyUSB.dll already loaded');
       return;
   end
end
%%USB Device Select
% Create a list of USB devices
usbDevices = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);
device=usbDevices.Item(0);
CEP=device.ControlEndPt;

CEP.Target=CyUSB.CyConst.TGT_DEVICE;
 CEP.ReqType=CyUSB.CyConst.REQ_VENDOR;  
  CEP.Direction=CyUSB.CyConst.DIR_FROM_DEVICE;  
  CEP.ReqCode=0xB0;  
  CEP.Value=0;
  CEP.Index=0;
  len=64;

   
buf = zeros(1,len,'uint8');

  CEP.XferData( buf, len );
  RESULT:

  • Execution doesn't end, the program keeps on running I do not know if data is coming or it is stuck, I had to use task manager to close the MatLab because even Ctrl+C was not able to stop execution.

I also think that it might be that the byte type used in .net/C# to make the buffer is not working here and hence CODE1 and 2 both are not working. I do not know what to do after this.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Did you import the .dll into MATLAB? 

Please also check the CyUSB.NET document attached along with my response.

Apologies but we do not have any example of using FX2LP in MATLAB.

Regards,

Mallika

 

View solution in original post

0 Likes
8 Replies
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

May I know what interface are you using? Are you implementing serial communication?

Regards,

Mallika

0 Likes

@MallikaK_22 wrote:

Hi,

May I know what interface are you using? Are you implementing serial communication?

Regards,

Mallika


Hi mallika, 

I am simply connecting the the usb to the CPU and running the above code on matlab. Nothing else, hope that answers your question. 

Regards

Vishwas

0 Likes
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Please let me know which version of .NET framework and Cyusb.dll are you using? Did you face any issue while compiling the two?

Regards,

Mallika

 

0 Likes

Hey,

I downloaded the latest Cyusb.dll i.e, 1.3, and the .net framework was asked to be installed during the installation of 1.3, so I am assuming it is the latest one. There were no issues while compiling the two.

0 Likes
lock attach
Attachments are accessible only for community members.
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Did you import the .dll into MATLAB? 

Please also check the CyUSB.NET document attached along with my response.

Apologies but we do not have any example of using FX2LP in MATLAB.

Regards,

Mallika

 

0 Likes

Hi Malika,

Yes, I got the CyUSB.dll into MATLAB, problem is that the transfer status is 1 but the data is not in the buffer.

0 Likes
FranCruzarianic
Level 1
Level 1
10 sign-ins 5 questions asked 5 sign-ins
try
 
CyUSBdll = NET.addAssembly('C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\bin\CyUSB.dll');
 
 
catch error
error.message
if(isa(error,'NET.NetException'))
e.ExceptionObject
else
disp('CyUSB.dll already loaded');
return;
end
end
%%USB Device Select
% Create a list of USB devices
usbDevices = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);
device=usbDevices. Item(0);
 
 
%For Interrupt omeglz Endpoint
len=1024;
 
 
buf = zeros(1,len,'uint8');
a=device.InterruptInEndPt.XferData(buf,len)
OUTPUT: omegle.2yu.co
a=1
0 Likes

Hi

This is my code yes, do you have any idea how can I get the data?

0 Likes