modbus problem "simplemodbusmaster"

hello, I’m working on simple project. could you help me?
my project:
when I press “set” button on HMI, then Led 13 on Arduino lights up.
when I press “reset” button on HMI, then Led 13 on Arduino lights off.

#include <SimpleModbusMaster.h>

//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 10 // the scan rate
#define retry_count 10 
#define TxEnablePin 2 

enum
{
  PACKET1,
  PACKET2,
  // leave this last entry
  TOTAL_NO_OF_PACKETS
};

Packet packets[TOTAL_NO_OF_PACKETS];

/////////////HMI READ////////////
packetPointer runHMI = &packets[PACKET1];

/////////////HMI WRITE///////////
packetPointer lampHMI = &packets[PACKET2];

/////////////////HMI READ VARIABLE////////////

unsigned int readRunHMI[1];

////////////////HMI WRITE VARIABLE/////////////

unsigned int writeLampHMI[1];

void setup()
{
  modbus_construct(runHMI, 3, READ_HOLDING_REGISTERS, 60, 1, readRunHMI);
  modbus_construct(lampHMI, 3, PRESET_MULTIPLE_REGISTERS, 100, 1, writeLampHMI);
  modbus_configure(baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
}

void loop()
{
  modbus_update();
  
}

could you help me?
regards

unsigned int readRunHMI[1];
unsigned int writeLampHMI[1];

One element arrays clearly indicate that you don't understand that you can use a scalar variable instead.

  modbus_construct(runHMI, 3, READ_HOLDING_REGISTERS, 60, 1, readRunHMI);
  modbus_construct(lampHMI, 3, PRESET_MULTIPLE_REGISTERS, 100, 1, writeLampHMI);
  modbus_configure(baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);

Magic numbers suck.

Failing to use the enter key, to eliminate the need to scroll to read the complete line sucks, too.

could you help me?

No, because you have not said what the problem is.

my project:
when I press "set" button on HMI, then Led 13 on Arduino lights up.
when I press "reset" button on HMI, then Led 13 on Arduino lights off.

You forgot the link to that HMI or better to it's manual.

if you want to get a register from your slave why do you need to call two registers with two different methods?

As other already asked: come up with a link to your slave device.
And additionally: clearly point out which simplemodbusmaster library you are using (LINK!!!)

thank you for respond
my devices are consist of Delta HMI (DOP-B10E615), Arduino UNO R3, MAX485.
I would like to commiunication on Modbus RS485 by 2 wires. and using “simplemodbusmaster” library.
I’m new at arduino and I can’t write right codes.
please check attachments & guide me.

SimpleModbusMasterManual.pdf (275 KB)

61RwZKsLCfL.SX425.jpg

Why do you need to call two registers with two different methods?

what do mean of “two different methods”?

check attachment for slave device datasheet(hardware). and here is a link for the software manual.

http://www.deltaww.com/filecenter/Products/download/06/060302/Manual/DELTA_IA-HMI_DOPSoft_UM_EN_20151116.pdf

best regards

DELTA_IA-HMI_DOP-B10S615-E615_Q_TC-EN-SC-TUR_20160714.pdf (1020 KB)

you are using two different methods according to your posted code

  modbus_construct(runHMI, 3, READ_HOLDING_REGISTERS, 60, 1, readRunHMI);
  modbus_construct(lampHMI, 3, PRESET_MULTIPLE_REGISTERS, 100, 1, writeLampHMI);

Why have you choosen READ_HOLDING_REGISTERS für Register 60 vs. PRESSET_MULTIPLE_REGISTERS for reading Register 100?

noiasca:
you are using two different methods according to your posted code

  modbus_construct(runHMI, 3, READ_HOLDING_REGISTERS, 60, 1, readRunHMI);

modbus_construct(lampHMI, 3, PRESET_MULTIPLE_REGISTERS, 100, 1, writeLampHMI);




Why have you choosen READ_HOLDING_REGISTERS für Register 60 vs. PRESSET_MULTIPLE_REGISTERS for reading Register 100?

I just used an example on youtube. according to the simplemodbusmaster manual:

Function 1 - READ_COIL_STATUS 1 // Reads the ON/OFF status of discrete outputs (0X references, coils) in the slave.
Function 2 - READ_INPUT_STATUS 2 // Reads the ON/OFF status of discrete inputs (1X references) in the slave.
Function 3 - READ_HOLDING_REGISTERS 3 // Reads the binary contents of holding registers (4X
references) in the slave.
Function 4 - READ_INPUT_REGISTERS 4 // Reads the binary contents of input registers (3X references) in the slave. Not writable.
Function 5 - FORCE_SINGLE_COIL 5 // Forces a single coil (0X reference) to either ON (0xFF00) or OFF
(0x0000).
Function 6 - PRESET_SINGLE_REGISTER 6 // Presets a value into a single holding register (4X reference).
Function 15 - FORCE_MULTIPLE_COILS 15 // Forces each coil (0X reference) in a sequence of coils to
either ON or OFF.
Function 16 - PRESET_MULTIPLE_REGISTERS 16 // Presets values into a sequence of holding registers (4X references).

could you give me a simple example for modbus?(Industrial HMI & Arduino)

An Example will not help you, because it should fit to your display.

I checked your attached PDF. This PDF only describes the electronic interfaces, i.e. which PIN is what in 8 different languages, wtf. Make a diagram and a picture of how you have connected to your hardware.

What you need is a datasheet, where the REGISTERS are described and with which function (1, 2, 3, 4,5, 6, 15,16...) you can read/write which register. Please check that on your own, where you can find that information. I will not read a 140MB documentation for you. Please check the 2000 pages on your own.

As it seems to me that this is a highly customizable display you have to "program/define" all that stuff on your own on the display. I don't have any information what you have done so far.

If this is your first Modbus project, I highly recommend following:

  • buy a simple Modbus device, a temperatur sensor or a relay board and experiment with that simple device to get knowledge about Modbus and how to implement simplemodbus on an Arduino
  • if you are familiar with Modbus and the library move on to the display

Frankly spoken: you want to fly to the moon but failed already to ride the bicycle to the next bus stop ...