Go Down

Topic: Help with ModBus RTU Master-Slave: SimpleModbus [SOLVED] (Read 387061 times) previous topic - next topic

dhrubajyoti2009

#795
Jan 08, 2019, 02:52 am Last Edit: Jan 08, 2019, 02:55 am by dhrubajyoti2009
Thanks Noiasca,

Apologies I mentioned a wrong panel meter, actual meter that I have connected is EM6430. Datasheet is available in the below link

https://www.schneider-electric.com/resources/sites/SCHNEIDER_ELECTRIC/content/live/FAQS/276000/FA276938/en_US/EM6430_User_Manual_NHA12535-03.pdf

I have made all the ground terminals common except the slave device, because it's a electrical panel meter and I donot have a separate ground for it.

Can you please explain how do I make ground common with the panel meter. If it is actually needed?

In the serial terminal I see that failed requests increases and the high byte value also increases and then it overflows. Attached error pic.

I could read the values using my USB to RS485 module in pc via demo software, I checked the resistance across A&B of the usb module it shows nothing in this case but when

I checked the resistance across the A&B of the RS485 to RS232 module it shows 120Ohms. Can this be a reason?

Can you check if I have mentioned the address correctly or it should be some different formats.

noiasca

if the panel doesn't have ground on RS485, just use two wire connection A&B. If it is missing you can't connect the ground - in this particular case it should be ok.

What I see from your code, these two parts do not fit together:
Code: [Select]

#define Total_Registers 1      //Total number of registers data reads

versus

 //Packet Identity, Slave ID, Operation Code, Address of register, No of register, Local start ID
  modbus_construct(&Packets[Packet_1], 5, READ_HOLDING_REGISTERS, 0x3903, 2, 0);


If you check the datasheet register 0x3903 is a float so you have to read 4 bytes. You will need:
Code: [Select]

#define Total_Registers 4      //Total number of registers data reads

and

 //Packet Identity, Slave ID, Operation Code, Address of register, No of register, Local start ID
  modbus_construct(&Packets[Packet_1], 5, READ_HOLDING_REGISTERS, 0x3903, 4, 0);


This alone will not solve your problem, but has to be correct also (and might help to solve the jumping value of your high byte).

There should be a termination resistance on both sides/end of the line - on your meter and the RS485 module.

As you mentioned, that you are able to read with the PC, there might be an issue in your hardware-wiring which we can't check. Please make a very good picture of your setup where we can see clearly each connection from Mega to RS485 - to your slave. Double check the proper RX/TX lines on the MEGA - I had already cheap MEGA clones where the labeling of RX/TX were wrong.


P.S.: if you copy Serial Output to this board, don't make screenshots, just CTRL-C/CTRL-V will do the same. To make your postings more readable, post code - and Serial Output in Code-Tags
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

dhrubajyoti2009

Thanks Noiasca,

The Serial Monitor Output after making the following changes as you suggested:
Quote
---------------------------------
MODBUS Testing
Exception errors: 0
Failed requests: 4
Successful requests: 0
Low byte: 0
High byte: 0
Active_Power 0.00
----------------------------------
Exception errors: 0
Failed requests: 8
Successful requests: 0
Low byte: 0
High byte: 0
Active_Power 0.00
----------------------------------
Exception errors: 0
Failed requests: 10
Successful requests: 0
Low byte: 0
High byte: 0
Active_Power 0.00
Note: External Power Supply, RS485 Module and Arduino Mega has common ground.
            Termination Resistance has been attached at both ends: RS485 has its own termination resistance and Panel Meter has 120ohms attached externally.


------------------------------------------------------------------------------------------------------------------
After doing all these I tried with the below-mentioned code:
Quote
#include <ModbusMaster.h>
#define MAX485_DE      3
#define MAX485_RE_NEG  2
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}
void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  // Init in receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
  // Modbus communication runs at 19200 baud
  Serial1.begin(19200);
  Serial.begin(19200);
 
  // Modbus slave ID 1
  node.begin(5, Serial1);
  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
  uint8_t result;
  uint32_t data[6];
 
  // Toggle the coil at address 0x0002 (Manual Load Control)
  //result = node.writeSingleCoil(0x0003, state);
  //state = !state;
  // Read 16 registers starting at 0x3100)
  result = node.readHoldingRegisters(3900, 30);
  if (result == node.ku8MBSuccess)
  {
    Serial.println("---------------------------------------------");
    Serial.print("Frequency: ");
    Serial.println(node.getResponseBuffer(15)/100.0f);
    Serial.print("L - N Voltage: ");
    Serial.println((node.getResponseBuffer(11)+node.getResponseBuffer(12))/100.0f);
    Serial.print("V1 - N Voltage: ");
    Serial.println(node.getResponseBuffer(27)/100.0f);
  }
  delay(1000);
}

