Newer
Older
// ============================================================================
//
// = CONTEXT
// TANGO Project - DDC KeithleyDDCProtocol Support Library
//
// = FILENAME
// KeithleyDDCProtocol.cpp
//
// = AUTHOR
// X. Elattaoui
//
// ============================================================================
// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include "KeithleyDDCProtocol.h"
#include "TangoGpibLink.h"
// ============================================================================
// KeithleyDDCProtocol::KeithleyDDCProtocol
// ============================================================================
KeithleyDDCProtocol::KeithleyDDCProtocol (std::string& gpib_device_name)
: ElectrometerProtocol(),
{
std::cout << "KeithleyDDCProtocol::KeithleyDDCProtocol <-" << std::endl;
std::cout << "KeithleyDDCProtocol::KeithleyDDCProtocol ->" << std::endl;
}
// ============================================================================
// KeithleyDDCProtocol::~KeithleyDDCProtocol
// ============================================================================
KeithleyDDCProtocol::~KeithleyDDCProtocol (void)
{
std::cout << "KeithleyDDCProtocol::~KeithleyDDCProtocol <-" << std::endl;
std::cout << "KeithleyDDCProtocol::~KeithleyDDCProtocol ->" << std::endl;
}
// ============================================================================
// KeithleyDDCProtocol::build_communicationLink
// ============================================================================
bool KeithleyDDCProtocol::build_communicationLink()
{
if (_commDevName.empty())
return false;
_communication_link = new TangoGpibLink (_commDevName);
if (!_communication_link)
return false;
//- Read data with no prefix
this->disable_readingWithPrefix();
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
// ============================================================================
// KeithleyDDCProtocol::set_range
// ============================================================================
void KeithleyDDCProtocol::set_range (std::string value)
{
std::stringstream cmd_to_send;
//- send command to Keithley device
cmd_to_send << "R" << value << "X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::get_range
// ============================================================================
std::string KeithleyDDCProtocol::get_range (void)
{
throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED",
"For DDC Keithley type, please check the status.",
"KeithleyDDCProtocol::get_range( ).");
}
// ============================================================================
// KeithleyDDCProtocol::zero_check_on
// ============================================================================
void KeithleyDDCProtocol::zero_check_on (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "C1X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::zero_check_off
// ============================================================================
void KeithleyDDCProtocol::zero_check_off (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "C0X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::zero_correct_on
// ============================================================================
void KeithleyDDCProtocol::zero_correct_on (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "Z1X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::zero_correct_off
// ============================================================================
void KeithleyDDCProtocol::zero_correct_off (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "Z0X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::auto_zero_on
// ============================================================================
void KeithleyDDCProtocol::auto_zero_on (void)
{
throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED",
"DDC Keithley does not support this command.",
"KeithleyDDCProtocol::auto_zero_on( ).");
}
// ============================================================================
// KeithleyDDCProtocol::auto_zero_off
// ============================================================================
void KeithleyDDCProtocol::auto_zero_off (void)
{
throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED",
"DDC Keithley does not support this command.",
"KeithleyDDCProtocol::auto_zero_off( ).");
}
// ============================================================================
// KeithleyDDCProtocol::autoRange_ON
// ============================================================================
void KeithleyDDCProtocol::autoRange_on (void)
{
std::stringstream cmd_to_send;
cmd_to_send << "R0X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::autoRange_OFF
// ============================================================================
void KeithleyDDCProtocol::autoRange_off (void)
{
throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED",
"DDC Keithley does not support this command.",
"KeithleyDDCProtocol::autoRange_off( ).");
}
// ============================================================================
// KeithleyDDCProtocol::autoRange_OFF for Keithley 486 & 487
// ============================================================================
void KeithleyDDCProtocol::autoRange_OFF_forK486_487 (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "R10X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::autoRange_OFF for Keithley 617 & 6512
// ============================================================================
void KeithleyDDCProtocol::autoRange_OFF_forK617_6512 (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "R12X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::MODE -> Ampere, Volt, Ohm, Coulomb and V on I meters
// ============================================================================
// ============================================================================
// KeithleyDDCProtocol::setAmperMeterMode (617 & 6512 Keithley DDC models
// ============================================================================
void KeithleyDDCProtocol::setAmperMeterMode (void)
{
std::stringstream cmd_to_send;
//- mode current
_mode = "CURRent";
//- send command
cmd_to_send << "F1X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setAmperMeterMode (487 Keithley DDC model
// ============================================================================
void KeithleyDDCProtocol::setAmperMeterMode_forK487 (void)
{
std::stringstream cmd_to_send;
//- mode current
_mode = "CURRent";
//- send command
cmd_to_send << "F0X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setVoltMeterMode (617 & 6512 Keithley DDC models
// ============================================================================
void KeithleyDDCProtocol::setVoltMeterMode (void)
{
std::stringstream cmd_to_send;
//- mode volt
_mode = "VOLTage";
//- send command
cmd_to_send << "F0X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setOhmMeterMode (617 & 6512 Keithley DDC models
// ============================================================================
void KeithleyDDCProtocol::setOhmMeterMode (void)
{
std::stringstream cmd_to_send;
//- send command
//- mode ohm
_mode = "RESistance";
cmd_to_send << "F2X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setCoulombMeterMode (617 & 6512 Keithley DDC models
// ============================================================================
void KeithleyDDCProtocol::setCoulombMeterMode (void)
{
std::stringstream cmd_to_send;
//- mode coulomb
_mode = "CHARge";
//- send command
cmd_to_send << "F3X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::get_value
// ============================================================================
std::string KeithleyDDCProtocol::get_value (void)
{
std::stringstream cmd_to_send;
std::string argout("no data");
//- send command : G0X -> prefix (to check if device overload !) and second X to get data
//this->disable_readingWithPrefix();
//- get data value
cmd_to_send << "X" << std::ends;
_communication_link->write(cmd_to_send.str());
argout = _communication_link->read();
std::cout << "KeithleyDDCProtocol::get_value = " << argout << std::endl;
// cmd_to_send << "G1X" << std::ends;
// _communication_link->write(cmd_to_send.str());
//if(argout[0] == 'O')
// _is_overloaded = true;
//else
// _is_overloaded = false;
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
// ============================================================================
// KeithleyDDCProtocol::get_integratedValue
// ============================================================================
std::vector<double> KeithleyDDCProtocol::get_integratedValue (void)
{
std::string tmp("");
//- This command queries the bufferised values after an integration
tmp = _communication_link->read();
//- extract all data
return buildDataList(tmp);
}
// ============================================================================
// KeithleyDDCProtocol::get_fetchValue
// ============================================================================
std::vector<double> KeithleyDDCProtocol::get_fetchValue (void)
{
std::string tmp("");
//- This command queries the last bufferised value(s)
tmp = _communication_link->read();
//- extract all data
return buildDataList(tmp);
}
// ============================================================================
// KeithleyDDCProtocol::buildDataList
//
// This method extract and convert data from the received string
// ============================================================================
std::vector<double> KeithleyDDCProtocol::buildDataList(std::string datalist)
{
std::string dataStr("");
std::vector<double> argout;
std::string::size_type posBeg;
std::string::size_type posEnd;
//- there is just one value
if(posEnd == std::string::npos)
{
argout.push_back( XString<double>::convertFromString(datalist) );
}
else
{
for(; posEnd != std::string::npos; )
{
dataStr = datalist.substr(posBeg,posEnd);
argout.push_back( XString<double>::convertFromString(dataStr) );
posBeg = posEnd+1;
posEnd = datalist.find(',', posBeg);
//- end of string reached so latest data is here
if(posEnd == std::string::npos)
{
dataStr = datalist.substr(posBeg);
argout.push_back( XString<double>::convertFromString(dataStr) );
break;
}
}
}
return argout;
}
// ============================================================================
// KeithleyDDCProtocol::reset
// ============================================================================
void KeithleyDDCProtocol::reset (void)
{
std::stringstream cmd_to_send;
cmd_to_send << "*RST" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::get_raw_status
// ============================================================================
std::string KeithleyDDCProtocol::get_raw_status (void)
{
std::stringstream cmd_to_send;
std::string argout("no data");
//- send command : G0X -> show prefix ( = keithley type )
std::cout << "KeithleyDDCProtocol::get_raw_status returns *" << argout << "*" << std::ends;
// this->disable_readingWithPrefix();
// ============================================================================
// KeithleyDDCProtocol::get_DDC_configuration
// ============================================================================
std::string KeithleyDDCProtocol::get_DDC_configuration (void)
{
std::stringstream cmd_to_send;
std::string argout("no data");
//- send command : G0X -> show prefix ( = keithley type )
cmd_to_send.str("");
//- get status word
cmd_to_send << "U0X" << std::endl;
argout = _communication_link->write_read(cmd_to_send.str());
std::cout << "KeithleyDDCProtocol::get_DDC_configuration returns *" << argout << "*" << std::ends;
//this->disable_readingWithPrefix();
// ============================================================================
// KeithleyDDCProtocol::clear_registers
// ============================================================================
void KeithleyDDCProtocol::clear_registers (void)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "*CLS" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::set_buffer_size()
// ============================================================================
void KeithleyDDCProtocol::set_buffer_size (std::string cmd)
{
//- send command
_communication_link->write(cmd);
}
// ============================================================================
// ============================================================================
void KeithleyDDCProtocol::set_triggerMode (std::string cmd)
{
//- send command
_communication_link->write(cmd);
}
// ============================================================================
// KeithleyDDCProtocol::enable_SRQBufferFull()
// ============================================================================
void KeithleyDDCProtocol::enable_SRQBufferFull (void)
{
std::string cmd_to_send("M2X");
//- send command : enable buffer full in the Measurement event enable register
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::disable_SRQBufferFull()
// ============================================================================
void KeithleyDDCProtocol::disable_SRQBufferFull (void)
{
std::string cmd_to_send("M0X");
//- send command : disable buffer full event
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::SRQLineState()
// ============================================================================
bool KeithleyDDCProtocol::SRQLineState (void)
{
//- if asserted -> the programmed event occurs : the device can be asked !
return _communication_link->SRQLineState();
}
// ============================================================================
// KeithleyDDCProtocol::readStatusByteRegister()
// ============================================================================
{
//- if asserted -> the programmed event occurs : the device can be asked !
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
}
// ============================================================================
// KeithleyDDCProtocol::set_conversionRate()
// ============================================================================
void KeithleyDDCProtocol::set_conversionRate (void)
{
std::string cmd_to_send("Q0X");
//- send command : ADC default conversion rate
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::enable_readingWithPrefix()
// ============================================================================
void KeithleyDDCProtocol::enable_readingWithPrefix (void)
{
std::string cmd_to_send("G0X");
//- send command : ADC default conversion rate
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::disable_readingWithPrefix()
// ============================================================================
void KeithleyDDCProtocol::disable_readingWithPrefix (void)
{
std::string cmd_to_send("G1X");
//- send command : ADC default conversion rate
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::enable_ReadingsFromElectrometer() -> disable storing mode
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
// ============================================================================
void KeithleyDDCProtocol::enable_ReadingsFromElectrometer (void)
{
std::string cmd_to_send("B0X");
//- send command : readings from Electrometer
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::enable_readingsFromBuffer_K617_6512()
// ============================================================================
void KeithleyDDCProtocol::enable_readingsFromBuffer_K617_6512 (void)
{
std::string cmd_to_send("B1X");
//- send command : ADC default conversion rate
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::enable_readingsFromBuffer_K486_487()
// ============================================================================
void KeithleyDDCProtocol::enable_readingsFromBuffer_K486_487 (void)
{
std::string cmd_to_send("B2X");
//- send command : ADC default conversion rate
_communication_link->write(cmd_to_send);
}
// ============================================================================
// KeithleyDDCProtocol::enable_integrationPeriod()
// ============================================================================
void KeithleyDDCProtocol::enable_integrationPeriod (void)
{
std::string cmd_to_send("S1X");
//-
//- send command : this command is only for k_486 or K_487
//- S1 is for : "Line cycle integration period (5-I /2d resolution)"
_communication_link->write(cmd_to_send);
}
/*// ============================================================================
// KeithleyDDCProtocol::init_keithley to perform reading(s) data
// ============================================================================
void KeithleyDDCProtocol::init_keithley (void)
{
//- Set default conversion rate (internal keithley device conversion rate)
this->set_conversionRate();
//- Set default conversion rate (internal keithley device conversion rate)
this->set_conversionRate();
//- Disable readings with prefix
this->disable_readingWithPrefix();
//- send command : INIT to trigg readings !
_communication_link->write(cmd_to_send);
}
// Following functions are part of commands supported via the DDC protocol.
// We may have to implement them after first tests on beamlines
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
// ============================================================================
// KeithleyDDCProtocol::setExternalFeedbackMeterMode (617 & 6512 Keithley DDC models
// ============================================================================
void KeithleyDDCProtocol::setExternalFeedbackMeterMode (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "F4X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setVonIMeterMode (only 617 Keithley DDC model
// ============================================================================
void KeithleyDDCProtocol::setVonIMeterMode (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "F5X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
// ============================================================================
// KeithleyDDCProtocol::setVonIMeterMode (only 487 Keithley DDC model
// ============================================================================
void KeithleyDDCProtocol::setVonIMeterMode_forK487 (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
std::stringstream cmd_to_send;
//- send command
cmd_to_send << "F1X" << std::ends;
_communication_link->write(cmd_to_send.str());
}
... TO BE IMPLEMENTED !!!!!
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::reading_source (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::data_store (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::data_format (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::baseline_suppression_ON (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::baseline_suppression_OFF (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
// ============================================================================
// KeithleyDDCProtocol::reading_source
// ============================================================================
void KeithleyDDCProtocol::keithley_status (void)
throw (electrometer::ElectrometerException, Tango::DevFailed)
{
}
*/