-
Notifications
You must be signed in to change notification settings - Fork 78
/
SiglentSCPIOscilloscope.cpp
4981 lines (4346 loc) · 133 KB
/
SiglentSCPIOscilloscope.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
/***********************************************************************************************************************
* *
* libscopehal v0.1 *
* *
* Copyright (c) 2012-2023 Andrew D. Zonenberg and contributors *
* 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. *
* *
***********************************************************************************************************************/
/*
* Generic Siglent scope driver. Currently supports SDS2000X+ and SDS1104X-E.
* This file was originally derived from the LeCroy driver but has been modified extensively.
* Note that this port replaces the previous Siglent driver, which was non-functional. That is available in the git
* archive if needed.
*
* SDS2000/5000/6000 port (c) 2021 Dave Marples.
* Tested on SDS2000X+. If someone wants to loan an SDS5000/6000A/6000Pro for testing those
* can be integrated and the changes required should be limited.
*
* Starting SDS1x04X-E port (c) 2021 Dannes and Stefan Mandl
* Using Programming Guide PG01-E02D an Firmware 6.1.37R8
* Tested on SDS1104X-E. Should also support SDS10000CML+/CNL+/Dl+/E+/F+, SDS2000/2000x, SDS1000x/1000x+,
* SDS1000X-E/X-C but these are untested. Feedback and/or loan instruments appreciated.
*
*
* Current State
* =============
*
* SDS2000XP
*
* - Basic functionality for analog channels works.
* - There is no feature detection because the scope does not support *OPT? (Request made)
* - Digital channels are not implemented (code in here is leftover from LeCroy)
* - Triggers are untested.
* - Sampling lengths up to 10MSamples are supported. 50M and 100M need to be batched and will be
* horribly slow.
*
* SDS1104X-E
*
* Using Programming Guide PG01-E02D and Firmware 6.2.37R8
* receive data from scope on c1 c2 c3 c4
* set EDGE Trigger on channel
* using 4 Channels ( 70 kS 25 MS/s) got 4,23 WFM/s
* using 4 Channels ( 700 kpts 100 MSa/s) got 1,62 WFM/s
* using 1 Channels ( 1.75 Mpts 250 MSa/s) got 2,38 WFM/s
* using 4 Channels ( 3.5 Mpts 500 MSa/s) got 0,39 WFM/s
*
* TODO Click "Reload configuration from scope" sometimes we loosing WAVE rendering ( threading issue ?)
* TODO sometimes socket timeout (Warning: Socket read failed errno=11 errno=4)
*
* Note that this port replaces the previous Siglent driver, which was non-functional. That is available in the git
* archive if needed.
*/
#include "scopehal.h"
#include "SiglentSCPIOscilloscope.h"
#include "base64.h"
#include <locale>
#include <stdarg.h>
#include <omp.h>
#include <thread>
#include <chrono>
#include "DropoutTrigger.h"
#include "EdgeTrigger.h"
#include "PulseWidthTrigger.h"
#include "RuntTrigger.h"
#include "SlewRateTrigger.h"
#include "UartTrigger.h"
#include "WindowTrigger.h"
using namespace std;
static const struct
{
const char* name;
float val;
} c_sds2000xp_threshold_table[] = {{"TTL", 1.5F}, {"CMOS", 1.65F}, {"LVCMOS33", 1.65F}, {"LVCMOS25", 1.25F}, {NULL, 0}};
static const std::chrono::milliseconds c_trigger_delay(1000); // Delay required when forcing trigger
static const std::chrono::milliseconds c_adc_delay(200); // Delay required when setting ADC mode
static const char* c_custom_thresh = "CUSTOM,"; // Prepend string for custom digital threshold
static const float c_thresh_thresh = 0.01f; // Zero equivalence threshold for fp comparisons
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction
SiglentSCPIOscilloscope::SiglentSCPIOscilloscope(SCPITransport* transport)
: SCPIDevice(transport)
, SCPIInstrument(transport)
, m_hasLA(false)
, m_hasDVM(false)
, m_hasFunctionGen(false)
, m_hasFastSampleRate(false)
, m_memoryDepthOption(0)
, m_hasI2cTrigger(false)
, m_hasSpiTrigger(false)
, m_hasUartTrigger(false)
, m_maxBandwidth(10000)
, 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)
{
//Enable command rate limiting
//TODO: only for some firmware versions or instrument SKUs?
transport->EnableRateLimiting(chrono::milliseconds(50));
//standard initialization
FlushConfigCache();
IdentifyHardware();
DetectAnalogChannels();
SharedCtorInit();
DetectOptions();
//Figure out if scope is in low or high bit depth mode so we can download waveforms with the correct format
GetADCMode(0);
}
string SiglentSCPIOscilloscope::converse(const char* fmt, ...)
{
string ret;
char opString[128];
va_list va;
va_start(va, fmt);
vsnprintf(opString, sizeof(opString), fmt, va);
va_end(va);
ret = m_transport->SendCommandQueuedWithReply(opString, false);
return ret;
}
void SiglentSCPIOscilloscope::sendOnly(const char* fmt, ...)
{
char opString[128];
va_list va;
va_start(va, fmt);
vsnprintf(opString, sizeof(opString), fmt, va);
va_end(va);
m_transport->SendCommandQueued(opString);
}
void SiglentSCPIOscilloscope::SharedCtorInit()
{
m_digitalChannelCount = 0;
//Add the external trigger input
m_extTrigChannel =
new OscilloscopeChannel(
this,
"EX",
"",
Unit(Unit::UNIT_FS),
Unit(Unit::UNIT_VOLTS),
Stream::STREAM_TYPE_TRIGGER,
m_channels.size());
m_channels.push_back(m_extTrigChannel);
//Add the function generator output
if(m_hasFunctionGen)
{
//TODO: this is stupid, it shares the same name as our scope input!
//Is this going to break anything??
m_awgChannel = new FunctionGeneratorChannel(this, "C1", "#808080", m_channels.size());
m_channels.push_back(m_awgChannel);
m_awgChannel->SetDisplayName("AWG");
}
else
m_awgChannel = nullptr;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
// Omit header and units in numbers for responses to queries.
sendOnly("CHDR OFF");
// change momory size to 14K. less data on the network
SetSampleDepth(14000);
// ToDo fix render we get this imformation sometimes late
// then we miss channel in GUI. Workaround ....
GetChannelVoltageRange(0, 0);
GetChannelVoltageRange(1, 0);
GetChannelVoltageRange(2, 0);
GetChannelVoltageRange(3, 0);
GetChannelOffset(0, 0);
GetChannelOffset(1, 0);
GetChannelOffset(2, 0);
GetChannelOffset(3, 0);
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
//This is the default behavior, but it's safer to explicitly specify it
//TODO: save bandwidth and simplify parsing by doing OFF
sendOnly("CHDR SHORT");
//Desired format for waveform data
//Only use increased bit depth if the scope actually puts content there!
sendOnly(":WAVEFORM:WIDTH %s", m_highDefinition ? "WORD" : "BYTE");
break;
case MODEL_SIGLENT_SDS2000X_HD:
sendOnly("CHDR SHORT");
sendOnly(":WAVEFORM:WIDTH WORD");
break;
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
sendOnly("CHDR SHORT");
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
//Controlled memory depth, adjust sample rate based on this
if(m_modelid == MODEL_SIGLENT_SDS6000A)
sendOnly("ACQ:MMAN FMDepth");
//Clear the state-change register to we get rid of any history we don't care about
PollTrigger();
//Enable deduplication for vertical axis commands once we know what we're dealing with
switch(m_modelid)
{
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
m_transport->DeduplicateCommand("OFST");
m_transport->DeduplicateCommand("VOLT_DIV");
break;
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
m_transport->DeduplicateCommand("OFFSET");
m_transport->DeduplicateCommand("SCALE");
break;
default:
break;
}
}
void SiglentSCPIOscilloscope::IdentifyHardware()
{
//Ask for the ID
string reply = converse("*IDN?");
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;
m_maxBandwidth = 0;
m_requireSizeWorkaround = false;
if(m_vendor.compare("Siglent Technologies") == 0)
{
// TODO(dannas): Tighten this check
// The Programming Guide says that we support SDS1000CFL, SDS1000A,
// SDS10000CML+/CNL+/Dl+/E+/F+, SDS2000/2000x, SDS1000x/1000x+,
// SDS1000X-E/X-C. But I only have a SDS1004X-E so we should only check for that
if(m_model.compare(0, 4, "SDS1") == 0)
{
m_modelid = MODEL_SIGLENT_SDS1000;
m_maxBandwidth = 100;
if(m_model.compare(4, 1, "2") == 0)
m_maxBandwidth = 200;
if(m_fwVersion != "8.2.6.1.37R9")
LogWarning("Siglent firmware \"%s\" is not tested\n", m_fwVersion.c_str());
return;
}
else if(m_model.compare(0, 4, "SDS2") == 0 && m_model.back() == 'E')
{
m_modelid = MODEL_SIGLENT_SDS2000XE;
m_maxBandwidth = 100;
if(m_model.compare(4, 1, "2") == 0)
m_maxBandwidth = 200;
else if(m_model.compare(4, 1, "3") == 0)
m_maxBandwidth = 350;
if(m_model.compare(4, 1, "5") == 0)
m_maxBandwidth = 500;
return;
}
else if(m_model.compare(0, 4, "SDS2") == 0 && m_model.back() == 's')
{
m_modelid = MODEL_SIGLENT_SDS2000XP;
m_maxBandwidth = 100;
if(m_model.compare(4, 1, "2") == 0)
m_maxBandwidth = 200;
else if(m_model.compare(4, 1, "3") == 0)
m_maxBandwidth = 350;
if(m_model.compare(4, 1, "5") == 0)
m_maxBandwidth = 500;
//Check if version requires size workaround (1.3.9R6 and older)
int ubootMajorVersion;
int ubootMinorVersion;
int fwMajorVersion;
int fwMinorVersion;
int fwPatchVersion;
int fwPatchRevision;
sscanf(m_fwVersion.c_str(), "%d.%d.%d.%d.%dR%d",
&ubootMajorVersion,
&ubootMinorVersion,
&fwMajorVersion,
&fwMinorVersion,
&fwPatchVersion,
&fwPatchRevision);
//Firmware 1.3.9R6 and older require size workaround.
//TODO: validate with scope with older versions
if(fwMajorVersion < 1)
m_requireSizeWorkaround = true;
else if((fwMajorVersion == 1) && (fwMinorVersion < 3))
m_requireSizeWorkaround = true;
else if((fwMajorVersion == 1) && (fwMinorVersion == 3) && (fwPatchVersion < 9))
m_requireSizeWorkaround = true;
else if((fwMajorVersion == 1) && (fwMinorVersion == 3) && (fwPatchVersion == 9) && (fwPatchRevision <= 6))
m_requireSizeWorkaround = true;
if(m_requireSizeWorkaround)
LogTrace("Current firmware (%s) requires size workaround\n", m_fwVersion.c_str());
//TODO: check for whether we actually have the license
//(no SCPI command for this yet)
m_hasFunctionGen = true;
}
else if( (m_model.compare(0, 4, "SDS2") == 0) && (m_model.find("HD") != string::npos) )
{
m_maxBandwidth = 100;
if(m_model.compare(4, 1, "2") == 0)
m_maxBandwidth = 200;
else if(m_model.compare(4, 1, "3") == 0)
m_maxBandwidth = 350;
//no 500 MHz HD model
//TODO: check for whether we actually have the license
//(no SCPI command for this yet)
m_hasFunctionGen = true;
//2000X+ HD is native 12 bit resolution (and has no 8 bit mode)
m_highDefinition = true;
m_modelid = MODEL_SIGLENT_SDS2000X_HD;
}
else if(m_model.compare(0, 4, "SDS5") == 0)
{
m_modelid = MODEL_SIGLENT_SDS5000X;
m_maxBandwidth = 350;
if(m_model.compare(5, 1, "5") == 0)
m_maxBandwidth = 500;
if(m_model.compare(5, 1, "0") == 0)
m_maxBandwidth = 1000;
}
else if(m_model.compare(0, 4, "SDS6") == 0)
{
m_modelid = MODEL_SIGLENT_SDS6000A;
m_maxBandwidth = 500;
if(m_model.compare(4, 1, "1") == 0)
m_maxBandwidth = 1000;
if(m_model.compare(4, 2, "2") == 0)
m_maxBandwidth = 2000;
}
else
{
LogWarning("Model \"%s\" is unknown, available sample rates/memory depths may not be properly detected\n",
m_model.c_str());
}
}
else
{
LogWarning("Vendor \"%s\" is unknown\n", m_vendor.c_str());
}
}
void SiglentSCPIOscilloscope::DetectOptions()
{
//AddDigitalChannels(16);
/* SDS2000XP has no capability to find the options :-( */
return;
}
/**
@brief Creates digital channels for the oscilloscope
*/
void SiglentSCPIOscilloscope::AddDigitalChannels(unsigned int count)
{
m_digitalChannelCount = count;
m_digitalChannelBase = m_channels.size();
char chn[32];
for(unsigned int i = 0; i < count; i++)
{
snprintf(chn, sizeof(chn), "D%u", i);
auto chan = new OscilloscopeChannel(
this,
chn,
GetDefaultChannelColor(m_channels.size()),
Unit(Unit::UNIT_FS),
Unit(Unit::UNIT_COUNTS),
Stream::STREAM_TYPE_DIGITAL,
m_channels.size());
m_channels.push_back(chan);
m_digitalChannels.push_back(chan);
}
}
/**
@brief Figures out how many analog channels we have, and add them to the device
*/
void SiglentSCPIOscilloscope::DetectAnalogChannels()
{
int nchans = 1;
// Char 7 of the model name is the number of channels
if(m_model.length() > 7)
{
switch(m_model[6])
{
case '2':
nchans = 2;
break;
case '4':
nchans = 4;
break;
}
}
for(int i = 0; i < nchans; i++)
{
//Hardware name of the channel
string chname = string("C") + to_string(i+1);
//Color the channels based on Siglents standard color sequence
//yellow-pink-cyan-green-lightgreen
string color = "#ffffff";
switch(i % 4)
{
case 0:
color = "#ffff00";
break;
case 1:
color = "#ff6abc";
break;
case 2:
color = "#00ffff";
break;
case 3:
color = "#00c100";
break;
}
//Create the channel
m_channels.push_back(
new OscilloscopeChannel(
this,
chname,
color,
Unit(Unit::UNIT_FS),
Unit(Unit::UNIT_VOLTS),
Stream::STREAM_TYPE_ANALOG,
i));
}
m_analogChannelCount = nchans;
}
SiglentSCPIOscilloscope::~SiglentSCPIOscilloscope()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device information
string SiglentSCPIOscilloscope::GetDriverNameInternal()
{
return "siglent";
}
OscilloscopeChannel* SiglentSCPIOscilloscope::GetExternalTrigger()
{
return m_extTrigChannel;
}
void SiglentSCPIOscilloscope::FlushConfigCache()
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
if(m_trigger)
delete m_trigger;
m_trigger = NULL;
m_channelVoltageRanges.clear();
m_channelOffsets.clear();
m_channelsEnabled.clear();
m_channelDeskew.clear();
m_probeIsActive.clear();
m_sampleRateValid = false;
m_memoryDepthValid = false;
m_triggerOffsetValid = false;
m_meterModeValid = false;
m_awgEnabled.clear();
m_awgDutyCycle.clear();
m_awgRange.clear();
m_awgOffset.clear();
m_awgFrequency.clear();
m_awgShape.clear();
m_awgImpedance.clear();
m_adcModeValid = false;
//Clear cached display name of all channels
for(auto c : m_channels)
{
if(GetInstrumentTypesForChannel(c->GetIndex()) & Instrument::INST_OSCILLOSCOPE)
c->ClearCachedDisplayName();
}
}
/**
@brief See what measurement capabilities we have
*/
unsigned int SiglentSCPIOscilloscope::GetMeasurementTypes()
{
unsigned int type = 0;
return type;
}
/**
@brief See what features we have
*/
unsigned int SiglentSCPIOscilloscope::GetInstrumentTypes() const
{
unsigned int type = INST_OSCILLOSCOPE;
if(m_hasFunctionGen)
type |= INST_FUNCTION;
return type;
}
uint32_t SiglentSCPIOscilloscope::GetInstrumentTypesForChannel(size_t i) const
{
if(m_awgChannel && (m_awgChannel->GetIndex() == i) )
return Instrument::INST_FUNCTION;
//If we get here, it's an oscilloscope channel
return Instrument::INST_OSCILLOSCOPE;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Channel configuration
bool SiglentSCPIOscilloscope::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];
}
//Analog
if(i < m_analogChannelCount)
{
//See if the channel is enabled, hide it if not
string reply;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
reply = converse("C%d:TRACE?", i + 1);
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelsEnabled[i] = (reply.find("OFF") != 0); //may have a trailing newline, ignore that
}
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
reply = converse(":CHANNEL%d:SWITCH?", i + 1);
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelsEnabled[i] = (reply.find("OFF") != 0); //may have a trailing newline, ignore that
}
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
}
else
{
//Digital
//See if the channel is on
size_t nchan = i - (m_analogChannelCount + 1);
string str = converse(":DIGITAL:D%d?", nchan);
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelsEnabled[i] = (str == "OFF") ? false : true;
}
lock_guard<recursive_mutex> lock2(m_cacheMutex);
return m_channelsEnabled[i];
}
void SiglentSCPIOscilloscope::EnableChannel(size_t i)
{
bool wasInterleaving = IsInterleaving();
//No need to lock the main mutex since sendOnly now pushes to the queue
//If this is an analog channel, just toggle it
if(i < m_analogChannelCount)
{
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
sendOnly(":C%d:TRACE ON", i + 1);
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
sendOnly(":CHANNEL%d:SWITCH ON", i + 1);
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
}
else if(i == m_extTrigChannel->GetIndex())
{
//Trigger can't be enabled
}
else
{
//Digital channel
sendOnly(":DIGITAL:D%d ON", i - (m_analogChannelCount + 1));
}
lock_guard<recursive_mutex> lock(m_cacheMutex);
m_channelsEnabled[i] = true;
//Sample rate and memory depth can change if interleaving state changed
if(IsInterleaving() != wasInterleaving)
{
m_memoryDepthValid = false;
m_sampleRateValid = false;
}
}
bool SiglentSCPIOscilloscope::CanEnableChannel(size_t i)
{
// Can enable all channels except trigger
return !(i == m_extTrigChannel->GetIndex());
}
void SiglentSCPIOscilloscope::DisableChannel(size_t i)
{
bool wasInterleaving = IsInterleaving();
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
m_channelsEnabled[i] = false;
}
if(i < m_analogChannelCount)
{
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
sendOnly("C%d:TRACE OFF", i + 1);
break;
// -------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
//If this is an analog channel, just toggle it
if(i < m_analogChannelCount)
sendOnly(":CHANNEL%d:SWITCH OFF", i + 1);
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
}
else if(i == m_extTrigChannel->GetIndex())
{
//Trigger can't be enabled
}
else
{
//Digital channel
//Disable this channel
sendOnly(":DIGITAL:D%d OFF", i - (m_analogChannelCount + 1));
//If we have NO digital channels enabled, disable the appropriate digital bus
//bool anyDigitalEnabled = false;
// for (uint32_t c=m_analogChannelCount+1+((chNum/8)*8); c<(m_analogChannelCount+1+((chNum/8)*8)+c_digiChannelsPerBus); c++)
// anyDigitalEnabled |= m_channelsEnabled[c];
// if(!anyDigitalEnabled)
//sendOnly(":DIGITAL:BUS%d:DISP OFF",chNum/8);
}
//Sample rate and memory depth can change if interleaving state changed
if(IsInterleaving() != wasInterleaving)
{
m_memoryDepthValid = false;
m_sampleRateValid = false;
}
}
vector<OscilloscopeChannel::CouplingType> SiglentSCPIOscilloscope::GetAvailableCouplings(size_t /*i*/)
{
vector<OscilloscopeChannel::CouplingType> ret;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
ret.push_back(OscilloscopeChannel::COUPLE_DC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_AC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_GND);
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
ret.push_back(OscilloscopeChannel::COUPLE_DC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_AC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_DC_50);
ret.push_back(OscilloscopeChannel::COUPLE_AC_50);
ret.push_back(OscilloscopeChannel::COUPLE_GND);
break;
//SDS6000A does not support 50 ohm AC coupling
case MODEL_SIGLENT_SDS6000A:
ret.push_back(OscilloscopeChannel::COUPLE_DC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_AC_1M);
ret.push_back(OscilloscopeChannel::COUPLE_DC_50);
ret.push_back(OscilloscopeChannel::COUPLE_GND);
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
return ret;
}
OscilloscopeChannel::CouplingType SiglentSCPIOscilloscope::GetChannelCoupling(size_t i)
{
if(i >= m_analogChannelCount)
return OscilloscopeChannel::COUPLE_SYNTHETIC;
string replyType;
string replyImp;
m_probeIsActive[i] = false;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
replyType = Trim(converse("C%d:COUPLING?", i + 1));
if(replyType == "A50")
return OscilloscopeChannel::COUPLE_AC_50;
else if(replyType == "D50")
return OscilloscopeChannel::COUPLE_DC_50;
else if(replyType == "A1M")
return OscilloscopeChannel::COUPLE_AC_1M;
else if(replyType == "D1M")
return OscilloscopeChannel::COUPLE_DC_1M;
else if(replyType == "GND")
return OscilloscopeChannel::COUPLE_GND;
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
replyType = Trim(converse(":CHANNEL%d:COUPLING?", i + 1).substr(0, 2));
replyImp = Trim(converse(":CHANNEL%d:IMPEDANCE?", i + 1).substr(0, 3));
if(replyType == "AC")
return (replyImp.find("FIF") == 0) ? OscilloscopeChannel::COUPLE_AC_50 : OscilloscopeChannel::COUPLE_AC_1M;
else if(replyType == "DC")
return (replyImp.find("FIF") == 0) ? OscilloscopeChannel::COUPLE_DC_50 : OscilloscopeChannel::COUPLE_DC_1M;
else if(replyType == "GN")
return OscilloscopeChannel::COUPLE_GND;
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
//invalid
LogWarning("SiglentSCPIOscilloscope::GetChannelCoupling got invalid coupling [%s] [%s]\n",
replyType.c_str(),
replyImp.c_str());
return OscilloscopeChannel::COUPLE_SYNTHETIC;
}
void SiglentSCPIOscilloscope::SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type)
{
if(i >= m_analogChannelCount)
return;
//Get the old coupling value first.
//This ensures that m_probeIsActive[i] is valid
GetChannelCoupling(i);
//If we have an active probe, don't touch the hardware config
if(m_probeIsActive[i])
return;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
switch(type)
{
case OscilloscopeChannel::COUPLE_AC_50:
sendOnly("C%d:COUPLING %s", i + 1, "A50");
break;
case OscilloscopeChannel::COUPLE_DC_50:
sendOnly("C%d:COUPLING %s", i + 1, "D50");
break;
case OscilloscopeChannel::COUPLE_AC_1M:
sendOnly("C%d:COUPLING %s", i + 1, "A1M");
break;
case OscilloscopeChannel::COUPLE_DC_1M:
sendOnly("C%d:COUPLING %s", i + 1, "D1M");
break;
//treat unrecognized as ground
case OscilloscopeChannel::COUPLE_GND:
default:
sendOnly("C%d:COUPLING %s", i + 1, "GND");
break;
}
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
switch(type)
{
case OscilloscopeChannel::COUPLE_AC_1M:
sendOnly(":CHANNEL%d:COUPLING AC", i + 1);
sendOnly(":CHANNEL%d:IMPEDANCE ONEMEG", i + 1);
break;
case OscilloscopeChannel::COUPLE_DC_1M:
sendOnly(":CHANNEL%d:COUPLING DC", i + 1);
sendOnly(":CHANNEL%d:IMPEDANCE ONEMEG", i + 1);
break;
case OscilloscopeChannel::COUPLE_DC_50:
sendOnly(":CHANNEL%d:COUPLING DC", i + 1);
sendOnly(":CHANNEL%d:IMPEDANCE FIFTY", i + 1);
break;
case OscilloscopeChannel::COUPLE_AC_50:
sendOnly(":CHANNEL%d:COUPLING AC", i + 1);
sendOnly(":CHANNEL%d:IMPEDANCE FIFTY", i + 1);
break;
//treat unrecognized as ground
case OscilloscopeChannel::COUPLE_GND:
default:
sendOnly(":CHANNEL%d:COUPLING GND", i + 1);
break;
}
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}
}
double SiglentSCPIOscilloscope::GetChannelAttenuation(size_t i)
{
if(i > m_analogChannelCount)
return 1;
//TODO: support ext/10
if(i == m_extTrigChannel->GetIndex())
return 1;
string reply;
switch(m_modelid)
{
// --------------------------------------------------
case MODEL_SIGLENT_SDS1000:
case MODEL_SIGLENT_SDS2000XE:
reply = converse("C%d:ATTENUATION?", i + 1);
break;
// --------------------------------------------------
case MODEL_SIGLENT_SDS2000XP:
case MODEL_SIGLENT_SDS2000X_HD:
case MODEL_SIGLENT_SDS5000X:
case MODEL_SIGLENT_SDS6000A:
reply = converse(":CHANNEL%d:PROBE?", i + 1);
break;
// --------------------------------------------------
default:
LogError("Unknown scope type\n");
break;
// --------------------------------------------------
}