how to get visa BytesAvailable buffering?

9 Ansichten (letzte 30 Tage)
GeorgeLab
GeorgeLab am 27 Feb. 2025
Bearbeitet: Shantanu Dixit am 27 Mär. 2025
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.

Antworten (1)

Shantanu Dixit
Shantanu Dixit am 27 Mär. 2025
Bearbeitet: Shantanu Dixit am 27 Mär. 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!

Tags

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by