Trying to read EEG data from hardware using cypress .NET library that handles the CyUSB.

2 visualizaciones (últimos 30 días)
Hello,
I am using an electroencephalogram (EEG) that uses a CyUSB.sys driver. I am looking to get the incoming EEG data into MATLAB. The code is under the following. I have used Cypress CyUSB .NET DLL Programmer's Reference to write the code ( http://www.cypress.com/?docID=45233 ). Everyting works untill last line, Buf is a byte type I thought using a 'uint' should do the job. I do not know how to convert C# code in the programmers reference to MATLAB code.
CODE:
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=uint(len);
CEP.XferData(ref buf, ref len);
Error:
Last line is giving me this error
  5 comentarios
Walter Roberson
Walter Roberson el 23 de Mzo. de 2022
Editada: Walter Roberson el 23 de Mzo. de 2022
MATLAB has no function named uint so I do not know what your code might be doing.
indicates a file that includes the C++ api. It would be more robust to use that, as MATLAB can call that relatively directly; see https://www.mathworks.com/help/matlab/call-cpp-library-functions.html
vishwas dalal
vishwas dalal el 23 de Mzo. de 2022
Hi Walter,
My bad, the code that is working is the one you told, which is:
-len=64;
-buf = zeros(1, len, 'uint8');
-CEP.XferData( buf, len);
But it just doesnot stop, thanks for the input.

Iniciar sesión para comentar.

Respuestas (1)

Rafael Costa
Rafael Costa el 4 de Mayo de 2022
Editada: Rafael Costa el 4 de Mayo de 2022
Hello, I come here to give my contribution on the CyUSB.dll library linking problem in MATLAB, first of all, make sure that the CyUSB.dll class library is the latest 1.2.3.0(EZ-USB FX3 SDK), install the latest drivers for the proper functioning of the device. Read carefully the Cypress CyUSB .NET DLL programmer's reference manual, in the C# language, the 'as' operator is used for casting objects in another class, in Matlab it is somehow done automatically I think.
Use methodsview() to see what a method signature looks like for each class you want to use: methodsview(device), methodsview(outEndpoint), etc.
Try to run according to the code below, on my data acquisition device which contains the chip cy7c68013a-56pvxc it worked correctly, my device is a high-speed USB 2.0 device and transmits packets in bulk transfers (512 bytes). You can change the size of packets on each endpoint using method in a class, do it correctly and carefully.
asm = NET.addAssembly('C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\bin\CyUSB.dll');
usbDevices = CyUSB.USBDeviceList(CyUSB.CyConst.DEVICES_CYUSB);
device=usbDevices.Item(1204,241); %% VID & PID (0x04b4, 0x00F1)
outEndpoint = device.EndPointOf(2); % 0x02
inEndpoint = device.EndPointOf(134); %% 0x86
%% device %% to see the properties of the class
%% methodsview(device) %% to see the methods and methods signatures
outEndpoint.TimeOut = 1000;
inEndpoint.TimeOut = 1000;
%% methodsview(inEndpoint) %% to see the methods and methods signatures
XFERSIZE = 512;
len = 512;
buf = zeros(1, XFERSIZE,'uint8');
ct_loop = 9; %% amounts of readings that will be performed on the device
ct_bgn = 1;
ct_end = len;
inData_cast = zeros(1,len);
data_out = zeros(1, ct_loop*len);
inData_raw{ct_loop} = 0;
for i = 1:ct_loop
[~,inData_raw{i},~] = inEndpoint.XferData(buf, len); %% device to host
end
for i = 1:ct_loop
inData_cast = cast(inData_raw{i}, 'uint8');
data_out(ct_bgn : ct_end) = inData_cast;
ct_bgn = ct_end + 1;
ct_end = ct_end + len;
end
plot(data_out); %% it is only to see the raw data concatenated, it is necessary a long treatment or processing of the obtained data
device.Dispose();
clear all;

Categorías

Más información sobre MATLAB Compiler SDK en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by