dmm.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 #include "ui_dmmform.h"
16 #include <QStatusBar>
17 #include "dmm.h"
18 #include "interface.h"
19 #include "analyzer.h"
20 #include "xnodeconnector.h"
21 
22 XDMM::XDMM(const char *name, bool runtime,
23  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
24  XPrimaryDriverWithThread(name, runtime, ref(tr_meas), meas),
25  m_entry(create<XScalarEntry>("Value", false,
26  dynamic_pointer_cast<XDriver>(shared_from_this()))),
27  m_function(create<XComboNode>("Function", false)),
28  m_waitInms(create<XUIntNode>("WaitInms", false)),
29  m_form(new FrmDMM(g_pFrmMain)) {
30  meas->scalarEntries()->insert(tr_meas, m_entry);
31  iterate_commit([=](Transaction &tr){
32  tr[ *m_waitInms] = 100;
33  });
34  m_form->statusBar()->hide();
35  m_form->setWindowTitle(i18n("DMM - ") + getLabel() );
36  m_function->setUIEnabled(false);
37  m_waitInms->setUIEnabled(false);
38  m_conFunction = xqcon_create<XQComboBoxConnector>(m_function, m_form->m_cmbFunction, Snapshot( *m_function));
39  m_conWaitInms = xqcon_create<XQSpinBoxUnsignedConnector>(m_waitInms, m_form->m_numWait);
40 }
41 
42 void
44 //! impliment form->show() here
45  m_form->showNormal();
46  m_form->raise();
47 }
48 
49 void
51  double x = reader.pop<double>();
52  tr[ *this].write_(x);
53  m_entry->value(tr, x);
54 }
55 void
56 XDMM::visualize(const Snapshot &shot) {
57 }
58 
59 void
61  try {
63  }
64  catch (XKameError &e) {
65  e.print(getLabel() + " " + i18n("DMM Error"));
66  }
67 }
68 
69 void *
70 XDMM::execute(const atomic<bool> &terminated) {
72 
73  m_function->setUIEnabled(true);
74  m_waitInms->setUIEnabled(true);
75 
76  iterate_commit([=](Transaction &tr){
77  m_lsnOnFunctionChanged =
78  tr[ *function()].onValueChanged().connectWeakly(
79  shared_from_this(), &XDMM::onFunctionChanged);
80  });
81  while( !terminated) {
82  msecsleep( ***waitInms());
83  if(( **function())->to_str().empty()) continue;
84 
85  auto writer = std::make_shared<RawData>();
86  double x;
87  XTime time_awared = XTime::now();
88  // try/catch exception of communication errors
89  try {
90  x = oneShotRead();
91  }
92  catch (XKameError &e) {
93  e.print(getLabel() + " " + i18n("DMM Read Error"));
94  continue;
95  }
96  writer->push(x);
97  finishWritingRaw(writer, time_awared, XTime::now());
98  }
99 
100  m_function->setUIEnabled(false);
101  m_waitInms->setUIEnabled(false);
102 
103  m_lsnOnFunctionChanged.reset();
104 
105  return NULL;
106 }
107 

Generated for KAME4 by  doxygen 1.8.3