15 #include "charinterface.h"
16 #include "xwavengraph.h"
18 REGISTER_TYPE(
XDriverList, LecroyDSO,
"Lecroy/Teledyne/Iwatsu DSO");
21 XLecroyDSO::XLecroyDSO(
const char *name,
bool runtime,
22 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
25 for(
auto &&x: {trace1(), trace2(), trace3(), trace4()})
26 tr[ *x].add({
"C1",
"C2",
"C3",
"C4",
"M1",
"M2",
"M3",
"M4"});
27 for(
auto &&x: {vFullScale1(), vFullScale2(), vFullScale3(), vFullScale4()})
28 tr[ *x].add({
"0.02",
"0.05",
"0.1",
"0.2",
"0.5",
"1",
"2",
"5",
"10",
"20",
"50",
"100"});
29 tr[ *trigSource()].add({
"C1",
"C2",
"C3",
"C4",
"LINE",
"EX",
"EX10",
"PA",
"ETM10"});
33 interface()->setGPIBUseSerialPollOnRead(
false);
34 interface()->setGPIBUseSerialPollOnWrite(
false);
35 interface()->setEOS(
"\n");
37 trans( *recordLength()) = 10000;
42 interface()->send(
"COMM_HEADER OFF");
43 interface()->send(
"COMM_FORMAT DEF9,WORD,BIN");
45 interface()->send(
"COMM_ORDER LO");
47 interface()->query(
"TIME_DIV?");
48 trans( *timeWidth()) = interface()->toDouble() * 10.0;
50 interface()->query(
"MEMORY_SIZE?");
51 XString str = interface()->toStrSimplified();
52 double x = interface()->toDouble();
53 if(str.find(
"MA") != std::string::npos)
55 if(str.find(
"K") != std::string::npos)
57 trans( *recordLength()) = lrint(x);
60 onAverageChanged(shot_this,
average().
get());
65 XLecroyDSO::isWaveMaster() {
66 interface()->query(
"*IDN?");
67 if(interface()->toStr().find(
"WAVEMASTER") != std::string::npos)
return true;
69 if(interface()->scanf(
"LECROY,LT%s", buf) == 1)
return false;
70 if(interface()->scanf(
"LECROY,LC%s", buf) == 1)
return false;
72 if(interface()->scanf(
"LECROY,9%d", &num) == 1)
return false;
78 XLecroyDSO::activateTrace(
const char *name) {
79 interface()->queryf(
"%s:TRACE?", name);
80 if( !strncmp( &interface()->buffer()[0],
"OFF", 2)) {
81 interface()->queryf(
"%s:TRACE ON;*OPC?", name);
84 onAverageChanged(shot_this,
average().
get());
91 XString ch = ( **trace1())->to_str();
93 activateTrace(ch.c_str());
99 XString ch = ( **trace2())->to_str();
101 activateTrace(ch.c_str());
107 XString ch = ( **trace3())->to_str();
109 activateTrace(ch.c_str());
115 XString ch = ( **trace4())->to_str();
117 activateTrace(ch.c_str());
124 interface()->send(
"TRIG_MODE STOP");
125 int avg = shot_this[ *
average()];
126 avg = std::max(1, avg);
132 interface()->send(
"ARM");
135 interface()->send(
"TRIG_MODE NORM");
139 bool wavemaster = isWaveMaster();
140 const char *atype = sseq ?
"SUMMED" :
"CONTINUOUS";
142 atype = sseq ?
"AVGS" :
"AVGC";
143 XString chs[] = {shot_this[ *trace1()].to_str(), shot_this[ *trace2()].to_str(),
144 shot_this[ *trace3()].to_str(), shot_this[ *trace4()].to_str()};
145 const char *tchs[] = {
"TA",
"TB",
"TC",
"TD"};
149 for(
auto it = chs; it != chs + 4; ++it) {
153 interface()->sendf(
"%s:DEFINE EQN,'AVG(%s)',AVERAGETYPE,%s,SWEEPS,%d",
154 *tch, it->c_str(), atype, avg);
157 interface()->sendf(
"%s:DEFINE EQN,'%s(%s)',SWEEPS,%d",
158 *tch, atype, it->c_str(), avg);
160 interface()->sendf(
"%s:TRACE ON", *tch);
164 interface()->send(
"TRIG_MODE NORM");
172 onAverageChanged(shot_this,
average().
get());
176 interface()->sendf(
"TRIG_SELECT EDGE,SR,%s", shot[ *trigSource()].to_str().c_str());
180 interface()->sendf(
"TRIG_DELAY %fPCT", (
double)shot[ *trigPos()]);
185 interface()->sendf(
"%s:TRIG_LEVEL %gV", shot_this[ *trigSource()].to_str().c_str(), (
double)shot_this[ *trigLevel()]);
190 interface()->sendf(
"%s:TRIG_SLOPE %s", shot_this[ *trigSource()].to_str().c_str(),
191 (shot_this[ *trigFalling()] ?
"NEG" :
"POS"));
195 interface()->sendf(
"TIME_DIV %.1g", (
double)shot[ *timeWidth()] / 10.0);
200 XString ch = shot_this[ *trace1()].to_str();
201 if(ch.empty())
return;
202 interface()->sendf(
"%s:VOLT_DIV %.1g", ch.c_str(), atof(shot_this[ *vFullScale1()].to_str().c_str()) / 10.0);
207 XString ch = shot_this[ *trace2()].to_str();
208 if(ch.empty())
return;
209 interface()->sendf(
"%s:VOLT_DIV %.1g", ch.c_str(), atof(shot_this[ *vFullScale2()].to_str().c_str()) / 10.0);
214 XString ch = shot_this[ *trace3()].to_str();
215 if(ch.empty())
return;
216 interface()->sendf(
"%s:VOLT_DIV %.1g", ch.c_str(), atof(shot_this[ *vFullScale3()].to_str().c_str()) / 10.0);
221 XString ch = shot_this[ *trace4()].to_str();
222 if(ch.empty())
return;
223 interface()->sendf(
"%s:VOLT_DIV %.1g", ch.c_str(), atof(shot_this[ *vFullScale4()].to_str().c_str()) / 10.0);
228 XString ch = shot_this[ *trace1()].to_str();
229 if(ch.empty())
return;
230 interface()->sendf(
"%s:OFFSET %.8g V", ch.c_str(), (double)shot_this[ *vOffset1()]);
235 XString ch = shot_this[ *trace2()].to_str();
236 if(ch.empty())
return;
237 interface()->sendf(
"%s:OFFSET %.8g V", ch.c_str(), (double)shot_this[ *vOffset2()]);
242 XString ch = shot_this[ *trace3()].to_str();
243 if(ch.empty())
return;
244 interface()->sendf(
"%s:OFFSET %.8g V", ch.c_str(), (double)shot_this[ *vOffset3()]);
249 XString ch = shot_this[ *trace4()].to_str();
250 if(ch.empty())
return;
251 interface()->sendf(
"%s:OFFSET %.8g V", ch.c_str(), (double)shot_this[ *vOffset4()]);
255 interface()->sendf(
"MEMORY_SIZE %.2g", (
double)(
unsigned int)shot[ *recordLength()]);
263 interface()->send(
"ARM");
266 interface()->send(
"TRIG_MODE NORM");
274 interface()->send(
"STOP;CLEAR_SWEEPS");
276 interface()->send(
"ARM");
278 interface()->send(
"TRIG_MODE NORM");
287 int avg = shot_this[ *
average()];
288 avg = std::max(1, avg);
289 if( !shot_this[ *trace1()].to_str().empty()) {
290 interface()->queryf(
"%s:TRACE?", shot_this[ *trace1()].to_str().c_str());
291 if( !strncmp( &interface()->buffer()[0],
"ON", 2)) {
293 XString ch = (avg > 1) ?
XString(
"TA") : shot_this[ *trace1()].to_str();
294 n = lrint(inspectDouble(
"SWEEPS_PER_ACQ", ch));
297 if( !sseq || (avg < 2)) {
298 interface()->query(
"INR?");
299 if(interface()->toInt() & 1) {
308 *seq_busy = (n < avg);
313 XLecroyDSO::inspectDouble(
const char *req,
const XString &trace) {
314 interface()->queryf(
"%s:INSPECT? '%s'", trace.c_str(), req);
316 interface()->scanf(
"\"%*s : %lf", &x);
321 XLecroyDSO::getTimeInterval() {
322 return inspectDouble(
"HORIZ_INTERVAL", ( **trace1())->to_str());
331 writer->push<uint32_t>(channels.size());
332 for(
unsigned int i = 0; i < std::min((
unsigned int)channels.size(), 4u); i++) {
335 const char *fch[] = {
"TA",
"TB",
"TC",
"TD"};
338 interface()->sendf(
"%s:WAVEFORM? ALL", ch.c_str());
340 interface()->receive(4);
341 if(interface()->buffer().size() != 4)
343 interface()->setGPIBUseSerialPollOnRead(
false);
344 interface()->receive(2);
345 if(interface()->buffer().size() != 2)
347 writer->insert(writer->end(),
348 interface()->buffer().begin(), interface()->buffer().end());
350 interface()->scanf(
"#%1x", &n);
351 interface()->receive(n);
352 if(interface()->buffer().size() != n)
354 writer->insert(writer->end(),
355 interface()->buffer().begin(), interface()->buffer().end());
356 int blks = interface()->toUInt();
357 XTime tstart = XTime::now();
358 for(
int retry = 0;; retry++) {
359 interface()->receive(blks);
360 blks -= interface()->buffer().size();
361 writer->insert(writer->end(),
362 interface()->buffer().begin(), interface()->buffer().end());
365 if(XTime::now() - tstart > 3.0)
371 interface()->receive();
386 #define WAVEDESC_WAVE_ARRAY_COUNT 116
387 #define DATA_BLOCK 346
389 unsigned int ch_cnt = reader.pop<uint32_t>();
390 for(
unsigned int ch = 0; ch < ch_cnt; ch++) {
391 std::vector<char>::const_iterator dit = reader.popIterator();
393 sscanf( &*dit,
"#%1u", &n);
395 if(strncmp( &*dit,
"WAVEDESC", 8)) {
396 throw XRecordError(i18n(
"Invalid waveform"), __FILE__, __LINE__);
399 reader.popIterator() += WAVEDESC_WAVE_ARRAY_COUNT + n + 2;
400 int32_t count = reader.pop<int32_t>();
401 reader.pop<int32_t>();
402 int32_t first_valid = reader.pop<int32_t>();
403 int32_t last_valid = reader.pop<int32_t>();
404 int32_t first = reader.pop<int32_t>();
405 reader.pop<int32_t>();
406 reader.pop<int32_t>();
407 reader.pop<int32_t>();
408 int32_t acqcount = reader.pop<int32_t>();
409 reader.pop<int16_t>();
410 reader.pop<int16_t>();
411 float vgain = reader.pop<
float>();
412 float voffset = reader.pop<
float>();
415 reader.pop<int16_t>();
416 reader.pop<int16_t>();
417 float interval = reader.pop<
float>();
418 double hoffset = reader.pop<
double>();
420 fprintf(stderr,
"first_valid=%d,last_valid=%d,first=%d,acqcount=%d,count=%d\n",
421 (
int)first_valid, (
int)last_valid, (
int)first, (
int)acqcount, (
int)count);
424 (reader.size() < (count * 2 + DATA_BLOCK + n + 2) * ch_cnt))
426 tr[ *
this].setParameters(ch_cnt, hoffset, interval, count);
429 double *wave = tr[ *
this].waveDisp(ch);
430 reader.popIterator() = dit;
431 int length = shot[ *
this].lengthDisp();
432 for(
int i = 0; i < std::min(count, (int32_t)length); i++) {
433 int16_t x = reader.pop<int16_t>();
434 float v = voffset + vgain * x;