14 #include "charinterface.h"
15 #include "userdcsource.h"
17 REGISTER_TYPE(
XDriverList, YK7651,
"YOKOGAWA 7651 dc source");
18 REGISTER_TYPE(
XDriverList, ADVR6142,
"ADVANTEST TR6142/R6142/R6144 DC V/DC A source");
19 REGISTER_TYPE(
XDriverList, MicroTaskTCS,
"MICROTASK/Leiden Triple Current Source");
21 XYK7651::XYK7651(
const char *name,
bool runtime,
22 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas)
25 tr[ *
function()].add(
"F1");
26 tr[ *
function()].add(
"F5");
29 interface()->setGPIBUseSerialPollOnRead(
false);
30 interface()->setGPIBUseSerialPollOnWrite(
false);
40 if( !interface()->isOpened())
return;
43 if(shot[ *
function()] == 0) {
44 tr[ *range()].clear();
45 tr[ *range()].add(
"10mV");
46 tr[ *range()].add(
"100mV");
47 tr[ *range()].add(
"1V");
48 tr[ *range()].add(
"10V");
49 tr[ *range()].add(
"100V");
52 tr[ *range()].clear();
53 tr[ *range()].add(
"1mA");
54 tr[ *range()].add(
"10mA");
55 tr[ *range()].add(
"100mA");
58 interface()->send(( **
function())->to_str() +
"E");
61 XYK7651::changeOutput(
int ,
bool x) {
63 if( !interface()->isOpened())
return;
64 interface()->sendf(
"O%uE", x ? 1 : 0);
67 XYK7651::changeValue(
int ,
double x,
bool autorange) {
69 if( !interface()->isOpened())
return;
71 interface()->sendf(
"SA%.10fE", x);
73 interface()->sendf(
"S%.10fE", x);
76 XYK7651::max(
int ,
bool autorange)
const {
78 int ran = shot[ *range()];
79 if(shot[ *
function()] == 0) {
80 if(autorange || (ran == -1))
82 return 10e-3 * pow(10.0, (
double)ran);
85 if(autorange || (ran == -1))
87 return 1e-3 * pow(10.0, (
double)ran);
91 XYK7651::changeRange(
int ,
int ran) {
95 if( !interface()->isOpened())
return;
96 if(shot[ *
function()] == 0) {
106 interface()->sendf(
"R%dE", ran);
110 XADVR6142::XADVR6142(
const char *name,
bool runtime,
111 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas)
114 tr[ *
function()].add(
"V [V]");
115 tr[ *
function()].add(
"I [A]");
117 channel()->disable();
118 interface()->setEOS(
"\r\n");
127 if( !interface()->isOpened())
return;
130 if(shot[ *
function()] == 0) {
131 tr[ *range()].clear();
132 tr[ *range()].add(
"10mV");
133 tr[ *range()].add(
"100mV");
134 tr[ *range()].add(
"1V");
135 tr[ *range()].add(
"10V");
136 tr[ *range()].add(
"30V");
139 tr[ *range()].clear();
140 tr[ *range()].add(
"1mA");
141 tr[ *range()].add(
"10mA");
142 tr[ *range()].add(
"100mA");
147 XADVR6142::changeOutput(
int ,
bool x) {
149 if( !interface()->isOpened())
return;
151 interface()->send(
"E");
153 interface()->send(
"H");
156 XADVR6142::changeValue(
int ,
double x,
bool autorange) {
159 if( !interface()->isOpened())
return;
161 if(shot[ *
function()] == 0) {
162 interface()->sendf(
"D%.8fV", x);
166 interface()->sendf(
"D%.8fMA", x);
170 if(shot[ *
function()] == 0) {
171 if(shot[ *range()] <= 1)
177 interface()->sendf(
"D%.8f", x);
181 XADVR6142::max(
int ,
bool autorange)
const {
183 int ran = shot[ *range()];
184 if(shot[ *
function()] == 0) {
185 if(autorange || (ran == -1))
189 return 10e-3 * pow(10.0, (
double)ran);
192 if(autorange || (ran == -1))
194 return 1e-3 * pow(10.0, (
double)ran);
198 XADVR6142::changeRange(
int ,
int ran) {
202 if( !interface()->isOpened())
return;
203 if(shot[ *
function()] == 0) {
207 interface()->sendf(
"V%d", ran);
213 interface()->sendf(
"I%d", ran);
219 XMicroTaskTCS::XMicroTaskTCS(
const char *name,
bool runtime,
220 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas)
222 interface()->setEOS(
"\n");
223 interface()->setSerialBaudRate(9600);
224 interface()->setSerialStopBits(2);
226 tr[ *channel()].add(
"1");
227 tr[ *channel()].add(
"2");
228 tr[ *channel()].add(
"3");
230 tr[ *range()].add(
"99uA");
231 tr[ *range()].add(
"0.99uA");
232 tr[ *range()].add(
"9.9mA");
233 tr[ *range()].add(
"99mA");
237 XMicroTaskTCS::queryStatus(
Transaction &tr,
int ch) {
243 if( !interface()->isOpened())
return;
244 interface()->query(
"STATUS?");
245 if(interface()->scanf(
"%*u%*u,%u,%u,%u,%*u,%u,%u,%u,%*u,%u,%u,%u,%*u",
246 &ran[0], &v[0], &o[0],
247 &ran[1], &v[1], &o[1],
248 &ran[2], &v[2], &o[2]) != 9)
251 tr[ *value()] = pow(10.0, (
double)ran[ch] - 1) * 1e-6 * v[ch];
252 tr[ *output()] = o[ch];
253 tr[ *range()] = ran[ch] - 1;
256 XMicroTaskTCS::changeOutput(
int ch,
bool x) {
259 if(!interface()->isOpened())
return;
261 interface()->query(
"STATUS?");
262 if(interface()->scanf(
"%*u%*u,%*u,%*u,%u,%*u,%*u,%*u,%u,%*u,%*u,%*u,%u,%*u", &v[0], &v[1], &v[2])
265 for(
int i = 0; i < 3; i++) {
271 interface()->sendf(
"SETUP 0,0,%u,0,0,0,%u,0,0,0,%u,0", v[0], v[1], v[2]);
272 interface()->receive(2);
277 XMicroTaskTCS::changeValue(
int ch,
double x,
bool autorange) {
280 if(!interface()->isOpened())
return;
281 if((x >= 0.099) || (x < 0))
284 interface()->sendf(
"SETDAC %u 0 %u", (
unsigned int)(ch + 1), (
unsigned int)lrint(x * 1e6));
285 interface()->receive(1);
289 interface()->query(
"STATUS?");
290 if(interface()->scanf(
"%*u%*u,%u,%*u,%*u,%*u,%u,%*u,%*u,%*u,%u,%*u,%*u,%*u",
291 &ran[0], &ran[1], &ran[2]) != 3)
293 int v = lrint(x / (pow(10.0, (
double)ran[ch] - 1) * 1e-6));
294 v = std::max(std::min(v, 99), 0);
295 interface()->sendf(
"DAC %u %u", (
unsigned int)(ch + 1), (
unsigned int)v);
296 interface()->receive(2);
302 XMicroTaskTCS::changeRange(
int ch,
int newran) {
305 if(!interface()->isOpened())
return;
306 unsigned int ran[3], v[3];
307 interface()->query(
"STATUS?");
308 if(interface()->scanf(
"%*u%*u,%u,%u,%*u,%*u,%u,%u,%*u,%*u,%u,%u,%*u,%*u",
311 &ran[2], &v[2]) != 6)
313 double x = pow(10.0, (
double)ran[ch] - 1) * 1e-6 * v[ch];
314 int newv = lrint(x / (pow(10.0, (
double)newran) * 1e-6));
315 newv = std::max(std::min(newv, 99), 0);
316 interface()->sendf(
"SETDAC %u %u %u",
317 (
unsigned int)(ch + 1), (
unsigned int)(newran + 1), (
unsigned int)newv);
318 interface()->receive(1);
323 XMicroTaskTCS::max(
int ch,
bool autorange)
const {
324 if(autorange)
return 0.099;
327 if(!interface()->isOpened())
return 0.099;
329 interface()->query(
"STATUS?");
330 if(interface()->scanf(
"%*u%*u,%u,%*u,%*u,%*u,%u,%*u,%*u,%*u,%u,%*u,%*u,%*u",
331 &ran[0], &ran[1], &ran[2]) != 3)
333 return pow(10.0, (
double)(ran[ch] - 1)) * 99e-6;
339 interface()->query(
"ID?");
340 fprintf(stderr,
"%s\n", (
const char*)&interface()->buffer()[0]);