userdmm.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 //---------------------------------------------------------------------------
15 
16 #include "userdmm.h"
17 #include "charinterface.h"
18 //---------------------------------------------------------------------------
19 
20 REGISTER_TYPE(XDriverList, KE2000, "Keithley 2000/2001 DMM");
21 REGISTER_TYPE(XDriverList, KE2182, "Keithley 2182 nanovolt meter");
22 REGISTER_TYPE(XDriverList, HP34420A, "Agilent 34420A nanovolt meter");
23 REGISTER_TYPE(XDriverList, HP3458A, "Agilent 3458A DMM");
24 REGISTER_TYPE(XDriverList, HP3478A, "Agilent 3478A DMM");
25 REGISTER_TYPE(XDriverList, SanwaPC500, "SANWA PC500/510/520M DMM");
26 REGISTER_TYPE(XDriverList, SanwaPC5000, "SANWA PC5000 DMM");
27 
28 void
30  XString func = ( **function())->to_str();
31  if( !func.empty())
32  interface()->sendf(":CONF:%s", func.c_str());
33 }
34 double
36  interface()->query(":FETC?");
37  return interface()->toDouble();
38 }
39 double
41  interface()->query(":READ?");
42  return interface()->toDouble();
43 }
44 /*
45 double
46 XDMMSCPI::measure(const XString &func)
47 {
48  interface()->queryf(":MEAS:%s?", func.c_str());
49  return interface()->toDouble();
50 }
51 */
52 
53 XHP3458A::XHP3458A(const char *name, bool runtime,
54  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
55  XCharDeviceDriver<XDMM>(name, runtime, ref(tr_meas), meas) {
56  interface()->setGPIBMAVbit(0x80);
57  interface()->setGPIBUseSerialPollOnWrite(false);
58  iterate_commit([=](Transaction &tr){
59  const char *funcs[] = {
60  "DCV", "ACV", "ACDCV", "OHM", "OHMF", "DCI", "ACI", "ACDCI", "FREQ", "PER", "DSAC", "DSDC", "SSAC", "SSDC", ""
61  };
62  for(const char **func = funcs; strlen( *func); func++) {
63  tr[ *function()].add( *func);
64  }
65  });
66 }
67 void
69  XString func = ( **function())->to_str();
70  if( !func.empty())
71  interface()->sendf("FUNC %s;ARANGE ON", func.c_str());
72 }
73 double
74 XHP3458A::fetch() {
75  interface()->receive();
76  return interface()->toDouble();
77 }
78 double
80  interface()->query("END ALWAYS;OFORMAT ASCII;QFORMAT NUM;NRDGS 1;TRIG AUTO;TARM SGL");
81  return interface()->toDouble();
82 }
83 
84 
85 XHP3478A::XHP3478A(const char *name, bool runtime,
86  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
87  XCharDeviceDriver<XDMM>(name, runtime, ref(tr_meas), meas) {
88  interface()->setGPIBUseSerialPollOnWrite(false);
89  interface()->setGPIBMAVbit(0x01);
90 // setEOS("\r\n");
91  iterate_commit([=](Transaction &tr){
92  const char *funcs[] = {
93  "DCV", "ACV", "OHM", "OHMF", "DCI", "ACI", ""
94  };
95  for(const char **func = funcs; strlen( *func); func++) {
96  tr[ *function()].add( *func);
97  }
98  });
99 }
100 void
102  int func = ***function();
103  if(func < 0)
104  return;
105 // throw XInterface::XInterfaceError(i18n("Select function!"), __FILE__, __LINE__);
106  interface()->sendf("F%dRAZ1", func + 1);
107 }
108 double
109 XHP3478A::fetch() {
110  interface()->receive();
111  return interface()->toDouble();
112 }
113 double
115  interface()->query("T3");
116  return interface()->toDouble();
117 }
118 
119 XSanwaPC500::XSanwaPC500(const char *name, bool runtime,
120  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
121  XCharDeviceDriver<XDMM>(name, runtime, ref(tr_meas), meas) {
122  interface()->setSerialBaudRate(9600);
123  interface()->setSerialStopBits(2);
124 
125  iterate_commit([=](Transaction &tr){
126  const char *funcs[] = {
127  "AcV", "DcV", "Ac+DcV", "Cx", "Dx", "Dx", "TC", "TC", "TF", "Ohm",
128  "Conti", "AcA", "DcA", "Ac+DcA", "Hz", "Duty%", "%mA", "dB", "?", ""
129  };
130  for(const char **func = funcs; strlen( *func); func++) {
131  tr[ *function()].add( *func);
132  }
133  tr[ *function()].str(XString("?"));
134  });
135 }
136 void
138 }
139 double
140 XSanwaPC500::fetch() {
141  msecsleep(200);
142  requestData();
143  interface()->receive(8);
144  if((interface()->buffer()[0] != 0x10) ||
145  (interface()->buffer()[1] != 0x02))
146  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
147  if((interface()->buffer()[6] != 0x00) ||
148  (interface()->buffer()[7] != 0x00))
149  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
150  const int funcs[] = {0x05, 0x06, 0x07, 0x08, 0x04, 0x14, 0x00, 0x20, 0x40, 0x80,
151  0x180, 0x201, 0x202, 0x203, 0x400, 0x800, 0x802, 0x2000
152  };
153  int f = (int)interface()->buffer()[4] + (int)interface()->buffer()[5] * 256u;
154  for(int i = 0; i < (int)sizeof(funcs) / (int)sizeof(int); i++) {
155  if(funcs[i] == f) {
156  trans( *function()) = i;
157  }
158  }
159 
160  int dlen = interface()->buffer()[3] - 1;
161  interface()->receive(dlen);
162  std::vector<char> buf(dlen);
163  memcpy(&buf[0], &interface()->buffer()[0], dlen);
164  dbgPrint(XString(&buf[0]));
165  if(buf.size() < 6)
166  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
167  buf[dlen - 3] = '\0';
168  if((XString( &buf[0]) == "+OL") || (XString( &buf[0]) == " OL")) {
169  return 1e99;
170  }
171  if(XString( &buf[0]) == "-OL") {
172  return -1e99;
173  }
174  if(buf.size() < 14)
175  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
176  double x;
177  if(sscanf( &buf[0], "%8lf", &x) != 1) {
178  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
179  }
180  double e;
181  if(sscanf( &buf[8], "E%2lf", &e) != 1) {
182  throw XInterface::XInterfaceError(i18n("Format Error!"), __FILE__, __LINE__);
183  }
184  return x * pow(10.0, e);
185 }
186 double
188  return fetch();
189 }
190 void
192  char bytes[8] = {0x10, 0x02, 0x42, 0x00, 0x00, 0x00, 0x10, 0x03};
193  interface()->write(bytes, sizeof(bytes));
194 }
195 XSanwaPC5000::XSanwaPC5000(const char *name, bool runtime,
196  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
197  XSanwaPC500(name, runtime, ref(tr_meas), meas) {
198 
199 }
200 
201 void
203  char bytes[8] = {0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x03};
204  interface()->write(bytes, sizeof(bytes));
205 }

Generated for KAME4 by  doxygen 1.8.3