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:
- 81:d45bfa16953a
- Parent:
- 67:49f266601d83
- Child:
- 82:f3e495a98877
- Child:
- 86:189c125d8878
--- a/src/ModbusMaster/ModbusMaster.cpp Tue Sep 20 12:49:58 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Tue Sep 20 13:41:31 2016 +0000
@@ -11,6 +11,9 @@
#include "ModbusMaster.h"
#include "MbedJSONValue.h"
+DigitalOut dout1(PC_1);
+DigitalOut dout2(PA_1);
+
/*****************************************************************************
* Function: ModbusMaster
* Description: entry point for the Modbus Master
@@ -23,25 +26,28 @@
{
logInfo("%s ModbusMaster has started...", __func__);
bool status;
+ bool input;
MbedJSONValue json_value;
-
+
modbus_init(MB_BAUD_RATE);
DigitalOut flu_power(PA_11);
flu_power = 0; // provide power to the modbus
- printf("\r\nMODBUS INITIALIZED\r\n");
-
while( true ) {
- logInfo("Top Of Modbus Master Loop");
-
// configure modbus registers based in all files that start with "input"
std::vector<mDot::mdot_file> file_list = GLOBAL_mdot->listUserFiles();
for (std::vector<mDot::mdot_file>::iterator i = file_list.begin(); i != file_list.end(); ++i) {
- if( strncmp( i->name, "input", (strlen("input")-1)) == 0 ) {
+ input = true;
+ if( (strncmp( i->name, "input", (strlen("input")-1)) == 0) ||
+ (strncmp( i->name, "output", (strlen("output")-1)) == 0)) {
- logInfo("(%d)FOUND INPUT FILE: %s", __LINE__, i->name);
+ if( (strncmp( i->name, "output", (strlen("output")-1)) == 0) ) {
+ input = false;
+ }
+
+ logInfo("(%d)FOUND FILE: %s", __LINE__, i->name);
status = GLOBAL_mdot->readUserFile(i->name, ModbusMasterScratchBuf, 1024);
if( status != true ) {
@@ -49,7 +55,7 @@
} else {
logInfo("(%d)Read File SUCCESS: %s", __LINE__, ModbusMasterScratchBuf );
}
-
+
parse( json_value, ModbusMasterScratchBuf );
std::string id = json_value["id"].get<std::string>().c_str();
@@ -65,6 +71,7 @@
ModbusRegisterMap[id].order = atoi(json_value["order"].get<std::string>().c_str());
ModbusRegisterMap[id].fmt = json_value["fmt"].get<std::string>().c_str();
ModbusRegisterMap[id].rfreq = atoi(json_value["rfreq"].get<std::string>().c_str());
+ ModbusRegisterMap[id].input = input;
}
}
@@ -73,7 +80,7 @@
std::map<std::string, ModbusRegister>::iterator iter;
for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
- logInfo("Reading node=%d, reg=%d, size=%d, order=%d", iter->second.node, iter->second.reg, iter->second.size, iter->second.order );
+ logInfo("Processing 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);
@@ -84,9 +91,7 @@
if( status == true ) {
ModbusRegisterMap[iter->first].float_value = float_value;
logInfo("Modbus Tag:%s value=%2.2f", iter->first.c_str(), float_value );
- }
- else
- {
+ } else {
logInfo("Modbus Read Failed, tag=%s", iter->first.c_str() );
}
break;
@@ -101,6 +106,19 @@
default:
break;
}
+
+ if( iter->second.input == false )
+ {
+ printf("processing output=%s, reg=%d, value=%d\r\n",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;
+ }
+ }
}
logInfo("Checking for MAIL");
