Looking for an alternative for matlab's fread() - multiple computer communication
5 次查看(过去 30 天)
显示 更早的评论
I have a system of 2 computer that run seperate matlab session. In principle, I want to send a 'trigger' (6 byte double packet) to one computer just after the other computer finishes to run some code. I wish to get the trigger in fine time resolution (<100ms) and to be able to measure the latency if needed. Up to know, I used UDP communication with the following scheme:
computer 1 - ipA:
% sending the trigger
data = clock;
fwrite(ipB,data,'double');
meanwhile, the other computer scans for an non-empty packet:
computer 2 - ipB:
% create timer object for triggering
trigger = InitializeMyTimer(ipA);
triggertime= trigger.UserData;
when the timer has the following structure:
function [ triggObj ] = InitializeMyTimer(ipData)
% InitializeMyTimer() is a function to manage the reception of the a
% trigger from computer ipA
triggObj = timer;
triggObj.Period = 0.01; % 1 ms time between executions of the TimerFcn
triggObj.ExecutionMode = 'fixedRate';
triggObj.TimerFcn = @mytimer_cb;
triggObj.BusyMode = 'drop';
triggObj.TasksToExecute = 1e3; % this determines the timeout of the run in this gui
triggObj.UserData = ipData;
start(triggObj);
wait(triggObj);
end
function mytimer_cb(obj, event)
% timerFunc stops running when we recieve a packet of data
clocktime= fread(obj.Userdata ,6,'double');
if ~isempty(clocktime)
obj.Userdata = clocktime;
stop(obj);
end;
end
'fread' seems to be the bottleneck of this function since it takes at least 1 sec to run
clocktime= fread(obj.Userdata ,6,'double');
Further, I don't really found a good way to measure the send/receive latency. I though about several directions -
(1) send an analogoutput to a NI board connect to the ipB and read it from MATLAB
(2) try somehow to run multiple executions of 'fread' simultaneously.
(3) use serial communication between computer with a RS232 null mode cable and to read the trigger this way.
What should be the most promising technique? What do you guys suggest as an alternative?
Thanks, Noam
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Acquisition Toolbox Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!