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

조회 수: 2 (최근 30일)
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
Walter Roberson
Walter Roberson 2022년 3월 23일
편집: Walter Roberson 2022년 3월 23일
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 2022년 3월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rafael Costa
Rafael Costa 2022년 5월 4일
편집: Rafael Costa 2022년 5월 4일
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;
  댓글 수: 1
edeson
edeson 2023년 8월 1일
how to use the asynchronous IO function such as BeginDataXfer/FinishDataXfer( ) /WaitForXfer function

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by