Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1da41d3d8c12
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a5d675d616f
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Sep 24, 2020

  1. Copy the full SHA
    e3ac649 View commit details
  2. Copy the full SHA
    ab74571 View commit details
  3. Copy the full SHA
    6a5d675 View commit details
Showing with 95 additions and 107 deletions.
  1. +95 −107 scopehal/TektronixOscilloscope.cpp
202 changes: 95 additions & 107 deletions scopehal/TektronixOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ TektronixOscilloscope::TektronixOscilloscope(SCPITransport* transport)
else
m_family = FAMILY_UNKNOWN;

/*
//Last digit of the model number is the number of channels
std::string model_number = m_model;
model_number.erase(
@@ -60,9 +59,7 @@ TektronixOscilloscope::TektronixOscilloscope(SCPITransport* transport)
),
model_number.end()
);
int nchans = std::stoi(model_number) % 10;
*/
int nchans = 4;
int nchans = stoi(model_number) % 10;

// No header in the reply of queries
m_transport->SendCommand("HEAD 0");
@@ -74,6 +71,7 @@ TektronixOscilloscope::TektronixOscilloscope(SCPITransport* transport)
m_transport->SendCommand("ACQ:MOD SAM"); //actual sampled data, no averaging etc
m_transport->SendCommand("VERB OFF"); //Disable verbose mode (send shorter commands)
m_transport->SendCommand("DAT:ENC SRI"); //signed, little endian binary
m_transport->SendCommand("DAT:WID 2"); //16-bit data
break;

default:
@@ -217,11 +215,9 @@ bool TektronixOscilloscope::IsChannelEnabled(size_t i)

lock_guard<recursive_mutex> lock2(m_mutex);

// m_transport->SendCommand(m_channels[i]->GetHwname() + ":DISP?");
// string reply = m_transport->ReadReply();
//
string reply;
reply = "1";
m_transport->SendCommand(string("DISP:GLOB:") + m_channels[i]->GetHwname() + ":STATE?");
string reply = m_transport->ReadReply();

