Hi all,
I’ve read literally every forum post on MODBUS/RS485 but I’m still at a complete loss.
I’m after a solid solution that can read a modbus device (Novus DigiRail 2A) with the following params:
Baud Rate: 4800
Parity: Even
Stop Bits: 1
READ INPUT REGISTERS - 04H
Address:
0 PV of Channel 1 in percentage. Range from 0 to 62000.
1 PV of Channel 2 in percentage. Range from 0 to 62000.
2 – 4 Reserved
5 PV of Channel 1 in engineering unit.
6 PV of Channel 2 in engineering unit.
.
.
.
etc
I’ve know got a solid TTL->485 hardware setup, using the MAX485. I know this works, as I’ve tested it using the SDM_Energy_Monitor repo that I’ve ported to Photon/Electron, alongside an SDM120 Meter and it works a charm.
However this library doesn’t use another modbus library, rather it relies on the base Serial implementation for it’s communication.
So far, I haven’t been able to find a library that let’s me specify parity, stop bits etc as well as read registers successfully.
I’ve tried using the MODBUS_Master library provided on the Web IDE, with no luck. Also tried both of @peekay123’s modbus libraries with no luck. I’d just really like an answer because I’m struggling.
Thanks all.
Joe
EDIT:
This is the example I’m currently working from, which uses the MODBUS_Master lib from the IDE:
#include "ModbusMaster.h"
// instantiate ModbusMaster object as slave ID 1
ModbusMaster node(245);
void setup() {
// initialize Modbus communication baud rate
node.begin(4800);
node.enableTXpin(A5); //A1 is the pin used to control the TX enable pin of RS485 driver
//node.enableDebug(); //Print TX and RX frames out on Serial. Beware, enabling this messes up the timings for RS485 Transactions, causing them to fail.
Serial.begin(9600);
Serial.println("Starting Modbus Transaction:");
}
void loop() {
static uint32_t i;
uint8_t j, result;
uint16_t data[10];
i++;
result = node.readInputRegisters(0x0000, 1);
Serial.println("");
// do something with data if read is successful
if (result == node.ku8MBSuccess) {
Serial.print("Success, Received data: ");
for (j = 0; j < 2; j++) {
data[j] = node.getResponseBuffer(j);
Serial.print(data[j], HEX);
Serial.print(" ");
}
Serial.println("");
} else {
Serial.print("Failed, Response Code: ");
Serial.print(result, HEX);
Serial.println("");
delay(5000); //if failed, wait for bit longer, before retrying!
}
delay(1000);
}
This is how I’ve configured my device:
This is the communication manual: