I'm trying to connect with a 4 channel temperature controller using Arduino Modbus Library.
This is a part of my temperature controller datasheet. It has register for read PV of each channel.
I have studied example code of the library and now i'm trying to read PV of each channel.
So, I have modified the example code as below,
#include <ModbusMaster.h>
// instantiate ModbusMaster object
ModbusMaster node;
void setup()
{
// use Serial (port 0); initialize Modbus communication baud rate
Serial.begin(19200);
// communicate with Modbus slave ID 2 over Serial (port 0)
node.begin(2, Serial);
}
void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
// set word 0 of TX buffer to least-significant word of counter (bits 15..0)
node.setTransmitBuffer(0, lowWord(i));
// set word 1 of TX buffer to most-significant word of counter (bits 31..16)
node.setTransmitBuffer(1, highWord(i));
// slave: read (4) 16-bit registers starting at register 2 to RX buffer
result = node.readHoldingRegisters(1, 4);
// do something with data if read is successful
if (result == node.ku8MBSuccess)
{
for (j = 0; j < 4; j++)
{
data[j] = node.getResponseBuffer(j);
}
}
}
My questions are, Explain below lines in the code
// set word 0 of TX buffer to least-significant word of counter (bits 15..0)
node.setTransmitBuffer(0, lowWord(i));
// set word 1 of TX buffer to most-significant word of counter (bits 31..16)
node.setTransmitBuffer(1, highWord(i));
I didn't pass any request to slave, So, can I get the 4 PV value like this? If not, please explain how can I do it.
1 Answer 1
The setTransmitBuffer calls are for writeMultipleRegisters, which you removed from the example.
The first parameter of the readHoldingRegisters is the address of the register. The second parameter is the count of registers to read.
Your sketch doesn't show the retrieved data. You have no indication of success or fail.
-
As I understood,
setTransmitBuffer
using for initializing the TX buffer.Am I correct? Retrieved data stored in RX buffer. can't we get data usinggetResponseBuffer
?user_fs10– user_fs102018年09月25日 09:45:47 +00:00Commented Sep 25, 2018 at 9:45 -
you have
data[j] = node.getResponseBuffer(j);
2018年09月25日 11:48:07 +00:00Commented Sep 25, 2018 at 11:48
Explore related questions
See similar questions with these tags.