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.
Fork of TAIST_modbus by
Diff: modbus.cpp
- Revision:
- 7:cba97341e790
- Parent:
- 6:b6d3e73ad56f
--- a/modbus.cpp Mon Mar 19 07:02:47 2018 +0000
+++ b/modbus.cpp Wed Mar 21 09:09:40 2018 +0000
@@ -1,7 +1,8 @@
#include "mbed.h"
#include "modbus.h"
-uint8_t nodeId = 2;
+//RawSerial pc2(PC_6,PC_7);
+uint8_t nodeId = 4;
uint16_t regValue[ADDR_RANGE];
enum state {IDLE, RECEPTION, END} protState = IDLE;
@@ -136,7 +137,7 @@
return -lrc;
}
-void modbus_response(uint8_t reg_map)
+void modbus_response(uint8_t reg_map, char *tmpPrint)
{
char fmt00[] = ":%02X%02X%02X\r\n";
char fmt01[] = ":%02X%02X%02X%02X%02X\r\n";
@@ -156,8 +157,10 @@
frame[3] = tmp & 0xFF;
frame[4] = calc_lrc(frame, 4);
fmtstr = fmt01;
- sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
- printf("%s", str);
+ //sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
+ sprintf(tmpPrint, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
+ printf("%s", str);
+ //pc2.printf("%s", str);
break;
case 2:
tmp = modbus_read(1);
@@ -165,8 +168,10 @@
frame[3] = tmp & 0xFF;
frame[4] = calc_lrc(frame, 4);
fmtstr = fmt02;
- sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
- printf("%s", str);
+ //sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
+ sprintf(tmpPrint, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4]);
+ printf("%s", str);
+ //pc2.printf("%s", str);
break;
case 3:
tmp = modbus_read(0);
@@ -177,9 +182,11 @@
frame[5] = tmp & 0xFF;
frame[6] = calc_lrc(frame, 6);
fmtstr = fmt03;
- sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6]);
+ //sprintf(str, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6]);
+ sprintf(tmpPrint, fmtstr, frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6]);
// printf("Response: %s", str);
- printf("%s", str);
+ printf("%s", str);
+ //pc2.printf("%s", str);
break;
default:
fmtstr = fmt00;
