Skip to content

Instantly share code, notes, and snippets.

@mvladic
Created February 28, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvladic/79370346f5006c92f73a8ab8cb07f996 to your computer and use it in GitHub Desktop.
Save mvladic/79370346f5006c92f73a8ab8cb07f996 to your computer and use it in GitHub Desktop.
// Preamble:
// <format>,<type>,<points>,<count>,<xincrement>,<xorigin>,<xreference>,<yincrem ent>,<yorigin>,<yreference>
// Wherein,
// <format>: 0 (BYTE), 1 (WORD) or 2 (ASC).
// <type>: 0 (NORMal), 1 (MAXimum) or 2 (RAW).
// <points>: an integer between 1 and 12000000.
// <count>: the number of averages in the average sample mode and 1 in other modes.
// <xincrement>: the time difference between two neighboring points in the X direction.
// <xorigin>: the start time of the waveform data in the X direction.
// <xreference>: the reference time of the data point in the X direction.
// <yincrement>: the waveform increment in the Y direction.
// <yorigin>: the vertical offset relative to the "Vertical Reference Position" in the Y direction.
// <yreference>: the vertical reference position in the Y direction.
const CHUNK_MAX_POINTS = 1000000;
const NUM_CHANNELS = instrument.properties.channels.length;
connection.acquire();
var displayedChannels = [];
for (var iChannel = 1; iChannel <= NUM_CHANNELS; ++iChannel) {
var displayed = await connection.query(`CHANnel${iChannel}:DISPlay?`);
if (displayed) {
displayedChannels.push(iChannel);
}
}
if (displayedChannels.length > 0) {
connection.command("ACQuire:MDEPth auto");
connection.command("WAVeform:MODE raw");
connection.command("STOP");
connection.command("WAVeform:FORMat byte");
var samplingRate = await connection.query("ACQuire:SRATe?");
var timeScale = await connection.query("TIMebase:SCALe?");
var chunk_points = Math.floor(CHUNK_MAX_POINTS / displayedChannels.length);
for (var iDisplayedChannel = 0; iDisplayedChannel < displayedChannels.length; ++iDisplayedChannel) {
var iChannel = displayedChannels[iDisplayedChannel];
connection.command(`WAVeform:SOURce chan${iChannel}`);
var channelScale = await connection.query(`CHANnel${iChannel}:SCALe?`);
var channelOffset = await connection.query(`CHANnel${iChannel}:OFFSet?`);
var unit = await connection.query(`CHANnel${iChannel}:UNITs?`);
var color = instrument.properties.channels[iChannel - 1].color;
var colorInverse = instrument.properties.channels[iChannel - 1].colorInverse;
var label = `Channel ${iChannel}`;
var preamble = await connection.query("WAVeform:PREamble?");
var preambleArray = preamble.split(',');
var numPoints = parseInt(preambleArray[2]);
var yinc = parseFloat(preambleArray[7]);
var yor = parseFloat(preambleArray[8]);
var yref = parseFloat(preambleArray[9]);
var offset = -(yor + yref) * yinc;
var scale = yinc;
var description = `Channel: ${iChannel}, Sampling rate: ${samplingRate}, Preamble: ${preamble}`;
notify.info(description);
var data = [];
var numChunks = Math.ceil(numPoints / chunk_points);
for (var iChunk = 0; iChunk < numChunks; ++iChunk) {
notify.info(`Reading waveform data ${iChunk + 1} of ${numChunks}`);
var i = iChunk * chunk_points;
connection.command(`WAVeform:STARt ${i + 1}`);
connection.command(`WAVeform:STOP ${Math.min(i + chunk_points, numPoints)}`);
var waveform = await connection.query("WAVeform:DATA?");
data.push(waveform.data);
waveform.deleteLog();
}
session.addChart({
description,
data,
samplingRate,
offset,
scale,
format: 2,
unit,
color,
colorInverse,
label,
viewOptions: {
axesLines: {
type: "fixed",
majorSubdivision: {
horizontal: 12,
vertical: 8
},
minorSubdivision: {
horizontal: 5,
vertical: 5
}
}
},
horizontalScale: timeScale,
verticalScale: channelScale
});
}
}
connection.release();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment