Read The Autonics data counter Autonics CT6S-1p4t data counter via RS485 not read data

#include <ModbusMaster.h>
#define CT6S Serial1
// instantiate ModbusMaster object
ModbusMaster node1;

uint8_t result1;
static uint32_t i;
uint8_t j, result;
uint16_t data[8];
unsigned int regs[2];
const int Pin_Counter = 1;
int datacounter;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
CT6S.begin(9600);
// Modbus slave ID 1
node1.begin(1, CT6S);
}

void loop()
{

unsigned int datacounter = analogRead (Pin_Counter);
Serial.println(datacounter);
delay(100);

// Read 16 registers starting at 0x3100)
result = node1.readInputRegisters(0x1000, 13);
if (result == node1.ku8MBSuccess)
{
Serial.print("Counter: ");
Serial.println(node1.getResponseBuffer(1004));
Serial.print("Vload: ");
Serial.println(node1.getResponseBuffer(1006));
Serial.print("Pload: ");
Serial.println((node1.getResponseBuffer(0x1007) +
node1.getResponseBuffer(0x1013) << 13));
}

delay(10);
}


Schematic Autonics CT6S-1P4T

Comments in sketch contradict the code

0x3100 is not a 0x1000, 16 is not a 13... And none of these values match the register address pointed by the arrow in the picture in post #4.

Also take note that 0x1004 and 1004 are very different values:

Are you intended something as getResponseBuffer(0x1004) ?

What did you try to achieve in this line?

Are you understand what is <<13 means?

<<13 there are a number of addresses in the address data in the RS485 communication manual book

Are you intended something as getResponseBuffer(0x1004) ?

i want to read the counter data or the value that is in that address

continue what is which for the correct address of the correct Rs485 communication map ?

that's address 4 length 2..
try this..

result = node1.readInputRegisters(4, 2);

if you get a successful read..
still have to combine the 2 bytes into a word..

maybe like this..

  uint16_t value = (node1.getResponseBuffer(0) << 8) | node1.getResponseBuffer(1);

good luck.. ~q

nothing similar :frowning:

In which address - 1004 or 0x1004 ? Do you understand the difference?

Please read something about hexadecimal number format (0xNNN) - without clear understanding it and it difference with decimal numbers you will hardly can use Modbus protocol

reading through the doc's source..
ModbusMaster
you don't have to combine bytes..
getResponseBuffer returns a word not a byte..
if you read 1 register, it's at getResponseBuffer (0), the second at getResponseBuffer (1) and so on..

maybe you need to combine two words into a int32??

 int32_t val = (int32_t(bWord) << 16) | int32_t(aWord);

sorry.. ~q

Void loop()
{
static uint32_t val;

//set word 0 of TX buffer to least-significant word of counter (bists 15.. 0)
Node.setTransmitBuffer(0, lowWord(i));
//set word 0 of TX buffer to least-significant word of counter (bists 31.. 16)
Node.setTransmitBuffer(1, higWord(i));
//slave: write TX buffer to (2) 16-bit regsiters starting at register 0
result = node.writeMultipleRgisters(0,2)

}

i used the code above and managed to write the counter of autonics with arduino

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.