And the Serial Monitor Output shows:
Quote
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67
---------------------------------------------
Frequency: 169.68
L - N Voltage: 402.10
V1 - N Voltage: 172.67

It's getting communicated properly, because whenever I am changing baud-rate, parity or stop bit in the Panel Meter, immediately the output is stopped. And again after correcting the changes, the output gets resumed. But the output which I am getting is completely different from the one showing in the display.

Note: In this connection, no termination resistance has been used, and all grounds are made common. And the connection diagram is shown in the attached image.

Kindly help me out.

dhrubajyoti2009

Now using the library modbus master and doing some circuitry tweaking I could connect the slave but not getting the desired value.

For frequency it should be 50, but I am receiving 16968. node.getResponseBuffer(15) might needs some data conversion?

Can some one help.

noiasca

a) I see in your new code

  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

Based on the drawing you made it's clear for me why simplemodbus is not working. Simplemodbus handles only one enable PIN. So if you want to use simplemmodbus, you have to connect DE/RE to one PIN (by the way this is for me anyway the preferable way then handle two pins in the same time).

b) check the datasheet. Register 3900 + 15 for frequency is definied as float. So you will need to read 2 (or 4) bytes and 3915/3916/3917/3918 and combine them to a proper value. I don't understand why the manual sometimes says 2 bytes. For me float is 4 bytes. Even the Intervall between some values are 2 byte, some are 4bytes, so what ever the manufacturer thought how to encode this values - good luck ;-)
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

abhijoshi20

i have an error on simplemodbus i am connecting pm710 with arduino uno.
the error which i have is this.


SimpleModbusMasterArduino:141:70: error: 'modbus_construct' was not declared in this scope

   modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0, 1, readRegs);

                                                                      ^

SimpleModbusMasterArduino:171:119: error: too many arguments to function 'void modbus_configure(long int, unsigned int, unsigned int, unsigned char, unsigned char, Packet*, unsigned int)'

   modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);

                                                                                                                       ^

In file included from C:\\Documents\Arduino\libraries\SimpleModbusMasterV12\examples\SimpleModbusMasterArduino\SimpleModbusMasterArduino.ino:1:0:

C:\\Documents\Arduino\libraries\SimpleModbusMaster/SimpleModbusMaster.h:143:6: note: declared here

 void modbus_configure(long baud, unsigned int _timeout, unsigned int _polling,

      ^

C:\\Documents\Arduino\libraries\SimpleModbusMasterV12\examples\SimpleModbusMasterArduino\SimpleModbusMasterArduino.ino: In function 'void loop()':

SimpleModbusMasterArduino:178:17: error: too few arguments to function 'unsigned int modbus_update(Packet*)'

   modbus_update();

                 ^

In file included from C:\\Documents\Arduino\libraries\SimpleModbusMasterV12\examples\SimpleModbusMasterArduino\SimpleModbusMasterArduino.ino:1:0:

C:\\Documents\Arduino\libraries\SimpleModbusMaster/SimpleModbusMaster.h:142:14: note: declared here

 unsigned int modbus_update(Packet* packets);

              ^

Multiple libraries were found for "SimpleModbusMaster.h"
 Used: C:\\Documents\Arduino\libraries\SimpleModbusMaster
 Not used: C:\\Documents\Arduino\libraries\SimpleModbusMasterV2rev2
 Not used: C:\\Documents\Arduino\libraries\SimpleModbusMasterV12
exit status 1
'modbus_construct' was not declared in this scope
 

Patrik_Fernandes

Good Morning,
Using the simplemodbusmaster library it is possible to use this packet format so that I can use the maximum register (28), in this small test when I execute only first line connection ok, reading ok, when I run the two lines, OK connection, NOK reading , displays zero values.

 
Code: [Select]
 
  modbus_construct(&packets[PACKET1], 10, READ_HOLDING_REGISTERS, 1024, 8, 10);
  modbus_construct(&packets[PACKET1], 10, READ_HOLDING_REGISTERS, 1038, 6, 19);



visualizing the code I noticed that the records run through an array, but I'm not sure how the packages work on this occasion.
Another detail I'm using STM32F103 (BluePill), with some changes I made the library functional, if anyone interested.

cooldaddy

hallo all, im noob, just want ask something,

1. modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0, 6, 0) --> i read from simplemodbusmaster guide ... how i can get "1" ? its declare how many slave?

