From 59d2ef469275cbfe2d19d96f6c86146b8a2bdea7 Mon Sep 17 00:00:00 2001 From: Max Brueggemann Date: Sat, 3 Dec 2016 03:37:03 +0100 Subject: [PATCH] Fixed bug in Multiple Register/Coil writing --- yaMBSiavr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/yaMBSiavr.c b/yaMBSiavr.c index 2d8a15f..1ca7638 100644 --- a/yaMBSiavr.c +++ b/yaMBSiavr.c @@ -125,14 +125,15 @@ void modbusTickTimer(void) { if ((modbusTimer==modbusInterCharTimeout)) { BusState|=(1< perform crc check - BusState=(1<=requestedAmount) && ((DataPos-9)==rxbuffer[6])) //enough data received? + if (((rxbuffer[6])>=requestedAmount*2) && ((DataPos-9)>=rxbuffer[6])) //enough data received? { modbusRegisterToInt(rxbuffer+7,ptrToInArray+(unsigned char)(requestedAdr-startAddress),(unsigned char)(requestedAmount)); modbusSendMessage(5); @@ -322,7 +323,7 @@ uint8_t modbusExchangeBits(volatile uint8_t *ptrToInArray, uint16_t startAddress } else if (rxbuffer[1]==fcForceMultipleCoils) { - if (((rxbuffer[6]*8)>=requestedAmount) && ((DataPos-9)==rxbuffer[6])) //enough data received? + if (((rxbuffer[6]*8)>=requestedAmount) && ((DataPos-9)>=rxbuffer[6])) //enough data received? { for (uint16_t c = 0; c