From a00200af3c49818b50ea0ffea9c06a16569a1271 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Mon, 4 Jul 2022 14:48:59 +0300 Subject: [PATCH] fixed bta_meteo_modbus? --- BTA_modbusmeteo/bta_meteo_modbus.c | 7 ++++--- BTA_modbusmeteo/main.c | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BTA_modbusmeteo/bta_meteo_modbus.c b/BTA_modbusmeteo/bta_meteo_modbus.c index 9f4bbdd..fb8a32c 100644 --- a/BTA_modbusmeteo/bta_meteo_modbus.c +++ b/BTA_modbusmeteo/bta_meteo_modbus.c @@ -155,8 +155,8 @@ params_ans check_meteo_params(){ struct timeval timeout; fd_set set; time_t tstart = time(NULL); - int ctr = 15; // max 15 tries - while(ctr--) while(n_bytes){ + int ctr = 50; // max 50 tries + while(ctr--){ FD_ZERO(&set); FD_SET(portfd, &set); timeout.tv_sec = 0; @@ -174,7 +174,8 @@ params_ans check_meteo_params(){ size += n_bytes; if(n_bytes) continue; } - if(size > 0 && (res == 0 || size >= MODBUS_MAX_PACKET_SIZE || n_bytes == 0)) { + // read all or end of packet + if(size > 0 && res == 0 && (size == REQ_LEN || size == ANS_LEN)){ if(crc_check(buffer, size)){ if(size == REQ_LEN){ lastpar = buffer[2] << 8 | buffer[3]; diff --git a/BTA_modbusmeteo/main.c b/BTA_modbusmeteo/main.c index 0fcbf2b..a53788d 100644 --- a/BTA_modbusmeteo/main.c +++ b/BTA_modbusmeteo/main.c @@ -114,6 +114,7 @@ int main(int argc, char *argv[]){ return 1; } params_ans a = check_meteo_params(); + DBG("chk_meteo: %d", a); if(a == ANS_LOSTCONN){ LOG("Lost connection with device, reconnect!"); clear_flags();