I'm trying to read values stored in a bool* pointer from a modbus coil call.
I'm using modbus-esp8266 library. it's all ok with Input Registers and Holding Registers but i cannot read the result of a coil read.
#include <ModbusRTU.h>
#include <SoftwareSerial.h>
SoftwareSerial S(D2, D1);
ModbusRTU mb;
bool cb(Modbus::ResultCode event, uint16_t transactionId, void* data) { // Callback to monitor errors
if (event != Modbus::EX_SUCCESS) {
Serial.print("Error result: 0x");
Serial.print(event, HEX);
}
return true;
}
void setup() {
Serial.begin(115200);
S.begin(9600, SWSERIAL_8N1);
mb.begin(&S);
mb.master();
}
void loop() {
bool* coils;
if (!mb.slave()) { // Check if no transaction in progress
mb.readCoil(1, 1, coils, 1, cb); // Send Read Hreg from Modbus Server
while(mb.slave()) { // Check if transaction is active
mb.task();
delay(10);
}
Serial.println(*coils);
}
delay(1000);
}
I get this kind of error when trying to print *coils
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
How to get the boolean result value from it?
bool coils;andmb.readCoil(1, 1, &coils, 1, cb);. this way the function can the value of the variablecoil