15 #include "ui_flowcontrollerform.h"
16 #include "flowcontroller.h"
17 #include "interface.h"
19 #include "xnodeconnector.h"
22 XFlowControllerDriver::XFlowControllerDriver(
const char *name,
bool runtime,
23 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
26 dynamic_pointer_cast<
XDriver>(shared_from_this()),
"%.4f")),
28 m_valve(create<
XDoubleNode>(
"Valve", true,
"%.4f")),
32 m_warning(create<
XBoolNode>(
"Warning", true)),
33 m_alarm(create<
XBoolNode>(
"Alarm", true)),
34 m_control(create<
XBoolNode>(
"Control", true)),
38 tr[ *control()] =
false;
41 meas->scalarEntries()->insert(tr_meas, m_flow);
43 m_form->statusBar()->hide();
44 m_form->setWindowTitle(i18n(
"Flow Controller - ") +
getLabel() );
46 m_target->setUIEnabled(
false);
47 m_rampTime->setUIEnabled(
false);
48 m_openValve->setUIEnabled(
false);
49 m_closeValve->setUIEnabled(
false);
50 m_control->setUIEnabled(
false);
52 m_conFlow = xqcon_create<XQLCDNumberConnector>(m_flow->value(), m_form->m_lcdFlow);
53 m_conValve = xqcon_create<XQLCDNumberConnector>(m_valve, m_form->m_lcdValve);
54 m_form->m_dblTarget->setRange(0.0, 1000.0);
55 m_form->m_dblTarget->setSingleStep(0.1);
56 m_conTarget = xqcon_create<XQDoubleSpinBoxConnector>(m_target, m_form->m_dblTarget, m_form->m_slTarget);
57 m_conRampTime = xqcon_create<XQLineEditConnector>(m_rampTime, m_form->m_edRampTime);
58 m_conControl = xqcon_create<XQToggleButtonConnector>(m_control, m_form->m_ckbControl);
59 m_conAlarm = xqcon_create<XQLedConnector>(m_alarm, m_form->m_ledAlarm);
60 m_conWarning = xqcon_create<XQLedConnector>(m_warning, m_form->m_ledWarning);
61 m_conOpenValve = xqcon_create<XQButtonConnector>(m_openValve, m_form->m_btnOpenValve);
62 m_conCloseValve = xqcon_create<XQButtonConnector>(m_closeValve, m_form->m_btnCloseValve);
75 flow = reader.pop<
double>();
76 valve = reader.pop<
double>();
77 bool alarm = reader.pop<uint16_t>();
78 bool warning = reader.pop<uint16_t>();
79 m_flow->value(tr, flow);
80 tr[ *m_valve] = valve;
81 tr[ *m_alarm] = alarm;
82 tr[ *m_warning] = warning;
86 if(m_form->m_lblUnit->text().isEmpty()) {
87 m_form->m_dblTarget->setRange(0.0, shot[ *
this].m_fullScale);
88 m_form->m_lblUnit->setText(shot[ *
this].m_unit);
95 changeSetPoint(shot[ *
target()]);
98 e.print(
getLabel() +
" " + i18n(
"Error while changing target, "));
108 e.print(
getLabel() +
" " + i18n(
"Error while changing conditions, "));
118 e.print(
getLabel() +
" " + i18n(
"Error while opening valve, "));
125 setValveState(
false);
128 e.print(
getLabel() +
" " + i18n(
"Error while closeing valve, "));
135 changeControl(shot[ *control()]);
138 e.print(
getLabel() +
" " + i18n(
"Error, "));
143 XFlowControllerDriver::execute(
const atomic<bool> &terminated) {
151 m_target->setUIEnabled(
true);
152 m_rampTime->setUIEnabled(
true);
153 m_openValve->setUIEnabled(
true);
154 m_closeValve->setUIEnabled(
true);
155 m_control->setUIEnabled(
true);
158 m_valve->setUIEnabled(
false);
161 e.print(
getLabel() +
" " + i18n(
"Read Error, "));
165 tr[ *
this].m_fullScale = fs;
166 tr[ *
this].m_unit = unit_in_slm ?
"SLM" :
"SCCM";
167 m_lsnTarget = tr[ *
target()].onValueChanged().connectWeakly(shared_from_this(), &XFlowControllerDriver::onTargetChanged);
168 m_lsnRampTime = tr[ *
rampTime()].onValueChanged().connectWeakly(shared_from_this(), &XFlowControllerDriver::onRampTimeChanged);
169 m_lsnControl = tr[ *control()].onValueChanged().connectWeakly(shared_from_this(), &XFlowControllerDriver::onControlChanged);
170 m_lsnCloseValve = tr[ *closeValve()].onTouch().connectWeakly(shared_from_this(), &XFlowControllerDriver::onCloseValveTouched);
171 m_lsnOpenValve = tr[ *openValve()].onTouch().connectWeakly(shared_from_this(), &XFlowControllerDriver::onOpenValveTouched);
174 while( !terminated) {
176 XTime time_awared = XTime::now();
178 bool warning =
false, alarm =
false;
181 getStatus(flow,
valve, alarm, warning);
184 e.print(
getLabel() +
" " + i18n(
"Read Error, "));
187 auto writer = std::make_shared<RawData>();
190 writer->push((uint16_t)alarm);
191 writer->push((uint16_t)warning);
195 m_valve->setUIEnabled(
false);
196 m_rampTime->setUIEnabled(
false);
197 m_openValve->setUIEnabled(
false);
198 m_closeValve->setUIEnabled(
false);
199 m_control->setUIEnabled(
false);
202 m_lsnRampTime.reset();
203 m_lsnControl.reset();
204 m_lsnCloseValve.reset();
205 m_lsnOpenValve.reset();