UDP connection between MATLAB and MUSE isn't working ( Warning: Unsuccessful read: The specified amount of data was not returned within the timeout period.)

3 views (last 30 days)
Hello, i am trying to establish a UDP/IP connection to a MUSE headband. I have already succeeded to make a TCP/IP connection, but I couldn't receive all the data i wanted (it seems that it could record only a small part of the data).
when i'm trying to make a UDP connection, i receive the following warning: Unsuccessful read: The specified amount of data was not returned within the timeout period.
the code is as follow: (irrelevant parts of the code are marked as ...)
if true
function muse_recorder_new1(file_name, duration, port, preset)
...
tcpFlag = tbFlag && releaseYear > 2011;
...
if tcpFlag
udpserver = udp(ip,port,'timeout',30);
udpserver.InputBufferSize = 5000;
fopen(udpserver);
while true
if tcpFlag
try %Catch Matlab error
%a = fread(tcpServer, 4); %How large is the package (# bytes)-- this is the line we used in TCP connection
a = fread(udpserver, 4); %-- this is the line we try to use in UDP connection
fprintf('\n a= %s \n',a); % in TCP when we recieved data it printed whih kind of data was recievd (eeg/acc). in UDP we didnt receive anything at all.
catch err;
fprintf('\n error tcp \n');
break
end
bytesToRead = double(swapbytes(typecast(uint8(a),'int32')));
try %Catch Matlab error
bytesData = fread(tcpServer,bytesToRead);
% bytesData = udpserver();
catch err;
break
end
if tcpFlag
fclose(udpserver);
delete(udpserver);
% fclose(tcpServer);
% delete(tcpServer);
else
serverSocket.close();
serverSSocket.close();
end
display('End of Acquisition')
end
thank you for helping,
Gal

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!