userdcsource.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13  ***************************************************************************/
14 #include "charinterface.h"
15 #include "userdcsource.h"
16 
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");
20 
21 XYK7651::XYK7651(const char *name, bool runtime,
22  Transaction &tr_meas, const shared_ptr<XMeasure> &meas)
23  : XCharDeviceDriver<XDCSource>(name, runtime, ref(tr_meas), meas) {
24  iterate_commit([=](Transaction &tr){
25  tr[ *function()].add("F1");
26  tr[ *function()].add("F5");
27  });
28  channel()->disable();
29  interface()->setGPIBUseSerialPollOnRead(false);
30  interface()->setGPIBUseSerialPollOnWrite(false);
31 }
32 void
34  this->start();
35  msecsleep(3000); // wait for instrumental reset.
36 }
37 void
38 XYK7651::changeFunction(int /*ch*/, int ) {
39  XScopedLock<XInterface> lock( *interface());
40  if( !interface()->isOpened()) return;
41  iterate_commit([=](Transaction &tr){
42  const Snapshot &shot(tr);
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");
50  }
51  else {
52  tr[ *range()].clear();
53  tr[ *range()].add("1mA");
54  tr[ *range()].add("10mA");
55  tr[ *range()].add("100mA");
56  }
57  });
58  interface()->send(( **function())->to_str() + "E");
59 }
60 void
61 XYK7651::changeOutput(int /*ch*/, bool x) {
62  XScopedLock<XInterface> lock( *interface());
63  if( !interface()->isOpened()) return;
64  interface()->sendf("O%uE", x ? 1 : 0);
65 }
66 void
67 XYK7651::changeValue(int /*ch*/, double x, bool autorange) {
68  XScopedLock<XInterface> lock( *interface());
69  if( !interface()->isOpened()) return;
70  if(autorange)
71  interface()->sendf("SA%.10fE", x);
72  else
73  interface()->sendf("S%.10fE", x);
74 }
75 double
76 XYK7651::max(int /*ch*/, bool autorange) const {
77  Snapshot shot( *this);
78  int ran = shot[ *range()];
79  if(shot[ *function()] == 0) {
80  if(autorange || (ran == -1))
81  ran = 4;
82  return 10e-3 * pow(10.0, (double)ran);
83  }
84  else {
85  if(autorange || (ran == -1))
86  ran = 2;
87  return 1e-3 * pow(10.0, (double)ran);
88  }
89 }
90 void
91 XYK7651::changeRange(int /*ch*/, int ran) {
92  Snapshot shot( *this);
93  {
94  XScopedLock<XInterface> lock( *interface());
95  if( !interface()->isOpened()) return;
96  if(shot[ *function()] == 0) {
97  if(ran == -1)
98  ran = 4;
99  ran += 2;
100  }
101  else {
102  if(ran == -1)
103  ran = 2;
104  ran += 4;
105  }
106  interface()->sendf("R%dE", ran);
107  }
108 }
109 
110 XADVR6142::XADVR6142(const char *name, bool runtime,
111  Transaction &tr_meas, const shared_ptr<XMeasure> &meas)
112  : XCharDeviceDriver<XDCSource>(name, runtime, ref(tr_meas), meas) {
113  iterate_commit([=](Transaction &tr){
114  tr[ *function()].add("V [V]");
115  tr[ *function()].add("I [A]");
116  });
117  channel()->disable();
118  interface()->setEOS("\r\n");
119 }
120 void
122  this->start();
123 }
124 void
125 XADVR6142::changeFunction(int /*ch*/, int ) {
126  XScopedLock<XInterface> lock( *interface());
127  if( !interface()->isOpened()) return;
128  iterate_commit([=](Transaction &tr){
129  const Snapshot &shot(tr);
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");
137  }
138  else {
139  tr[ *range()].clear();
140  tr[ *range()].add("1mA");
141  tr[ *range()].add("10mA");
142  tr[ *range()].add("100mA");
143  }
144  });
145 }
146 void
147 XADVR6142::changeOutput(int /*ch*/, bool x) {
148  XScopedLock<XInterface> lock( *interface());
149  if( !interface()->isOpened()) return;
150  if(x)
151  interface()->send("E");
152  else
153  interface()->send("H");
154 }
155 void
156 XADVR6142::changeValue(int /*ch*/, double x, bool autorange) {
157  XScopedLock<XInterface> lock( *interface());
158  Snapshot shot( *this);
159  if( !interface()->isOpened()) return;
160  if(autorange) {
161  if(shot[ *function()] == 0) {
162  interface()->sendf("D%.8fV", x);
163  }
164  else {
165  x *= 1e3;
166  interface()->sendf("D%.8fMA", x);
167  }
168  }
169  else {
170  if(shot[ *function()] == 0) {
171  if(shot[ *range()] <= 1)
172  x *= 1e3;
173  }
174  else {
175  x *= 1e3;
176  }
177  interface()->sendf("D%.8f", x);
178  }
179 }
180 double
181 XADVR6142::max(int /*ch*/, bool autorange) const {
182  Snapshot shot( *this);
183  int ran = shot[ *range()];
184  if(shot[ *function()] == 0) {
185  if(autorange || (ran == -1))
186  ran = 4;
187  if(ran == 4)
188  return 30;
189  return 10e-3 * pow(10.0, (double)ran);
190  }
191  else {
192  if(autorange || (ran == -1))
193  ran = 2;
194  return 1e-3 * pow(10.0, (double)ran);
195  }
196 }
197 void
198 XADVR6142::changeRange(int /*ch*/, int ran) {
199  Snapshot shot( *this);
200  {
201  XScopedLock<XInterface> lock( *interface());
202  if( !interface()->isOpened()) return;
203  if(shot[ *function()] == 0) {
204  if(ran == -1)
205  ran = 2;
206  ran += 2;
207  interface()->sendf("V%d", ran);
208  }
209  else {
210  if(ran == -1)
211  ran = 2;
212  ran += 1;
213  interface()->sendf("I%d", ran);
214  }
215  }
216 }
217 
218 
219 XMicroTaskTCS::XMicroTaskTCS(const char *name, bool runtime,
220  Transaction &tr_meas, const shared_ptr<XMeasure> &meas)
221  : XCharDeviceDriver<XDCSource>(name, runtime, ref(tr_meas), meas) {
222  interface()->setEOS("\n");
223  interface()->setSerialBaudRate(9600);
224  interface()->setSerialStopBits(2);
225  iterate_commit([=](Transaction &tr){
226  tr[ *channel()].add("1");
227  tr[ *channel()].add("2");
228  tr[ *channel()].add("3");
229  tr[ *function()].disable();
230  tr[ *range()].add("99uA");
231  tr[ *range()].add("0.99uA");
232  tr[ *range()].add("9.9mA");
233  tr[ *range()].add("99mA");
234  });
235 }
236 void
237 XMicroTaskTCS::queryStatus(Transaction &tr, int ch) {
238  unsigned int ran[3];
239  unsigned int v[3];
240  unsigned int o[3];
241  {
242  XScopedLock<XInterface> lock( *interface());
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)
249  throw XInterface::XConvError(__FILE__, __LINE__);
250  }
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;
254 }
255 void
256 XMicroTaskTCS::changeOutput(int ch, bool x) {
257  {
258  XScopedLock<XInterface> lock( *interface());
259  if(!interface()->isOpened()) return;
260  unsigned int v[3];
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])
263  != 3)
264  throw XInterface::XConvError(__FILE__, __LINE__);
265  for(int i = 0; i < 3; i++) {
266  if(ch != i)
267  v[i] = 0;
268  else
269  v[i] ^= x ? 1 : 0;
270  }
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);
273  }
274  updateStatus();
275 }
276 void
277 XMicroTaskTCS::changeValue(int ch, double x, bool autorange) {
278  {
279  XScopedLock<XInterface> lock( *interface());
280  if(!interface()->isOpened()) return;
281  if((x >= 0.099) || (x < 0))
282  throw XInterface::XInterfaceError(i18n("Value is out of range."), __FILE__, __LINE__);
283  if(autorange) {
284  interface()->sendf("SETDAC %u 0 %u", (unsigned int)(ch + 1), (unsigned int)lrint(x * 1e6));
285  interface()->receive(1);
286  }
287  else {
288  unsigned int ran[3];
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)
292  throw XInterface::XConvError(__FILE__, __LINE__);
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);
297  }
298  }
299  updateStatus();
300 }
301 void
302 XMicroTaskTCS::changeRange(int ch, int newran) {
303  {
304  XScopedLock<XInterface> lock( *interface());
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",
309  &ran[0], &v[0],
310  &ran[1], &v[1],
311  &ran[2], &v[2]) != 6)
312  throw XInterface::XConvError(__FILE__, __LINE__);
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);
319  }
320  updateStatus();
321 }
322 double
323 XMicroTaskTCS::max(int ch, bool autorange) const {
324  if(autorange) return 0.099;
325  {
326  XScopedLock<XInterface> lock( *interface());
327  if(!interface()->isOpened()) return 0.099;
328  unsigned int ran[3];
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)
332  throw XInterface::XConvError(__FILE__, __LINE__);
333  return pow(10.0, (double)(ran[ch] - 1)) * 99e-6;
334  }
335 ;}
336 void
338  this->start();
339  interface()->query("ID?");
340  fprintf(stderr, "%s\n", (const char*)&interface()->buffer()[0]);
341 }

Generated for KAME4 by  doxygen 1.8.3