fourres.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 "fourres.h"
15 #include "ui_fourresform.h"
16 #include "interface.h"
17 #include "analyzer.h"
18 
19 REGISTER_TYPE(XDriverList, FourRes, "Resistance Measurement with Polarity Switching");
20 
21 XFourRes::XFourRes(const char *name, bool runtime,
22  Transaction &tr_meas, const shared_ptr<XMeasure> &meas)
23  : XSecondaryDriver(name, runtime, ref(tr_meas), meas),
24  m_resistance(create<XScalarEntry>("Resistance", false,
25  dynamic_pointer_cast<XDriver>(shared_from_this()))),
26  m_dmm(create<XItemNode < XDriverList, XDMM> >(
27  "DMM", false, ref(tr_meas), meas->drivers(), true)),
28  m_dcsource(create<XItemNode < XDriverList, XDCSource> >(
29  "DCSource", false, ref(tr_meas), meas->drivers(), true)),
30  m_control(create<XBoolNode>("Control", true)),
31  m_form(new FrmFourRes(g_pFrmMain)) {
32 
33  m_form->setWindowTitle(i18n("Resistance Measurement with Switching Polarity - ") + getLabel() );
34 
35  meas->scalarEntries()->insert(tr_meas, resistance());
36 
37  connect(dmm());
38  connect(dcsource());
39  iterate_commit([=](Transaction &tr){
40  tr[ *control()] = false;
41  tr[ *this].value_inverted = 0.0;
42  });
43  m_conControl = xqcon_create<XQToggleButtonConnector>(m_control, m_form->m_ckbControl);
44  m_conDMM = xqcon_create<XQComboBoxConnector>(m_dmm, m_form->m_cmbDMM, ref(tr_meas));
45  m_conDCSource = xqcon_create<XQComboBoxConnector>(m_dcsource, m_form->m_cmbDCSource, ref(tr_meas));
46  m_conRes = xqcon_create<XQLCDNumberConnector> (m_resistance->value(), m_form->m_lcdRes);
47 }
48 XFourRes::~XFourRes () {
49 }
50 void
52  m_form->showNormal();
53  m_form->raise();
54 }
55 bool
57  const Snapshot &shot_emitter, const Snapshot &shot_others,
58  XDriver *emitter) const {
59  shared_ptr<XDMM> dmm__ = shot_this[ *dmm()];
60  shared_ptr<XDCSource> dcsource__ = shot_this[ *dcsource()];
61  if( !dmm__ || !dcsource__) return false;
62  if(emitter != dmm__.get()) return false;
63  return true;
64 }
65 
66 void
67 XFourRes::analyze(Transaction &tr, const Snapshot &shot_emitter, const Snapshot &shot_others,
68  XDriver *emitter) throw (XRecordError&) {
69  Snapshot &shot_this(tr);
70  shared_ptr<XDMM> dmm__ = shot_this[ *dmm()];
71  shared_ptr<XDCSource> dcsource__ = shot_this[ *dcsource()];
72 
73  if(shot_emitter[ *dmm__].timeAwared() < shot_others[ *dcsource__].time())
74  throw XSkippedRecordError(__FILE__, __LINE__);
75 
76  double curr = shot_others[ *dcsource__->value()];
77  double var = shot_emitter[ *dmm__].value();
78 
79  if(curr < 0) {
80  tr[ *this].value_inverted = var;
81  throw XSkippedRecordError(__FILE__, __LINE__);
82  }
83  else {
84  if(shot_this[ *this].value_inverted == 0.0)
85  throw XSkippedRecordError(__FILE__, __LINE__);
86  resistance()->value(tr, (var - shot_this[ *this].value_inverted) / 2 / curr);
87  tr[ *this].value_inverted = 0.0;
88  }
89 }
90 
91 void
93  if(shot[ *control()]) {
94  shared_ptr<XDCSource> dcsource__ = shot[ *dcsource()];
95  dcsource__->iterate_commit([=](Transaction &tr){
96  double curr = tr[ *dcsource__->value()];
97  tr[ *dcsource__->value()] = -curr; //Invert polarity.
98  msecsleep(100);
99  });
100  }
101 }

Generated for KAME4 by  doxygen 1.8.3