Instrument control toolbox - acquiring data from two sources
1 回表示 (過去 30 日間)
古いコメントを表示
I am using the Matlab Instrument Control Toolbox for data acquisition. In fact I am using the exact script detailed on this page:
https://www.mathworks.com/examples/instrument/mw/instrument_oceanoptics_product-demo_OceanOptics-fetch-spectrum-through-ocean-optics-spectrometer-using-matlab-instrument-driver
where a spectrometer is being set up and then data is being acquired. While running this script, I also wish to obtain data from a serial COM3 port that is connected a different laptop and sending data via the serial port. I have created a callback function to do this.
*This part is in the main script*
appenderFile=fopen('Event_Markers.txt','a+t');
s=serial('COM3');
set(s,'BytesAvailable',{@myCallback,appenderFile});
set(s,'BytesAvailableFcnCount',1);
set(s,'BytesAvailableFcnMode','byte');
fopen(s);
*This is the callback function*
function myCallback(s,~,appenderFile)
bytes=(s,'BytesAvailable')
if(bytes==1)
[data count msg] = fread(s,bytes);
end
fprintf(appenderFile,'%d \n',data);
bytes=(s,'BytesAvailable');
while bytes==0
fprintf(appenderFile,'%d \n',data);
bytes=get(s,'BytesAvailable');
if bytes~=0
break
end
end
end
However I have noticed that incorporating this into the main script (in the link) that is acquiring the data, really slows down the acquisition by ~10-12s. I am unsure why this is.
Does anybody know what is the ideal way of doing this? To have the port being scanned constantly and to have data being acquired continuously as well?
Thanks
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!