15 #include "omronmodbus.h"
16 #include "charinterface.h"
18 REGISTER_TYPE(
XDriverList, OmronE5_CModbus,
"OMRON E5*C controller via modbus");
20 XOmronE5_CModbus::XOmronE5_CModbus(
const char *name,
bool runtime,
21 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
23 interface()->setSerialBaudRate(57600);
24 interface()->setSerialStopBits(1);
25 interface()->setSerialParity(XCharInterface::PARITY_EVEN);
27 createChannels(ref(tr_meas), meas,
true,
28 {
"1"}, {}, {
"Loop1"});
35 trans( *currentChannel(0)) = list.at(0);
37 interface()->presetSingleResistor(0x0, 0x00u + 1u);
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;
49 trans( *interval(0)) = i;
50 trans( *deriv(0)) = d;
52 uint32_t status =
static_cast<uint32_t
>(interface()->readHoldingTwoResistors(0x2));
53 bool isrunning = status & 0x01000000uL;
54 bool isman = status & 0x04000000uL;
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;
67 tr[ *powerRange(idx)].setUIEnabled(
false);
73 double digit = pow(10.0, -(
double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
74 return static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x0)) * digit;
77 double digit = pow(10.0, -(
double)static_cast<int32_t>(interface()->readHoldingTwoResistors(0x0420)));
78 return static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x0)) * digit;
81 return static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x8)) * 0.1;
83 void XOmronE5_CModbus::onPChanged(
unsigned int,
double p) {
84 interface()->presetTwoResistors(0x0a00, static_cast<uint32_t>(lrint(p / 0.1)));
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)));
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)));
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)));
98 void XOmronE5_CModbus::onManualPowerChanged(
unsigned int,
double pow) {
99 interface()->presetTwoResistors(0x600, static_cast<uint32_t>(lrint(pow / 0.1)));
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));
107 void XOmronE5_CModbus::onPowerRangeChanged(
unsigned int ,
int) {
109 void XOmronE5_CModbus::onCurrentChannelChanged(
unsigned int ,
const shared_ptr<XChannel> &) {
111 void XOmronE5_CModbus::onExcitationChanged(
const shared_ptr<XChannel> &,
int) {