diff --git a/lib/lib_basic/TasmotaModbus-3.5.0/src/TasmotaModbus.cpp b/lib/lib_basic/TasmotaModbus-3.5.0/src/TasmotaModbus.cpp index 252f3efd4..95db697f5 100644 --- a/lib/lib_basic/TasmotaModbus-3.5.0/src/TasmotaModbus.cpp +++ b/lib/lib_basic/TasmotaModbus-3.5.0/src/TasmotaModbus.cpp @@ -25,6 +25,7 @@ extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE}; +//#define TASMOTAMODBUSDEBUG TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin) : TasmotaSerial(receive_pin, transmit_pin, 1) { @@ -134,7 +135,8 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1 uint16_t crc = CalculateCRC(frame, framepointer); frame[framepointer++] = (uint8_t)(crc); frame[framepointer++] = (uint8_t)(crc >> 8); - + +#ifdef TASMOTAMODBUSDEBUG uint8_t *buf; uint16_t bufsize=(framepointer + 1) * 3; buf = (uint8_t *)malloc(bufsize); @@ -144,6 +146,7 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1 snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",frame[i]); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Send: %s"), buf); free(buf); +#endif flush(); write(frame, framepointer); @@ -181,6 +184,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count, ui } } +#ifdef TASMOTAMODBUSDEBUG // RX Logging uint8_t *buf; uint16_t bufsize=(mb_len + 1) * 3; @@ -191,6 +195,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count, ui snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",buffer[i]); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Received: %s"), buf); free(buf); +#endif if (buffer[1] & 0x80) { // 01 84 02 f2 f1 diff --git a/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino b/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino index a90e2b16c..479ea560b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino @@ -317,6 +317,7 @@ void ModbusBridgeHandle(void) modbusBridge.byteCount = 0; ModbusBridgeError errorcode = ModbusBridgeError::noerror; + if (modbusBridge.deviceAddress == 0) { #ifdef USE_MODBUS_BRIDGE_TCP @@ -682,12 +683,10 @@ void ModbusTCPHandle(void) if (dataPointer % 2 == 0) { writeData[dataPointer / 2] = (uint16_t)(((uint16_t)modbusBridgeTCP.tcp_buf[dataStartByte + dataPointer]) << 8); - AddLog(LOG_LEVEL_DEBUG_MORE, "%d=%04X", dataPointer/2, writeData[dataPointer/2]); } else { writeData[dataPointer / 2] |= ((uint16_t)modbusBridgeTCP.tcp_buf[dataStartByte + dataPointer]); - AddLog(LOG_LEVEL_DEBUG_MORE, "%d=%04X", dataPointer/2, writeData[dataPointer/2]); } } } @@ -806,7 +805,10 @@ void CmndModbusBridgeSend(void) } // Prevent buffer overflow due to usage of to many registers - if (modbusBridge.dataCount > MBR_MAX_REGISTERS) + if ((!bitMode) && (modbusBridge.dataCount > MBR_MAX_REGISTERS)) + errorcode = ModbusBridgeError::wrongcount; + + if ((bitMode) && (modbusBridge.dataCount > MBR_MAX_REGISTERS * 8)) errorcode = ModbusBridgeError::wrongcount; // Get Json data for writing