if(reply == "0")
{
m_channelsEnabled[i] = false;
@@ -237,7 +233,7 @@ bool TektronixOscilloscope::IsChannelEnabled(size_t i)
void TektronixOscilloscope::EnableChannel(size_t i)
{
lock_guard<recursive_mutex> lock(m_mutex);
// m_transport->SendCommand(m_channels[i]->GetHwname() + ":DISP ON");
m_transport->SendCommand(string("DISP:GLOB:") + m_channels[i]->GetHwname() + ":STATE ON");

lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelsEnabled[i] = true;
@@ -246,7 +242,7 @@ void TektronixOscilloscope::EnableChannel(size_t i)
void TektronixOscilloscope::DisableChannel(size_t i)
{
lock_guard<recursive_mutex> lock(m_mutex);
// m_transport->SendCommand(m_channels[i]->GetHwname() + ":DISP OFF");
m_transport->SendCommand(string("DISP:GLOB:") + m_channels[i]->GetHwname() + ":STATE OFF");

lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelsEnabled[i] = false;
@@ -488,9 +484,8 @@ bool TektronixOscilloscope::AcquireData()
string reply = m_transport->ReadReply();
sscanf(reply.c_str(), "%zu", &length);

LogDebug("Record length: %zu points\n", length);

snprintf(tmp, sizeof(tmp), "DAT:START 0;DAT:STOP %zu", length);
m_transport->SendCommand("DAT:START 0");
snprintf(tmp, sizeof(tmp), "DAT:STOP %zu", length);
m_transport->SendCommand(tmp);
}
break;
@@ -503,34 +498,23 @@ bool TektronixOscilloscope::AcquireData()
double ymult = 0;
double yoff = 0;

/*
//unsigned int format;
//unsigned int type;
size_t length;
//unsigned int average_count;
//double xorigin;
//double xreference;
double yincrement;
double yorigin;
double yreference;
*/
map<int, vector<AnalogWaveform*> > pending_waveforms;
for(size_t i=0; i<m_analogChannelCount; i++)
{
LogDebug("Channel %zu (%s)\n", i, m_channels[i]->GetHwname().c_str());
LogIndenter li2;

if(!IsChannelEnabled(i))
continue;

LogDebug("Channel %zu (%s)\n", i, m_channels[i]->GetHwname().c_str());
LogIndenter li2;

// Set source & get preamble+data
m_transport->SendCommand(string("DAT:SOU ") + m_channels[i]->GetHwname());
switch(m_family)
{
case FAMILY_MSO5_6:
{
//Ask for the waveform preamble and info
m_transport->SendCommand("WAVF?");
//Ask for the waveform preamble
m_transport->SendCommand("WFMO?");

//Get the preamble
for(int j=0; j<22; j++)
@@ -557,6 +541,9 @@ bool TektronixOscilloscope::AcquireData()
}
}

//Read the data blocks
m_transport->SendCommand("CURV?");

//Read length of the actual data
char tmplen[3] = {0};
m_transport->ReadRawData(2, (unsigned char*)tmplen); //expect #n
@@ -570,7 +557,9 @@ bool TektronixOscilloscope::AcquireData()
char* rxbuf = new char[msglen];
m_transport->ReadRawData(msglen, (unsigned char*)rxbuf);

//TODO: seems like we might have more than one block of data to process??
//convert bytes to samples
size_t nsamples = msglen/2;
int16_t* samples = (int16_t*)rxbuf;

//Set up the capture we're going to store our data into
//(no TDC data or fine timestamping available on Tektronix scopes?)
@@ -580,14 +569,14 @@ bool TektronixOscilloscope::AcquireData()
cap->m_startTimestamp = time(NULL);
double t = GetTime();
cap->m_startPicoseconds = (t - floor(t)) * 1e12f;
cap->Resize(msglen);
cap->Resize(nsamples);

//Convert to volts
for(int j=0; j<msglen; j++)
for(size_t j=0; j<nsamples; j++)
{
cap->m_offsets[j] = j;
cap->m_durations[j] = 1;
cap->m_samples[j] = ymult*rxbuf[j] + yoff;
cap->m_samples[j] = ymult*samples[j] + yoff;
}

//Done, update the data
@@ -603,83 +592,82 @@ bool TektronixOscilloscope::AcquireData()

default:
//m_transport->SendCommand("WFMPRE:" + m_channels[i]->GetHwname() + "?");
break;
}
/*
// string reply = m_transport->ReadReply();
// sscanf(reply.c_str(), "%u,%u,%lu,%u,%lf,%lf,%lf,%lf,%lf,%lf",
// &format, &type, &length, &average_count, &xincrement, &xorigin, &xreference, &yincrement, &yorigin, &yreference);
for(int j=0;j<10;++j)
m_transport->ReadReply();
/*
// string reply = m_transport->ReadReply();
// sscanf(reply.c_str(), "%u,%u,%lu,%u,%lf,%lf,%lf,%lf,%lf,%lf",
// &format, &type, &length, &average_count, &xincrement, &xorigin, &xreference, &yincrement, &yorigin, &yreference);
for(int j=0;j<10;++j)
m_transport->ReadReply();
//format = 0;
//type = 0;
//average_count = 0;
xincrement = 1000;
//xorigin = 0;
//xreference = 0;
yincrement = 0.01;
yorigin = 0;
yreference = 0;
length = 500;
//Figure out the sample rate
int64_t ps_per_sample = round(xincrement * 1e12f);
//LogDebug("%ld ps/sample\n", ps_per_sample);
//LogDebug("length = %d\n", length);
//Set up the capture we're going to store our data into
//(no TDC data available on Tektronix scopes?)
AnalogWaveform* cap = new AnalogWaveform;
cap->m_timescale = ps_per_sample;
cap->m_triggerPhase = 0;
cap->m_startTimestamp = time(NULL);
double t = GetTime();
cap->m_startPicoseconds = (t - floor(t)) * 1e12f;
//Ask for the data
m_transport->SendCommand("CURV?");
char tmp[16] = {0};
//Read the length header
m_transport->ReadRawData(2, (unsigned char*)tmp);
tmp[2] = '\0';
int numDigits = atoi(tmp+1);
LogDebug("numDigits = %d\n", numDigits);
// Read the number of points
m_transport->ReadRawData(numDigits, (unsigned char*)tmp);
tmp[numDigits] = '\0';
int numPoints = atoi(tmp);
LogDebug("numPoints = %d\n", numPoints);
uint8_t* temp_buf = new uint8_t[numPoints / sizeof(uint8_t)];
//Read the actual data
m_transport->ReadRawData(numPoints, (unsigned char*)temp_buf);
//Discard trailing newline
m_transport->ReadRawData(1, (unsigned char*)tmp);
//Format the capture
cap->Resize(length);
for(size_t j=0; j<length; j++)
{
cap->m_offsets[j] = j;
cap->m_durations[j] = 1;
cap->m_samples[j] = yincrement * (temp_buf[j] - yreference) + yorigin;
}
//format = 0;
//type = 0;
//average_count = 0;
xincrement = 1000;
//xorigin = 0;
//xreference = 0;
yincrement = 0.01;
yorigin = 0;
yreference = 0;
length = 500;
//Figure out the sample rate
int64_t ps_per_sample = round(xincrement * 1e12f);
//LogDebug("%ld ps/sample\n", ps_per_sample);
//LogDebug("length = %d\n", length);
//Set up the capture we're going to store our data into
//(no TDC data available on Tektronix scopes?)
AnalogWaveform* cap = new AnalogWaveform;
cap->m_timescale = ps_per_sample;
cap->m_triggerPhase = 0;
cap->m_startTimestamp = time(NULL);
double t = GetTime();
cap->m_startPicoseconds = (t - floor(t)) * 1e12f;
//Ask for the data
m_transport->SendCommand("CURV?");
char tmp[16] = {0};
//Read the length header
m_transport->ReadRawData(2, (unsigned char*)tmp);
tmp[2] = '\0';
int numDigits = atoi(tmp+1);
LogDebug("numDigits = %d\n", numDigits);
// Read the number of points
m_transport->ReadRawData(numDigits, (unsigned char*)tmp);
tmp[numDigits] = '\0';
int numPoints = atoi(tmp);
LogDebug("numPoints = %d\n", numPoints);
uint8_t* temp_buf = new uint8_t[numPoints / sizeof(uint8_t)];
//Read the actual data
m_transport->ReadRawData(numPoints, (unsigned char*)temp_buf);
//Discard trailing newline
m_transport->ReadRawData(1, (unsigned char*)tmp);
//Format the capture
cap->Resize(length);
for(size_t j=0; j<length; j++)
{
cap->m_offsets[j] = j;
cap->m_durations[j] = 1;
cap->m_samples[j] = yincrement * (temp_buf[j] - yreference) + yorigin;
}
//Done, update the data
pending_waveforms[i].push_back(cap);
//Done, update the data
pending_waveforms[i].push_back(cap);
//Clean up
delete[] temp_buf;
*/
break;
}

//Clean up
delete[] temp_buf;
*/
}

//Now that we have all of the pending waveforms, save them in sets across all channels