From 8feffde365243baeecc64d2c7c071442386bd673 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 15 Nov 2020 16:09:05 +0100 Subject: [PATCH] sml add optional 2 modbus stop bits --- tasmota/xsns_53_sml.ino | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 5356efb04..826d2df0f 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -86,6 +86,7 @@ struct METER_DESC { char *txmem; uint8_t index; uint8_t max_index; + uint8_t sopt; }; // this descriptor method is no longer supported @@ -2012,7 +2013,14 @@ dddef_exit: if (*lp!=',') goto next_line; lp++; script_meter_desc[index].type=*lp; - lp+=2; + lp++; + if (*lp!=',') { + script_meter_desc[index].sopt=*lp&7; + lp++; + } else { + script_meter_desc[index].sopt=0; + } + lp++; script_meter_desc[index].flag=strtol(lp,&lp,10); if (*lp!=',') goto next_line; lp++; @@ -2180,20 +2188,24 @@ init10: #endif #endif -#ifdef ESP32 - if (meter_desc_p[meters].type=='M') { - meter_ss[meters]->begin(meter_desc_p[meters].params, SERIAL_8E1,meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin); - } else { - meter_ss[meters]->begin(meter_desc_p[meters].params,SERIAL_8N1,meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin); + SerialConfig smode = SERIAL_8N1; + if (meter_desc_p[meters].sopt == 2) { + smode = SERIAL_8N2; } + if (meter_desc_p[meters].type=='M') { + smode = SERIAL_8E1; + if (meter_desc_p[meters].sopt == 2) { + smode = SERIAL_8E2; + } + } +#ifdef ESP32 + meter_ss[meters]->begin(meter_desc_p[meters].params, smode, meter_desc_p[meters].srcpin, meter_desc_p[meters].trxpin); #else if (meter_ss[meters]->begin(meter_desc_p[meters].params)) { meter_ss[meters]->flush(); } if (meter_ss[meters]->hardwareSerial()) { - if (meter_desc_p[meters].type=='M') { - Serial.begin(meter_desc_p[meters].params, SERIAL_8E1); - } + Serial.begin(meter_desc_p[meters].params, smode); ClaimSerial(); //Serial.setRxBufferSize(512); }