better modbus serial config

This commit is contained in:
gemu2015 2021-03-30 08:38:13 +02:00
parent 803ecbd9a6
commit 7bc7b83f18
1 changed files with 47 additions and 8 deletions

View File

@ -2293,8 +2293,26 @@ dddef_exit:
script_meter_desc[index].type = *lp;
lp++;
if (*lp != ',') {
switch (*lp) {
case 'N':
lp++;
script_meter_desc[index].sopt = 0x10 | (*lp & 3);
lp++;
break;
case 'E':
lp++;
script_meter_desc[index].sopt = 0x20 | (*lp & 3);
lp++;
break;
case 'O':
lp++;
script_meter_desc[index].sopt = 0x30 | (*lp & 3);
lp++;
break;
default:
script_meter_desc[index].sopt = *lp&7;
lp++;
}
} else {
script_meter_desc[index].sopt = 0;
}
@ -2491,6 +2509,25 @@ init10:
#endif
SerialConfig smode = SERIAL_8N1;
if (meter_desc_p[meters].sopt & 0xf0) {
// new serial config
switch (meter_desc_p[meters].sopt >> 4) {
case 1:
if ((meter_desc_p[meters].sopt & 1) == 1) smode = SERIAL_8N1;
else smode = SERIAL_8N2;
break;
case 2:
if ((meter_desc_p[meters].sopt & 1) == 1) smode = SERIAL_8E1;
else smode = SERIAL_8E2;
break;
case 3:
if ((meter_desc_p[meters].sopt & 1) == 1) smode = SERIAL_8O1;
else smode = SERIAL_8O2;
break;
}
} else {
// depecated serial config
if (meter_desc_p[meters].sopt == 2) {
smode = SERIAL_8N2;
}
@ -2500,6 +2537,8 @@ init10:
smode = SERIAL_8E2;
}
}
}
#ifdef ESP8266
if (meter_ss[meters]->begin(meter_desc_p[meters].params)) {
meter_ss[meters]->flush();