omronmodbus.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 "omronmodbus.h"
16 #include "charinterface.h"
17 
18 REGISTER_TYPE(XDriverList, OmronE5_CModbus, "OMRON E5*C controller via modbus");
19 
20 XOmronE5_CModbus::XOmronE5_CModbus(const char *name, bool runtime,
21  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
22  XModbusRTUDriver<XTempControl> (name, runtime, ref(tr_meas), meas) {
23  interface()->setSerialBaudRate(57600);
24  interface()->setSerialStopBits(1);
25  interface()->setSerialParity(XCharInterface::PARITY_EVEN);
26 
27  createChannels(ref(tr_meas), meas, true,
28  {"1"}, {}, {"Loop1"});
29 }
31  start();
32 
33  Snapshot shot_ch( *channels());
34  const XNode::NodeList &list( *shot_ch.list());
35  trans( *currentChannel(0)) = list.at(0);
36 
37  interface()->presetSingleResistor(0x0, 0x00u + 1u); //Writing on
38 
39  double digit = pow(10.0, -(double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
40  double target = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x106)) * digit;
41  trans( *targetTemp(0)) = target;
42  double manpow = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x600)) * 0.1;
43  trans( *manualPower(0)) = manpow;
44  double p = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0a00)) * 0.1;
45  double id_digit = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x1312)) ? 0.1 : 1.0;
46  double i = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0a04)) * id_digit;
47  double d = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0a08)) * id_digit;
48  trans( *prop(0)) = p;
49  trans( *interval(0)) = i;
50  trans( *deriv(0)) = d;
51 
52  uint32_t status = static_cast<uint32_t>(interface()->readHoldingTwoResistors(0x2));
53  bool isrunning = status & 0x01000000uL;
54  bool isman = status & 0x04000000uL;
55 
56  iterate_commit([=](Transaction &tr){
57  const Snapshot &shot(tr);
58  for(unsigned int idx = 0; idx < numOfLoops(); ++idx) {
59  if( !hasExtDevice(shot, idx)) {
60  tr[ *heaterMode(idx)].clear();
61  tr[ *heaterMode(idx)].add({"OFF", "AUTO", "MAN"});
62  tr[ *powerMax(idx)].setUIEnabled(false);
63  tr[ *powerMin(idx)].setUIEnabled(false);
64  tr[ *currentChannel(idx)].setUIEnabled(false);
65  tr[ *heaterMode(idx)] = isrunning ? (isman ? 2 : 1) : 0;
66  }
67  tr[ *powerRange(idx)].setUIEnabled(false);
68  }
69  });
70 
71 }
72 double XOmronE5_CModbus::getRaw(shared_ptr<XChannel> &) {
73  double digit = pow(10.0, -(double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
74  return static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0)) * digit;
75 }
76 double XOmronE5_CModbus::getTemp(shared_ptr<XChannel> &) {
77  double digit = pow(10.0, -(double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
78  return static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0)) * digit;
79 }
80 double XOmronE5_CModbus::getHeater(unsigned int loop) {
81  return static_cast<int32_t>(interface()->readHoldingTwoResistors(0x8)) * 0.1;
82 }
83 void XOmronE5_CModbus::onPChanged(unsigned int, double p) {
84  interface()->presetTwoResistors(0x0a00, static_cast<uint32_t>(lrint(p / 0.1)));
85 }
86 void XOmronE5_CModbus::onIChanged(unsigned int, double i) {
87  double id_digit = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x1312)) ? 0.1 : 1.0;
88  interface()->presetTwoResistors(0x0a04, static_cast<uint32_t>(lrint(i / id_digit)));
89 }
90 void XOmronE5_CModbus::onDChanged(unsigned int, double d) {
91  double id_digit = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x1312)) ? 0.1 : 1.0;
92  interface()->presetTwoResistors(0x0a08, static_cast<uint32_t>(lrint(d / id_digit)));
93 }
94 void XOmronE5_CModbus::onTargetTempChanged(unsigned int, double temp) {
95  double digit = pow(10.0, -(double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
96  interface()->presetTwoResistors(0x106, static_cast<uint32_t>(lrint(temp / digit)));
97 }
98 void XOmronE5_CModbus::onManualPowerChanged(unsigned int, double pow) {
99  interface()->presetTwoResistors(0x600, static_cast<uint32_t>(lrint(pow / 0.1)));
100 }
101 void XOmronE5_CModbus::onHeaterModeChanged(unsigned int, int) {
102  bool isman = ( **heaterMode(0))->to_str() == "MAN";
103  bool isrunning = (( **heaterMode(0))->to_str() == "AUTO") || isman;
104  interface()->presetSingleResistor(0x0, 0x0100u + (isrunning ? 0u : 1u));
105  interface()->presetSingleResistor(0x0, 0x0900u + (isman ? 1u : 0u));
106 }
107 void XOmronE5_CModbus::onPowerRangeChanged(unsigned int /*loop*/, int) {
108 }
109 void XOmronE5_CModbus::onCurrentChannelChanged(unsigned int , const shared_ptr<XChannel> &) {
110 }
111 void XOmronE5_CModbus::onExcitationChanged(const shared_ptr<XChannel> &, int) {
112 }

Generated for KAME4 by  doxygen 1.8.3