2. 0,6,0--> please explain that number , where it come ?

3. regs
  • what that mean ? why people put different number? it declare some thing at whole coding?


i m trying understand this structure and so many people post code with different number so confusing

thanks .... 

noiasca

following page 2 and 9 in  SimpleModbusMasterManual.pdf for your example


the first parameter is the packet pointer
1,                                             ... the slaves modbus adress
READ_HOLDING_REGISTERS,     ... the function you use to access the register on your device
0,  ... start adress where you start reading
6, ... how many bytes do you want to read
0 ... the start byte of your holding register (where to store the received data)
 

to set this parameters correct it is essential to have a datasheet available of your slave wherein you have detailed information about
- how to set up the device adress,
- what registers are available
- using which function,
- and how the data is encoded
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

cooldaddy

hallo again,

I dont know this is repost or not, my reply didnt shown at my computer

following tk4s communication address as below :
https://www.instrumart.com/assets/Autonics-TK-communication-manual.pdf

Im trying read PV @ input_register_address

1. it said address 17 from master, but at colum it writen 11H, which one is slave modbuss address ?

2. Start address is 1000? im counting 3001001 - 300001 = 1000 or 3E8, should I use 0x1000 or 0x3E8 ?

3. About how many byte, i must count all byte from slave address, data, function until CRC so its 8 byte ? or only need 1 byte for read data only ?

4. start byte og input register is 300001 so it will 1 ?

5. regarding #define TOTAL_NO_OF_REGISTERS ( ? ) because i just read PV so it will be #define TOTAL_NO_OF_REGISTERS 1 ?

6. TOTAL_NO_OF_REGISTERS will be declare at regs [1] ? since only read PV?

Thanks in advance

Ian7Goodwin

Hi Andrew,

Did you get this working?

Regards

Ian G

Rizky_recycle


I am a beginner, does anyone have a modbus code example for powerlogic pm5350?
Please help me. thanks .

masterx

Hi guys,

I am trying to read DDM1000CTR 3 phase device over Modbus RTU and I am receiving 16323 as a value, but it should be float in kWh.
Please check attached image, it's software ShortBus Modbus Scanner I used to test and it works with proper configuration.

Please can someone help me with sample for arduino, how to setup same thing as on PC software.
I do not know how to swap byte order and read result as floating point.

Thanks


calebishaya

Hello Guys, As a fellow Arduinoist.

I need your advice, (Most especially from JuanB, Rockwallaby, Noiasca, or anyone with a reliable product)


I have devices with RS485 ports and MODBUS protocol. I want to be able to read and

write data from these devices from a remote site on a website. I have been reading through this thread for a

while now, I observed that few guys have been developing products (i hope for the market) for SCADA.

I don't have the time to develop my own and I don't want a product that is not flexible, I want a device that   

will be programmable. With such a community, I believe you can help me.

Thanks

noiasca

long answer:
Quote
I want to be able to read and write data from these devices from a remote site on a website.
the simplemodbus Master library - we are talking about in this thread - is perfect for reading data over and over again. It's not the preferred way to write data once. Therefore, if you want to write single values to your slave, you should search for another library.

Quote
I don't have the time to develop my own
sure?

It's as simple as that: out of three given parameters
- time to be invested by you
- money for the project
- expectations to the final product

you can either invest more money or you reduce your expectations if you have no time.

Quote
and I don't want a product that is not flexible, I want a device that   
will be programmable. With such a community, I believe you can help me.
If you have a look at some of the modbus test tools for PCs, you'll see how complex a "flexible" software is. You might be able to imagine what work would be necessary to do something similar on an Arduino. I assume most of us only have implementations for their specific requirements, with limited support of their needed slave devices. I don't say that it wouldn't be possible, but for what use case? Either I need something dedicated for my purpose - or something to test my slaves. And if I want to test, I choose my PC.

So my final advices:
- Consider to invest LOT OF YOUR TIME.
- If you need support for your devices, post a CLICKABLE link to the manual, where we can clearly see the modbus registers. Tell us the exact page, where this information starts.
- tell us, for what hardware platform you are developing,
- provide a schematic of your wiring and a real picture of your setup
- State a clear question, clear enough for  even for non-native speakers like me ;-)

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

Go Up