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:
- 186:16912aa18c2a
- Parent:
- 181:e2c982c94e98
- Child:
- 188:d35a74bf4e92
diff -r 1e4d6ee57c31 -r 16912aa18c2a src/ModbusMaster/ModbusMaster.cpp
--- a/src/ModbusMaster/ModbusMaster.cpp Tue Oct 04 20:51:39 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Wed Oct 05 20:47:21 2016 +0000
@@ -161,6 +161,16 @@
}
break;
case TYPE_32BIT_INT:
+ int32_t int32_value;
+ status = ReadModbus_32bit_int( &int32_value, iter->second.order );
+ if( status == true ) {
+ ModbusRegisterMap[iter->first].float_value = int32_value;
+ ModbusRegisterMap[iter->first].valid = true;
+ logInfo("Modbus Tag:%s value=%2.2f", iter->first.c_str(), ModbusRegisterMap[iter->first].float_value );
+ } else {
+ ModbusRegisterMap[iter->first].valid = false;
+ logInfo("Modbus Read Failed, tag=%s", iter->first.c_str() );
+ }
break;
case TYPE_32BIT_UINT:
break;
@@ -373,6 +383,36 @@
default:
return false;
}
+// printf("0x%x 0x%x 0x%x 0x%x\r\n", value.b.hi_hi, value.b.hi_lo, value.b.lo_hi, value.b.lo_lo);
*float_value = value.f;
return true;
}
+
+bool ReadModbus_32bit_int( int32_t *int32_value, int order )
+{
+ MR_REGISTER_32BIT_INT value;
+
+ if (mbInterruptComplete() != true ) {
+ return false;
+ }
+
+ switch( order ) {
+ case BigEndian:
+ value.b.lo_lo = modbus_input_buffer[6];
+ value.b.lo_hi = modbus_input_buffer[5];
+ value.b.hi_lo = modbus_input_buffer[4];
+ value.b.hi_hi = modbus_input_buffer[3];
+ break;
+ case BigEndianReverseWord:
+ value.b.lo_lo = modbus_input_buffer[4];
+ value.b.lo_hi = modbus_input_buffer[3];
+ value.b.hi_lo = modbus_input_buffer[6];
+ value.b.hi_hi = modbus_input_buffer[5];
+ break;
+ default:
+ return false;
+ }
+// printf("0x%x 0x%x 0x%x 0x%x\r\n", value.b.hi_hi, value.b.hi_lo, value.b.lo_hi, value.b.lo_lo);
+ *int32_value = value.i;
+ return true;
+}
\ No newline at end of file
