Failure to read binary data from a visa instrument using readbinblock or read: Format error detected during binblockread.
19 次查看(过去 30 天)
显示 更早的评论
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
- 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)
1 个评论
Walter Roberson
2023-2-4
Try
char(read(instr,1,'uint8'))
as possibly 'char' is reading pairs (if for some reason MATLAB thinks the link is not single-byte character set)
回答(1 个)
chrisw23
2023-2-6
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?)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!