Skip to content

Commit 77d8f84

Browse files
committed
Added support for 16bit waveform data download on DHO models.
1 parent c5145fb commit 77d8f84

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

scopehal/RigolOscilloscope.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ RigolOscilloscope::RigolOscilloscope(SCPITransport* transport)
5050
, m_triggerWasLive(false)
5151
, m_triggerOneShot(false)
5252
, m_liveMode(false)
53+
, m_highDefinition(false)
5354
{
5455
//Last digit of the model number is the number of channels
5556
if(1 == sscanf(m_model.c_str(), "DS%d", &m_modelNumber))
@@ -115,6 +116,9 @@ RigolOscilloscope::RigolOscilloscope(SCPITransport* transport)
115116
// - DHO1072 (70MHz), DHO1074 (70MHz), DHO1102 (100MHz), DHO1104 (100MHz), DHO1202 (200MHz), DHO1204 (200MHz)
116117
// - DHO4204 (200MHz), DHO4404 (400 MHz), DHO4804 (800MHz)
117118
m_protocol = DHO;
119+
// Those are 12 bits (HD) models => default to high definition mode
120+
// This can be overriden by driver 8bits setting
121+
m_highDefinition = true;
118122

119123
int model_multiplicator = 100;
120124
int model_modulo = 100;
@@ -237,7 +241,7 @@ RigolOscilloscope::RigolOscilloscope(SCPITransport* transport)
237241
m_transport->SendCommandQueued(":WAV:POIN:MODE RAW");
238242
else
239243
{
240-
m_transport->SendCommandQueued(":WAV:FORM BYTE");
244+
m_transport->SendCommandQueued(string(":WAV:FORM ") + (m_highDefinition ? "WORD" : "BYTE"));
241245
m_transport->SendCommandQueued(":WAV:MODE RAW");
242246
}
243247
if(m_protocol == MSO5 || m_protocol == DS_OLD || m_protocol == DHO)
@@ -779,7 +783,7 @@ bool RigolOscilloscope::AcquireData()
779783
else if(m_protocol == MSO5)
780784
maxpoints = GetSampleDepth(); //You can use 250E6 points too, but it is very slow
781785

782-
unsigned char* temp_buf = new unsigned char[maxpoints + 1];
786+
unsigned char* temp_buf = new unsigned char[(m_highDefinition ? (maxpoints * 2) : maxpoints) + 1];
783787
map<int, vector<UniformAnalogWaveform*>> pending_waveforms;
784788
for(size_t i = 0; i < m_analogChannelCount; i++)
785789
{
@@ -900,6 +904,7 @@ bool RigolOscilloscope::AcquireData()
900904
//size_t blocksize = end - npoints;
901905
//LogDebug("Block size = %zu\n", blocksize);
902906
size_t header_blocksize;
907+
size_t header_blocksize_bytes;
903908
sscanf((char*)header, "%zu", &header_blocksize);
904909
//LogDebug("Header block size = %zu\n", header_blocksize);
905910

@@ -917,21 +922,37 @@ bool RigolOscilloscope::AcquireData()
917922
break;
918923
}
919924

925+
// Block size is provided in bytes, not in points
926+
header_blocksize_bytes = header_blocksize;
927+
if(m_highDefinition)
928+
header_blocksize = header_blocksize_bytes/2;
920929
if(header_blocksize > maxpoints)
921930
{
922931
header_blocksize = maxpoints;
923932
}
924933

925934
//Read actual block content and decode it
926935
//Scale: (value - Yorigin - Yref) * Yinc
927-
m_transport->ReadRawData(header_blocksize + 1, temp_buf); //trailing newline after data block
936+
m_transport->ReadRawData(header_blocksize_bytes + 1, temp_buf); //trailing newline after data block
928937

929938
double ydelta = yorigin + yreference;
930939
cap->Resize(cap->m_samples.size() + header_blocksize);
931940
cap->PrepareForCpuAccess();
941+
942+
const uint16_t* temp_buf_int16 = m_highDefinition ? reinterpret_cast<const uint16_t*>(temp_buf) : NULL;
932943
for(size_t j = 0; j < header_blocksize; j++)
933-
{
934-
float v = (static_cast<float>(temp_buf[j]) - ydelta) * yincrement;
944+
{ // Handle 8bit / 16bit acquisition modes
945+
float v;
946+
if(m_highDefinition)
947+
{
948+
v = (((static_cast<float>(temp_buf_int16[j]))) - ydelta) * yincrement;
949+
//LogDebug("V = %.3f, temp=%d, delta=%f, inc=%f\n", v, temp_buf_int16[j], ydelta, yincrement);
950+
}
951+
else
952+
{
953+
v = (static_cast<float>(temp_buf[j]) - ydelta) * yincrement;
954+
//LogDebug("V = %.3f, temp=%d, delta=%f, inc=%f\n", v, temp_buf[j], ydelta, yincrement);
955+
}
935956
if(m_protocol == DS_OLD)
936957
v = (128 - static_cast<float>(temp_buf[j])) * yincrement - ydelta;
937958
//LogDebug("V = %.3f, temp=%d, delta=%f, inc=%f\n", v, temp_buf[j], ydelta, yincrement);
@@ -1569,3 +1590,15 @@ void RigolOscilloscope::PushEdgeTrigger(EdgeTrigger* trig)
15691590
return;
15701591
}
15711592
}
1593+
1594+
/**
1595+
@brief Forces 16-bit transfer mode on/off when for HD models
1596+
*/
1597+
void RigolOscilloscope::ForceHDMode(bool mode)
1598+
{
1599+
if((m_protocol == DHO) && mode != m_highDefinition)
1600+
{
1601+
m_highDefinition = mode;
1602+
m_transport->SendCommandQueued(string(":WAV:FORM ") + (m_highDefinition ? "WORD" : "BYTE"));
1603+
}
1604+
}

scopehal/RigolOscilloscope.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class RigolOscilloscope : public virtual SCPIOscilloscope
9393
virtual bool IsInterleaving() override;
9494
virtual bool SetInterleaving(bool combine) override;
9595

96+
void ForceHDMode(bool mode);
97+
9698
protected:
9799
enum protocol_version
98100
{
@@ -135,6 +137,9 @@ class RigolOscilloscope : public virtual SCPIOscilloscope
135137
bool m_lowSrate; /* True for DHO low sample rate models (DHO800/900) */
136138
protocol_version m_protocol;
137139

140+
//True if we have >8 bit capture depth
141+
bool m_highDefinition;
142+
138143
void PushEdgeTrigger(EdgeTrigger* trig);
139144
void PullEdgeTrigger();
140145

0 commit comments

Comments
 (0)