Failure to read binary data from a visa instrument using readbinblock or read: Format error detected during binblockread.

17 views (last 30 days)
I need to read a binary block from Agilent laser mainframe HP8164A. The binary block is an 8-byte long double in Intel byte order. My main code is shown as below:
instr = visadev("GPIB0::20::INSTR");
flush(instr);
str = write(instr,'SOUR0:READ:DATA:BLOCK? LLOG,0,801');
data = readbinblock(instr,"double");
And I keep getting the error as:
Format error detected during binblockread.
binblock data must be in the format:
#[N][D][A], where
'#' is the token marking the start of the binblock.
'N' specifies the number of digits in D that follow.
'D' specifies the number of data bytes in A that follow.
A is the data
Things I've tried
  1. Read the original ASCII text from the instrument
str = writeread(instr,'SOUR0:READ:DATA:BLOCK? LLOG,0,801');
and I get
"#464080u±#µ>sùõF$µ>Ü)y$µ>ÈÏç$µ>øñ=U%µ>¶OÀÂ%µ>Ý]v2&µ>}ê=4&µ>'%'µ>rËÆz'µ>X ..."
The format looks good, which follows the #[N][D][A] format,, where N = 4, D = 6408 as where are 801 blocks.
2. Repeating the command
read(instr,1,'char')
Reading 1 char at a time. But it keeps skipping one character after each read. For example, it first reads '#', and then '6', skipping '4' in between. This is probably why readbinblock does not work.
3. Connect the instrument as a GPIB instrument and tried fread and binblockread. The same thing happens.
4. My code used to work with older versions of MATLAB, but not 2022a
Any idea on what is going on here? Thank you.
MATLAB Version: 9.12.0.1884302 (R2022a)
Instrument Control Toolbox: Version 4.6 (R2022a)

Answers (1)

chrisw23
chrisw23 on 6 Feb 2023
For this instruments a bunch of commands returns data in BinBlock format. i.e.
:RESult:BLOCk? Returns a specified binary block from the data array for the last power meter data acquisition function
:DATA:BLOCk? Returns a specified binary block from either a lambda logging operation...
:SLOT[n]:HEAD[m]:WAVelength:RESPonse? Wavelength Response table as a binary block
:READ[n][:CHANnel[m]][SCALar:]:POWer:ALL?
The instrument will send the data on cmd request to the outbut buffer and set the MAV bit when the message/data is available to be read. It's a good practice to read the data on MAV and not directly after the cmd request. Therefore you can configure the status subsystem of the device to fire a ServiceRequest event on MAV, which can be handled by an async callback method to read the data without polling the instruments state.
I suggest also to use Keysight Connection Expert with it's toolset to debug communication with InstrControl and IOMonitor.
Check the instrument state on error (:SYSTem:ERRor?)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!