1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 13:21:01 +01:00

Maybe fix?

This commit is contained in:
travis-farmer 2024-11-28 08:06:01 -05:00
parent 6551ce7b50
commit 367b86cd09
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 7 additions and 22 deletions

View File

@ -317,7 +317,7 @@ ModbusRTUMasterError Modbus::writeMultipleCoils(uint8_t id, uint16_t startAddres
adu.setDataRegister(2, quantity); adu.setDataRegister(2, quantity);
adu.data[4] = byteCount; adu.data[4] = byteCount;
for (uint16_t i = 0; i < quantity; i++) { 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++) { for (uint16_t i = quantity; i < (byteCount * 8); i++) {
bitClear(adu.data[5 + (i >> 3)], i & 7); bitClear(adu.data[5 + (i >> 3)], i & 7);

View File

@ -208,41 +208,26 @@ public:
int _read(VPIN vpin) override { int _read(VPIN vpin) override {
// Return current state from this device // Return current state from this device
uint16_t pin = vpin - _firstVpin; uint16_t pin = vpin - _firstVpin;
if (pin < _numDiscreteInputs) { return (int) discreteInputs[pin];
return (int) discreteInputs[pin];
} else
return 0;
} }
void _write(VPIN vpin, int value) override { void _write(VPIN vpin, int value) override {
// Update current state for this device, in preparation the bus transmission // Update current state for this device, in preparation the bus transmission
uint16_t pin = vpin - _firstVpin - _numDiscreteInputs; uint16_t pin = vpin - _firstVpin - _numDiscreteInputs;
if (pin < _numCoils) { if (value == 1) coils[pin] = (char*) 0x1;
if (value){ if (value == 0) coils[pin] = (char*) 0x0;
if (value == 1) coils[pin] = (char*) 0x1;
if (value == 0) coils[pin] = (char*) 0x0;
//coils[pin] = value;
}
else
coils[pin];
}
} }
int _readAnalogue(VPIN vpin) override { int _readAnalogue(VPIN vpin) {
// Return acquired data value, e.g. // Return acquired data value, e.g.
int pin = vpin - _firstVpin - _numDiscreteInputs - _numCoils; 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 { void _writeAnalogue(VPIN vpin, int value, uint8_t param1=0, uint16_t param2=0) override {
uint16_t pin = vpin - _firstVpin - _numDiscreteInputs - _numCoils - _numInputRegisters; uint16_t pin = vpin - _firstVpin - _numDiscreteInputs - _numCoils - _numInputRegisters;
if (pin < _numHoldingRegisters) { holdingRegisters[pin] = (uint16_t*) value;
if (value)
holdingRegisters[pin-1] = (uint16_t*) value;
else
holdingRegisters[pin-1];
}
} }
uint8_t getBusNumber() { uint8_t getBusNumber() {