visadev - how to know bytes available

15 ビュー (過去 30 日間)
covfefe
covfefe 2025 年 8 月 29 日
編集済み: Andrei 2025 年 10 月 16 日 18:22
Hello,
I have existing code that has been working great on 2016-2023 Matlabs:
Instrument = visa('ni', 'GPIB0::18::INSTR');
fprintf(Instrument, ['MMEMory:STORe:SCReen ', DeviceFile]);
fprintf(Instrument, ['MMEMory:DATA? ', DeviceFile]);
[DataRead, count] = fread(Instrument.HANDLE);
When I updated to the latest Matlab, the fread now takes extremely long (times out), giving the following warning:
transportlib:client:ReadWarning
Warning: The specified amount of data was not returned within the Timeout period for 'read'.
'visadev' unable to read any data. For more information on possible reasons, see visadev Read Warnings.
It seems fread now wants a 2nd argument, specifying the number of Bytes to read. But this does not seem posible to get:
  • The instrument (Agilent E4443A) does not have a command to provide the size of the file
  • Instrument.NumBytesAvailable has been depreacted
What is the best way to read an unknown Byte amount with visadev (similar to previous gpib/visa implementations):
  • Can I read until a terminator?
  • Can I check the number of Bytes available on the buffer?
thank you
  1 件のコメント
Torsten
Torsten 2025 年 8 月 29 日

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2025 年 8 月 30 日
You can configureTerminator followed by readline
If your data is binary then you could uint8(char()) the readline() string result and then typecast to the actual datatype.
If your data is binary then you could potentially write it in "binblock" format and use readbinblock
There does not appear to be any supported way to determine the size of the input queue. (I do not have any hardware that supports VISA so I cannot test for unsupported ways.)
  1 件のコメント
covfefe
covfefe 2025 年 8 月 30 日
I just tried all 3 possible values for the Terminator, without luck:
K>> configureTerminator(Instrument.HANDLE,"CR")
K>> GPIBwrite(Instrument, ['MMEMory:DATA? ', DeviceFile]); [DataRead, count] = fread(Instrument.HANDLE);
Warning: The specified amount of data was not returned within the Timeout period for 'read'.
'visadev' unable to read all requested data. For more information on possible reasons, see visadev Read Warnings.
K>> configureTerminator(Instrument.HANDLE,"LF")
K>> GPIBwrite(Instrument, ['MMEMory:DATA? ', DeviceFile]); [DataRead, count] = fread(Instrument.HANDLE);
Warning: The specified amount of data was not returned within the Timeout period for 'read'.
'visadev' unable to read all requested data. For more information on possible reasons, see visadev Read Warnings.
K>> configureTerminator(Instrument.HANDLE,"CR/LF")
K>> GPIBwrite(Instrument, ['MMEMory:DATA? ', DeviceFile]); [DataRead, count] = fread(Instrument.HANDLE);
Warning: The specified amount of data was not returned within the Timeout period for 'read'.
'visadev' unable to read all requested data. For more information on possible reasons, see visadev Read Warnings.

サインインしてコメントする。


Andrei
Andrei 2025 年 10 月 16 日 18:18
編集済み: Andrei 2025 年 10 月 16 日 18:22
Please refer to the following doc page for trasitioning your code from visa to visadev
Based on the Agilent E4443A programming manual, the data format returned by instrument is a binary block, you can use readbinblock function to read it (rather than reading it with read and then parsing the binary block header).
deviceFile = 'specify_your_file_path_on_instrument';
% Connect to insturment
v = visadev("GPIB0::18::INSTR");
% Capture instrument screenshot and transfer data
writeline(v, ['MMEMory:STORe:SCReen ', deviceFile]);
writeline(v, ['MMEMory:DATA? ', deviceFile]);
data = readbinblock(v,"uint8");
% Flush any remaining bytes appended by the instrument after the binary block
flush(v)
% Save screenshot data to an image file
% Assuming the file format for deviceFile is GIF per the instrument programmer manual
fid = fopen('screenshot.gif','w');
fwrite(fid,data,'uint8');
fclose(fid)
% Disconnect from instrument
clear v

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by