From 367b86cd09261dc119090d52897c81a051eaa815 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Thu, 28 Nov 2024 08:06:01 -0500 Subject: [PATCH] Maybe fix? --- IO_Modbus.cpp | 2 +- IO_Modbus.h | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/IO_Modbus.cpp b/IO_Modbus.cpp index ad065e4..17e0878 100644 --- a/IO_Modbus.cpp +++ b/IO_Modbus.cpp @@ -317,7 +317,7 @@ ModbusRTUMasterError Modbus::writeMultipleCoils(uint8_t id, uint16_t startAddres adu.setDataRegister(2, quantity); adu.data[4] = byteCount; for (uint16_t i = 0; i < quantity; i++) { - bitWrite(adu.data[5 + (i >> 3)], i & 7, (bool) buf[i]); + bitWrite(adu.data[5 + (i >> 3)], i & 7, buf[i]); } for (uint16_t i = quantity; i < (byteCount * 8); i++) { bitClear(adu.data[5 + (i >> 3)], i & 7); diff --git a/IO_Modbus.h b/IO_Modbus.h index 01b87e6..55fba17 100644 --- a/IO_Modbus.h +++ b/IO_Modbus.h @@ -208,41 +208,26 @@ public: int _read(VPIN vpin) override { // Return current state from this device uint16_t pin = vpin - _firstVpin; - if (pin < _numDiscreteInputs) { - return (int) discreteInputs[pin]; - } else - return 0; + return (int) discreteInputs[pin]; } void _write(VPIN vpin, int value) override { // Update current state for this device, in preparation the bus transmission uint16_t pin = vpin - _firstVpin - _numDiscreteInputs; - if (pin < _numCoils) { - if (value){ - if (value == 1) coils[pin] = (char*) 0x1; - if (value == 0) coils[pin] = (char*) 0x0; - //coils[pin] = value; - } - else - coils[pin]; - } + if (value == 1) coils[pin] = (char*) 0x1; + if (value == 0) coils[pin] = (char*) 0x0; } - int _readAnalogue(VPIN vpin) override { + int _readAnalogue(VPIN vpin) { // Return acquired data value, e.g. int pin = vpin - _firstVpin - _numDiscreteInputs - _numCoils; - return (int) inputRegisters[pin-1]; + return (int) inputRegisters[pin]; } void _writeAnalogue(VPIN vpin, int value, uint8_t param1=0, uint16_t param2=0) override { uint16_t pin = vpin - _firstVpin - _numDiscreteInputs - _numCoils - _numInputRegisters; - if (pin < _numHoldingRegisters) { - if (value) - holdingRegisters[pin-1] = (uint16_t*) value; - else - holdingRegisters[pin-1]; - } + holdingRegisters[pin] = (uint16_t*) value; } uint8_t getBusNumber() {