-
Notifications
You must be signed in to change notification settings - Fork 79
/
LeCroyOscilloscope.cpp
2154 lines (1826 loc) · 56.8 KB
/
LeCroyOscilloscope.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/
#include "scopehal.h"
#include "LeCroyOscilloscope.h"
#include "ProtocolDecoder.h"
#include "base64.h"
#include <locale>
using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction
LeCroyOscilloscope::LeCroyOscilloscope(SCPITransport* transport)
: SCPIOscilloscope(transport)
, m_hasLA(false)
, m_hasDVM(false)
, m_hasFunctionGen(false)
, m_triggerArmed(false)
, m_triggerOneShot(false)
, m_sampleRateValid(false)
, m_sampleRate(1)
, m_memoryDepthValid(false)
, m_memoryDepth(1)
, m_triggerOffsetValid(false)
, m_triggerOffset(0)
, m_highDefinition(false)
{
//standard initialization
FlushConfigCache();
IdentifyHardware();
DetectAnalogChannels();
SharedCtorInit();
DetectOptions();
}
void LeCroyOscilloscope::SharedCtorInit()
{
m_digitalChannelCount = 0;
//Add the external trigger input
m_extTrigChannel = new OscilloscopeChannel(
this,
"EX",
OscilloscopeChannel::CHANNEL_TYPE_TRIGGER,
"",
1,
m_channels.size(),
true);
m_channels.push_back(m_extTrigChannel);
//Desired format for waveform data
//Only use increased bit depth if the scope actually puts content there!
if(m_highDefinition)
m_transport->SendCommand("COMM_FORMAT DEF9,WORD,BIN");
else
m_transport->SendCommand("COMM_FORMAT DEF9,BYTE,BIN");
//Always use "max memory" config for setting sample depth
m_transport->SendCommand("VBS? 'app.Acquisition.Horizontal.Maximize=\"SetMaximumMemory\"'");
//Disable channel interleaving until we support this properly
m_transport->SendCommand("COMBINE_CHANNELS 1");
//Clear the state-change register to we get rid of any history we don't care about
PollTrigger();
}
void LeCroyOscilloscope::IdentifyHardware()
{
//Turn off headers (complicate parsing and add fluff to the packets)
m_transport->SendCommand("CHDR OFF");
//Ask for the ID
m_transport->SendCommand("*IDN?");
string reply = m_transport->ReadReply();
char vendor[128] = "";
char model[128] = "";
char serial[128] = "";
char version[128] = "";
if(4 != sscanf(reply.c_str(), "%127[^,],%127[^,],%127[^,],%127s", vendor, model, serial, version))
{
LogError("Bad IDN response %s\n", reply.c_str());
return;
}
m_vendor = vendor;
m_model = model;
m_serial = serial;
m_fwVersion = version;
//Look up model info
m_modelid = MODEL_UNKNOWN;
if(m_model.find("WS3") == 0)
m_modelid = MODEL_WAVESURFER_3K;
else if(m_model.find("HDO9") == 0)
m_modelid = MODEL_HDO_9K;
else if(m_model.find("DDA5") == 0)
m_modelid = MODEL_DDA_5K;
else if(m_model.find("WAVERUNNER8") == 0)
m_modelid = MODEL_WAVERUNNER_8K;
else if(m_model.find("SDA3") == 0)
m_modelid = MODEL_SDA_3K;
else if (m_vendor.compare("SIGLENT") == 0)
{
// TODO: if LeCroy and Siglent classes get split, then this should obviously
// move to the Siglent class.
if (m_model.compare(0, 4, "SDS2") == 0 && m_model.back() == 'X')
m_modelid = MODEL_SIGLENT_SDS2000X;
}
//TODO: better way of doing this?
if(m_model.find("HD") != string::npos)
m_highDefinition = true;
}
void LeCroyOscilloscope::DetectOptions()
{
m_transport->SendCommand("*OPT?");
string reply = m_transport->ReadReply();
if(reply.length() > 3)
{
//Read options until we hit a null
vector<string> options;
string opt;
for(unsigned int i=0; i<reply.length(); i++)
{
if(reply[i] == 0)
{
options.push_back(opt);
break;
}
else if(reply[i] == ',')
{
options.push_back(opt);
opt = "";
}
//skip newlines
else if(reply[i] == '\n')
continue;
else
opt += reply[i];
}
if(opt != "")
options.push_back(opt);
//Print out the option list and do processing for each
LogDebug("Installed options:\n");
if(options.empty())
LogDebug("* None\n");
for(auto o : options)
{
//If we have an LA module installed, add the digital channels
if( (o == "MSXX") && !m_hasLA)
{
LogDebug("* MSXX (logic analyzer)\n");
AddDigitalChannels(16);
}
//If we have the voltmeter installed, make a note of that
else if(o == "DVM")
{
m_hasDVM = true;
LogDebug("* DVM (digital voltmeter / frequency counter)\n");
SetMeterAutoRange(false);
}
//If we have the function generator installed, remember that
else if(o == "AFG")
{
m_hasFunctionGen = true;
LogDebug("* AFG (function generator)\n");
}
//Ignore protocol decodes, we do those ourselves
else if( (o == "I2C") || (o == "UART") || (o == "SPI") )
{
LogDebug("* %s (protocol decode, ignoring)\n", o.c_str());
}
//Ignore UI options
else if(o == "XWEB")
{
LogDebug("* %s (UI option, ignoring)\n", o.c_str());
}
//No idea what it is
else
LogDebug("* %s (not yet implemented)\n", o.c_str());
}
}
//If we don't have a code for the LA software option, but are a -MS scope, add the LA
if(!m_hasLA && (m_model.find("-MS") != string::npos))
AddDigitalChannels(16);
}
/**
@brief Creates digital channels for the oscilloscope
*/
void LeCroyOscilloscope::AddDigitalChannels(unsigned int count)
{
m_hasLA = true;
LogIndenter li;
m_digitalChannelCount = count;
char chn[32];
for(unsigned int i=0; i<count; i++)
{
snprintf(chn, sizeof(chn), "Digital%d", i);
auto chan = new OscilloscopeChannel(
this,
chn,
OscilloscopeChannel::CHANNEL_TYPE_DIGITAL,
GetDefaultChannelColor(m_channels.size()),
1,
m_channels.size(),
true);
m_channels.push_back(chan);
m_digitalChannels.push_back(chan);
}
//Enable all of them
}
/**
@brief Figures out how many analog channels we have, and add them to the device
If you're lucky, the last digit of the model number will be the number of channels (HDO9204)
But, since we can't have nice things, theres are plenty of exceptions. Known formats so far:
* WAVERUNNER8104-MS has 4 channels (plus 16 digital)
* DDA5005 / DDA5005A have 4 channels
* SDA3010 have 4 channels
*/
void LeCroyOscilloscope::DetectAnalogChannels()
{
//General model format is family, number, suffix. Not all are always present.
//Trim off alphabetic characters from the start of the model number
size_t pos;
for(pos=0; pos < m_model.length(); pos++)
{
if(isalpha(m_model[pos]))
continue;
else if(isdigit(m_model[pos]))
break;
else
{
LogError("Unrecognized character (not alphanumeric) in model number %s\n", m_model.c_str());
return;
}
}
//Now we should be able to read the model number
int modelNum = atoi(m_model.c_str() + pos);
//Last digit of the model number is normally the number of channels (WAVESURFER3022, HDO8108)
int nchans = modelNum % 10;
//DDA5005 and similar have 4 channels despite a model number ending in 5
//SDA3010 have 4 channels despite a model number ending in 0
if(m_modelid == MODEL_DDA_5K || m_modelid == MODEL_SDA_3K)
nchans = 4;
for(int i=0; i<nchans; i++)
{
//Hardware name of the channel
string chname = string("C1");
chname[1] += i;
//Color the channels based on LeCroy's standard color sequence (yellow-pink-cyan-green)
string color = "#ffffff";
switch(i)
{
case 0:
color = "#ffff80";
break;
case 1:
color = "#ff8080";
break;
case 2:
color = "#80ffff";
break;
case 3:
color = "#80ff80";
break;
}
//Create the channel
m_channels.push_back(
new OscilloscopeChannel(
this,
chname,
OscilloscopeChannel::CHANNEL_TYPE_ANALOG,
color,
1,
i,
true));
}
m_analogChannelCount = nchans;
}
LeCroyOscilloscope::~LeCroyOscilloscope()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device information
string LeCroyOscilloscope::GetDriverNameInternal()
{
return "lecroy";
}
OscilloscopeChannel* LeCroyOscilloscope::GetExternalTrigger()
{
return m_extTrigChannel;
}
void LeCroyOscilloscope::FlushConfigCache()
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
m_triggerChannelValid = false;
m_triggerLevelValid = false;
m_triggerType = TRIGGER_TYPE_DONTCARE;
m_triggerTypeValid = false;
m_channelVoltageRanges.clear();
m_channelOffsets.clear();
m_channelsEnabled.clear();
m_channelDeskew.clear();
m_sampleRateValid = false;
m_memoryDepthValid = false;
m_triggerOffsetValid = false;
}
/**
@brief See what measurement capabilities we have
*/
unsigned int LeCroyOscilloscope::GetMeasurementTypes()
{
unsigned int type = 0;
if(m_hasDVM)
{
type |= DC_VOLTAGE;
type |= DC_RMS_AMPLITUDE;
type |= AC_RMS_AMPLITUDE;
type |= FREQUENCY;
}
return type;
}
/**
@brief See what features we have
*/
unsigned int LeCroyOscilloscope::GetInstrumentTypes()
{
unsigned int type = INST_OSCILLOSCOPE;
if(m_hasDVM)
type |= INST_DMM;
if(m_hasFunctionGen)
type |= INST_FUNCTION;
return type;
}
string LeCroyOscilloscope::GetName()
{
return m_model;
}
string LeCroyOscilloscope::GetVendor()
{
return m_vendor;
}
string LeCroyOscilloscope::GetSerial()
{
return m_serial;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Channel configuration
bool LeCroyOscilloscope::IsChannelEnabled(size_t i)
{
//ext trigger should never be displayed
if(i == m_extTrigChannel->GetIndex())
return false;
//Early-out if status is in cache
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
if(m_channelsEnabled.find(i) != m_channelsEnabled.end())
return m_channelsEnabled[i];
}
//Need to lock the main mutex first to prevent deadlocks
lock_guard<recursive_mutex> lock(m_mutex);
lock_guard<recursive_mutex> lock2(m_cacheMutex);
//Analog
if(i < m_analogChannelCount)
{
//See if the channel is enabled, hide it if not
string cmd = m_channels[i]->GetHwname() + ":TRACE?";
m_transport->SendCommand(cmd);
string reply = m_transport->ReadReply();
if(reply.find("OFF") == 0) //may have a trailing newline, ignore that
m_channelsEnabled[i] = false;
else
m_channelsEnabled[i] = true;
}
//Digital
else
{
//See if the channel is on
m_transport->SendCommand(string("VBS? 'return = app.LogicAnalyzer.Digital1.") + m_channels[i]->GetHwname() + "'");
string str = m_transport->ReadReply();
if(str == "0")
m_channelsEnabled[i] = false;
else
m_channelsEnabled[i] = true;
}
return m_channelsEnabled[i];
}
void LeCroyOscilloscope::EnableChannel(size_t i)
{
//LogDebug("enable channel %d\n", i);
lock_guard<recursive_mutex> lock(m_mutex);
//LogDebug("got mutex\n");
//If this is an analog channel, just toggle it
if(i < m_analogChannelCount)
m_transport->SendCommand(m_channels[i]->GetHwname() + ":TRACE ON");
//Trigger can't be enabled
else if(i == m_extTrigChannel->GetIndex())
{
}
//Digital channel
else
{
//If we have NO digital channels enabled, enable the first digital bus
bool anyDigitalEnabled = false;
for(auto c : m_digitalChannels)
{
if(m_channelsEnabled[c->GetIndex()])
{
anyDigitalEnabled = true;
break;
}
}
if(!anyDigitalEnabled)
m_transport->SendCommand("VBS? 'app.LogicAnalyzer.Digital1.UseGrid=\"YT1\"'");
//Enable this channel on the hardware
m_transport->SendCommand(string("VBS? 'app.LogicAnalyzer.Digital1.") + m_channels[i]->GetHwname() + " = 1'");
char tmp[128];
size_t nbit = (i - m_digitalChannels[0]->GetIndex());
snprintf(tmp, sizeof(tmp), "VBS? 'app.LogicAnalyzer.Digital1.BitIndex%zu = %zu'", nbit, nbit);
m_transport->SendCommand(tmp);
}
m_channelsEnabled[i] = true;
}
void LeCroyOscilloscope::DisableChannel(size_t i)
{
//LogDebug("enable channel %d\n", i);
lock_guard<recursive_mutex> lock(m_mutex);
//LogDebug("got mutex\n");
m_channelsEnabled[i] = false;
//If this is an analog channel, just toggle it
if(i < m_analogChannelCount)
m_transport->SendCommand(m_channels[i]->GetHwname() + ":TRACE OFF");
//Trigger can't be enabled
else if(i == m_extTrigChannel->GetIndex())
{
}
//Digital channel
else
{
//If we have NO digital channels enabled, disable the first digital bus
bool anyDigitalEnabled = false;
for(auto c : m_digitalChannels)
{
if(m_channelsEnabled[c->GetIndex()])
{
anyDigitalEnabled = true;
break;
}
}
if(!anyDigitalEnabled)
m_transport->SendCommand("VBS? 'app.LogicAnalyzer.Digital1.UseGrid=\"NotOnGrid\"'");
//Disable this channel
m_transport->SendCommand(string("VBS? 'app.LogicAnalyzer.Digital1.") + m_channels[i]->GetHwname() + " = 0'");
}
}
OscilloscopeChannel::CouplingType LeCroyOscilloscope::GetChannelCoupling(size_t i)
{
if(i > m_analogChannelCount)
return OscilloscopeChannel::COUPLE_SYNTHETIC;
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand(m_channels[i]->GetHwname() + ":COUPLING?");
string reply = m_transport->ReadReply().substr(0,3); //trim off trailing newline, all coupling codes are 3 chars
if(reply == "A1M")
return OscilloscopeChannel::COUPLE_AC_1M;
else if(reply == "D1M")
return OscilloscopeChannel::COUPLE_DC_1M;
else if(reply == "D50")
return OscilloscopeChannel::COUPLE_DC_50;
else if(reply == "GND")
return OscilloscopeChannel::COUPLE_GND;
//invalid
LogWarning("LeCroyOscilloscope::GetChannelCoupling got invalid coupling %s\n", reply.c_str());
return OscilloscopeChannel::COUPLE_SYNTHETIC;
}
void LeCroyOscilloscope::SetChannelCoupling(size_t /*i*/, OscilloscopeChannel::CouplingType /*type*/)
{
//FIXME
}
double LeCroyOscilloscope::GetChannelAttenuation(size_t i)
{
if(i > m_analogChannelCount)
return 1;
//TODO: support ext/10
if(i == m_extTrigChannel->GetIndex())
return 1;
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand(m_channels[i]->GetHwname() + ":ATTENUATION?");
string reply = m_transport->ReadReply();
double d;
sscanf(reply.c_str(), "%lf", &d);
return d;
}
void LeCroyOscilloscope::SetChannelAttenuation(size_t /*i*/, double /*atten*/)
{
//FIXME
}
int LeCroyOscilloscope::GetChannelBandwidthLimit(size_t i)
{
if(i > m_analogChannelCount)
return 0;
lock_guard<recursive_mutex> lock(m_mutex);
string cmd = "BANDWIDTH_LIMIT?";
m_transport->SendCommand(cmd);
string reply = m_transport->ReadReply();
size_t index = reply.find(m_channels[i]->GetHwname());
if(index == string::npos)
return 0;
char chbw[16];
sscanf(reply.c_str() + index + 3, "%15[^,\n]", chbw); //offset 3 for "Cn,"
string sbw(chbw);
if(sbw == "OFF")
return 0;
else if(sbw == "ON") //apparently "on" means lowest possible B/W?
return 20; //this isn't documented anywhere in the MAUI remote control manual
else if(sbw == "20MHZ")
return 20;
else if(sbw == "200MHZ")
return 200;
else if(sbw == "500MHZ")
return 500;
else if(sbw == "1GHZ")
return 1000;
else if(sbw == "2GHZ")
return 2000;
else if(sbw == "3GHZ")
return 3000;
else if(sbw == "4GHZ")
return 4000;
else if(sbw == "6GHZ")
return 6000;
LogWarning("LeCroyOscilloscope::GetChannelCoupling got invalid coupling %s\n", reply.c_str());
return 0;
}
void LeCroyOscilloscope::SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz)
{
lock_guard<recursive_mutex> lock(m_mutex);
char cmd[128];
if(limit_mhz == 0)
snprintf(cmd, sizeof(cmd), "BANDWIDTH_LIMIT %s,OFF", m_channels[i]->GetHwname().c_str());
else
snprintf(cmd, sizeof(cmd), "BANDWIDTH_LIMIT %s,%uMHZ", m_channels[i]->GetHwname().c_str(), limit_mhz);
m_transport->SendCommand(cmd);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DMM mode
bool LeCroyOscilloscope::GetMeterAutoRange()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.AutoRange'");
string str = m_transport->ReadReply();
int ret;
sscanf(str.c_str(), "%d", &ret);
return ret ? true : false;
}
void LeCroyOscilloscope::SetMeterAutoRange(bool enable)
{
lock_guard<recursive_mutex> lock(m_mutex);
if(enable)
m_transport->SendCommand("VBS 'app.acquisition.DVM.AutoRange = 1'");
else
m_transport->SendCommand("VBS 'app.acquisition.DVM.AutoRange = 0'");
}
void LeCroyOscilloscope::StartMeter()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS 'app.acquisition.DVM.DvmEnable = 1'");
}
void LeCroyOscilloscope::StopMeter()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS 'app.acquisition.DVM.DvmEnable = 0'");
}
double LeCroyOscilloscope::GetVoltage()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.Voltage'");
string str = m_transport->ReadReply();
double ret;
sscanf(str.c_str(), "%lf", &ret);
return ret;
}
double LeCroyOscilloscope::GetCurrent()
{
//DMM does not support current
return 0;
}
double LeCroyOscilloscope::GetTemperature()
{
//DMM does not support current
return 0;
}
double LeCroyOscilloscope::GetPeakToPeak()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.Amplitude'");
string str = m_transport->ReadReply();
double ret;
sscanf(str.c_str(), "%lf", &ret);
return ret;
}
double LeCroyOscilloscope::GetFrequency()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.Frequency'");
string str = m_transport->ReadReply();
double ret;
sscanf(str.c_str(), "%lf", &ret);
return ret;
}
int LeCroyOscilloscope::GetMeterChannelCount()
{
return m_analogChannelCount;
}
string LeCroyOscilloscope::GetMeterChannelName(int chan)
{
lock_guard<recursive_mutex> lock(m_mutex);
return m_channels[chan]->m_displayname;
}
int LeCroyOscilloscope::GetCurrentMeterChannel()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.DvmSource'");
string str = m_transport->ReadReply();
int i;
sscanf(str.c_str(), "C%d", &i);
return i - 1; //scope channels are 1 based
}
void LeCroyOscilloscope::SetCurrentMeterChannel(int chan)
{
lock_guard<recursive_mutex> lock(m_mutex);
char cmd[128];
snprintf(
cmd,
sizeof(cmd),
"VBS 'app.acquisition.DVM.DvmSource = \"C%d\"",
chan + 1); //scope channels are 1 based
m_transport->SendCommand(cmd);
}
Multimeter::MeasurementTypes LeCroyOscilloscope::GetMeterMode()
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("VBS? 'return = app.acquisition.DVM.DvmMode'");
string str = m_transport->ReadReply();
//trim off trailing whitespace
while(isspace(str[str.length()-1]))
str.resize(str.length() - 1);
if(str == "DC")
return Multimeter::DC_VOLTAGE;
else if(str == "DC RMS")
return Multimeter::DC_RMS_AMPLITUDE;
else if(str == "ACRMS")
return Multimeter::AC_RMS_AMPLITUDE;
else if(str == "Frequency")
return Multimeter::FREQUENCY;
else
{
LogError("Invalid meter mode \"%s\"\n", str.c_str());
return Multimeter::DC_VOLTAGE;
}
}
void LeCroyOscilloscope::SetMeterMode(Multimeter::MeasurementTypes type)
{
lock_guard<recursive_mutex> lock(m_mutex);
string stype;
switch(type)
{
case Multimeter::DC_VOLTAGE:
stype = "DC";
break;
case Multimeter::DC_RMS_AMPLITUDE:
stype = "DC RMS";
break;
case Multimeter::AC_RMS_AMPLITUDE:
stype = "ACRMS";
break;
case Multimeter::FREQUENCY:
stype = "Frequency";
break;
//not implemented, disable
case Multimeter::AC_CURRENT:
case Multimeter::DC_CURRENT:
case Multimeter::TEMPERATURE:
LogWarning("unsupported multimeter mode\n");
return;
}
char cmd[128];
snprintf(cmd, sizeof(cmd), "VBS 'app.acquisition.DVM.DvmMode = \"%s\"'", stype.c_str());
m_transport->SendCommand(cmd);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function generator mode
int LeCroyOscilloscope::GetFunctionChannelCount()
{
if(m_hasFunctionGen)
return 1;
else
return 0;
}
string LeCroyOscilloscope::GetFunctionChannelName(int /*chan*/)
{
return "FUNC";
}
bool LeCroyOscilloscope::GetFunctionChannelActive(int /*chan*/)
{
LogWarning("LeCroyOscilloscope::GetFunctionChannelActive unimplemented\n");
return false;
}
void LeCroyOscilloscope::SetFunctionChannelActive(int /*chan*/, bool on)
{
lock_guard<recursive_mutex> lock(m_mutex);
if(on)
m_transport->SendCommand("VBS 'app.wavesource.enable=True'");
else
m_transport->SendCommand("VBS 'app.wavesource.enable=False'");
}
float LeCroyOscilloscope::GetFunctionChannelDutyCycle(int /*chan*/)
{
//app.wavesource.dutycycle
LogWarning("LeCroyOscilloscope::GetFunctionChannelDutyCycle unimplemented\n");
return false;
}
void LeCroyOscilloscope::SetFunctionChannelDutyCycle(int /*chan*/, float /*duty*/)
{
//app.wavesource.dutycycle
}
float LeCroyOscilloscope::GetFunctionChannelAmplitude(int /*chan*/)
{
//app.wavesource.amplitude
LogWarning("LeCroyOscilloscope::GetFunctionChannelAmplitude unimplemented\n");
return 0;
}
void LeCroyOscilloscope::SetFunctionChannelAmplitude(int /*chan*/, float /*amplitude*/)
{
//app.wavesource.amplitude
}
float LeCroyOscilloscope::GetFunctionChannelOffset(int /*chan*/)
{
//app.wavesource.offset
LogWarning("LeCroyOscilloscope::GetFunctionChannelOffset unimplemented\n");
return 0;
}
void LeCroyOscilloscope::SetFunctionChannelOffset(int /*chan*/, float /*offset*/)
{
//app.wavesource.offset
}
float LeCroyOscilloscope::GetFunctionChannelFrequency(int /*chan*/)
{
//app.wavesource.frequency
LogWarning("LeCroyOscilloscope::GetFunctionChannelFrequency unimplemented\n");
return 0;
}
void LeCroyOscilloscope::SetFunctionChannelFrequency(int /*chan*/, float hz)
{
lock_guard<recursive_mutex> lock(m_mutex);
char tmp[128];
snprintf(tmp, sizeof(tmp), "VBS 'app.wavesource.frequency = %f'", hz);
m_transport->SendCommand(tmp);
}
FunctionGenerator::WaveShape LeCroyOscilloscope::GetFunctionChannelShape(int /*chan*/)
{
//app.wavesource.shape
LogWarning("LeCroyOscilloscope::GetFunctionChannelShape unimplemented\n");
return FunctionGenerator::SHAPE_SINE;
}
void LeCroyOscilloscope::SetFunctionChannelShape(int /*chan*/, WaveShape /*shape*/)
{
//app.wavesource.shape
}
float LeCroyOscilloscope::GetFunctionChannelRiseTime(int /*chan*/)
{
//app.wavesource.risetime
LogWarning("LeCroyOscilloscope::GetFunctionChannelRiseTime unimplemented\n");
return 0;
}
void LeCroyOscilloscope::SetFunctionChannelRiseTime(int /*chan*/, float sec)
{
lock_guard<recursive_mutex> lock(m_mutex);
char tmp[128];
snprintf(tmp, sizeof(tmp), "VBS 'app.wavesource.risetime = %f'", sec);
m_transport->SendCommand(tmp);
}
float LeCroyOscilloscope::GetFunctionChannelFallTime(int /*chan*/)
{
//app.wavesource.falltime
LogWarning("LeCroyOscilloscope::GetFunctionChannelFallTime unimplemented\n");
return 0;
}
void LeCroyOscilloscope::SetFunctionChannelFallTime(int /*chan*/, float sec)
{
lock_guard<recursive_mutex> lock(m_mutex);
char tmp[128];
snprintf(tmp, sizeof(tmp), "VBS 'app.wavesource.falltime = %f'", sec);
m_transport->SendCommand(tmp);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Triggering
void LeCroyOscilloscope::ResetTriggerConditions()
{
//FIXME
}
bool LeCroyOscilloscope::IsTriggerArmed()
{
return m_triggerArmed;
}
Oscilloscope::TriggerMode LeCroyOscilloscope::PollTrigger()
{
//LogDebug("Polling trigger\n");
//Read the Internal State Change Register
string sinr;
{
lock_guard<recursive_mutex> lock(m_mutex);
m_transport->SendCommand("INR?");
sinr = m_transport->ReadReply();
}
//LogDebug("Got trigger state\n");
int inr = atoi(sinr.c_str());
//See if we got a waveform
if(inr & 0x0001)
{
m_triggerArmed = false;
return TRIGGER_MODE_TRIGGERED;
}
//No waveform, but ready for one?
if(inr & 0x2000)
{
m_triggerArmed = true;
return TRIGGER_MODE_RUN;
}
//Stopped, no data available
//TODO: how to handle auto / normal trigger mode?
return TRIGGER_MODE_RUN;
}
bool LeCroyOscilloscope::ReadWaveformBlock(string& data)