Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 5 characters in body
Source Link
user_fs10
  • 187
  • 1
  • 14

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 achievedo it.

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 achieve it.

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.

Source Link
user_fs10
  • 187
  • 1
  • 14

Using Modbus-RTU with Arduino and temperature controller

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.

Registers

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 achieve it.