how to get visa BytesAvailable buffering?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
With the old visa function, what is required from the device for matlab to buffer data in the background (e.g. BytesAvailable property)? I have a USB-raw device that i'm attempting to program minimal firmware functionality into to stream data continuously to matlab. currently it sends data, and matlab receives it only when performing fread. it's not buffering in the background.
0 comentarios
Respuestas (1)
Shantanu Dixit
el 27 de Mzo. de 2025
Editada: Shantanu Dixit
el 27 de Mzo. de 2025
Hi George,
If I understood your query correctly, you want MATLAB to buffer data in the background using the 'visa' object so that data is available in 'BytesAvailable' property of the object.
Based on the documentation: https://in.mathworks.com/help/instrument/visa.html, 'visa' object does buffer incoming data, but the 'BytesAvailable' property can be used only when the data is read asynchronously https://in.mathworks.com/help/instrument/visa.html#mw_aaeffe24-c03c-434f-8b87-6b224dd932d3.
You can enable the background buffering by using asynchronous reading, 'ReadAsyncMode'(set to continuous by default) and setting up a callback function ('BytesAvailableFcn'). This function will automatically trigger when a specified number of bytes are available ('BytesAvailableFcnCount') or a terminator is read.
% visaObj: visa object
visaObj.BytesAvailableFcnMode = 'byte';
visaObj.BytesAvailableFcnCount = 64; % set to sufficiently large value (based on data)
visaObj.BytesAvailableFcn = @myCallbackFunction; % callback
function myCallbackFunction(obj, ~)
% logic to read the available data
end
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!