Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/ModbusMaster/ModbusMaster.cpp
- Revision:
- 148:ee3cbaafe355
- Parent:
- 147:105bcf234f81
- Child:
- 149:950c90425f7c
diff -r 105bcf234f81 -r ee3cbaafe355 src/ModbusMaster/ModbusMaster.cpp
--- a/src/ModbusMaster/ModbusMaster.cpp Wed Sep 28 12:34:34 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Wed Sep 28 17:57:36 2016 +0000
@@ -13,6 +13,8 @@
DigitalOut dout1(PC_1);
DigitalOut dout2(PA_1);
+DigitalIn flow_switch(PA_0);
+DigitalIn dinp2(PC_13);
/*****************************************************************************
* Function: ModbusMaster
@@ -74,6 +76,7 @@
ModbusRegisterMap[id].rfreq = atoi(json_value["rfreq"].get<std::string>().c_str());
ModbusRegisterMap[id].input = input;
ModbusRegisterMap[id].simulated = false;
+ ModbusRegisterMap[id].valid = true;
}
}
@@ -106,22 +109,23 @@
}
continue;
}
-
+
if( iter->second.node != 0 ) {
-
- logInfo("Processing Input: node=%d, reg=%d, size=%d, order=%d", iter->second.node, iter->second.reg, iter->second.size, iter->second.order );
+
+// logInfo("Processing Input: node=%d, reg=%d, size=%d, order=%d", iter->second.node, iter->second.reg, iter->second.size, iter->second.order );
SendModbusCommand(iter->second.node, iter->second.reg, iter->second.size);
Thread::wait(30);
-
switch( iter->second.type ) {
case TYPE_32BIT_FLOAT:
float float_value;
status = ReadModbus_32bit_float( &float_value, iter->second.order );
if( status == true ) {
ModbusRegisterMap[iter->first].float_value = float_value;
- logInfo("Modbus Tag:%s value=%2.2f", iter->first.c_str(), float_value );
+ ModbusRegisterMap[iter->first].valid = true;
+// logInfo("Modbus Tag:%s value=%2.2f", iter->first.c_str(), float_value );
} else {
- logInfo("Modbus Read Failed, tag=%s", iter->first.c_str() );
+ ModbusRegisterMap[iter->first].valid = false;
+// logInfo("Modbus Read Failed, tag=%s", iter->first.c_str() );
}
break;
case TYPE_32BIT_INT:
@@ -137,15 +141,21 @@
}
}
- if( iter->second.input == false ) {
- if( iter->second.node == 0 ) {
- logInfo("processing PIN output=%s, reg=%d, value=%d",iter->first.c_str(), ModbusRegisterMap[iter->first].reg, (bool)ModbusRegisterMap[iter->first].float_value);
- if( ModbusRegisterMap[iter->first].reg == 1 ) {
- dout1 = (bool)ModbusRegisterMap[iter->first].float_value;
- } else {
- dout2 = (bool)ModbusRegisterMap[iter->first].float_value;
- }
-
+ if( (iter->second.node == 0) && (iter->second.input == false) ) {
+// logInfo("processing PIN output=%s, reg=%d, value=%d",iter->first.c_str(), ModbusRegisterMap[iter->first].reg, (bool)ModbusRegisterMap[iter->first].float_value);
+ if( ModbusRegisterMap[iter->first].reg == 1 ) {
+ dout1 = (bool)ModbusRegisterMap[iter->first].float_value;
+ } else {
+ dout2 = (bool)ModbusRegisterMap[iter->first].float_value;
+ }
+ }
+ if( (iter->second.node == 0) && (iter->second.input == true) ) {
+// logInfo("processing PIN input=%s, reg=%d, value=%d",iter->first.c_str(), ModbusRegisterMap[iter->first].reg, (bool)ModbusRegisterMap[iter->first].float_value);
+ if( ModbusRegisterMap[iter->first].reg == 1 ) {
+ // digital input
+ ModbusRegisterMap[iter->first].float_value = (float)flow_switch.read();
+ } else {
+ ModbusRegisterMap[iter->first].float_value = (float)dinp2.read();
}
}
}
