Go Down

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

ismailsinapli

#810
Aug 25, 2019, 10:46 pm Last Edit: Aug 25, 2019, 11:19 pm by ismailsinapli
Hi JPrust,

Maybe you will need this line of code:
Code: [Select]

modbus_configure(&Serial, 19200, SERIAL_8N2, DEVICE_ID, TxEnablePin, HOLDING_REGS_SIZE, holdingRegs);
// modbus_update_comms(baud, byteFormat, id) is not needed but allows for easy update of the
// port variables and slave id dynamically in any function.
modbus_update_comms(19200, SERIAL_8N2, 1);




As you declared in your code, register of VAL_LED is READ register (address 0) and VAL_POT(address 1) is WRITE register. So, in HMI you can access with address 40001 for VAL_LED (HMI write value into this register such as button input) and 40002 for VAL_POT(HMI will read from this register such as number display?).

Why 40001 and 40002? Because in Delta HMI register address, address 0 will be 40001, so if you need to access register 10, it will be 40011 in Delta HMI. and the data will be WORD.

Hop it will help.

Thanh Nguyen

Hi JPrust,

Maybe you will need this line of code:
Code: [Select]

modbus_configure(&Serial, 19200, SERIAL_8N2, DEVICE_ID, TxEnablePin, HOLDING_REGS_SIZE, holdingRegs);
// modbus_update_comms(baud, byteFormat, id) is not needed but allows for easy update of the
// port variables and slave id dynamically in any function.
modbus_update_comms(19200, SERIAL_8N2, 1);


As you declared in your code, register of VAL_LED is READ register (address 0) and VAL_POT(address 1) is WRITE register. So, in HMI you can access with address 40001 for VAL_LED (HMI write value into this register such as button input) and 40002 for VAL_POT(HMI will read from this register such as number display?).

Why 40001 and 40002? Because in Delta HMI register address, address 0 will be 40001, so if you need to access register 10, it will be 40011 in Delta HMI. and the data will be WORD.

Hop it will help.

Thanh Nguyen

Hi JPrust,

Maybe you will need this line of code:
Code: [Select]

modbus_configure(&Serial, 19200, SERIAL_8N2, DEVICE_ID, TxEnablePin, HOLDING_REGS_SIZE, holdingRegs);
// modbus_update_comms(baud, byteFormat, id) is not needed but allows for easy update of the
// port variables and slave id dynamically in any function.
modbus_update_comms(19200, SERIAL_8N2, 1);


As you declared in your code, register of VAL_LED is READ register (address 0) and VAL_POT(address 1) is WRITE register. So, in HMI you can access with address 40001 for VAL_LED (HMI write value into this register such as button input) and 40002 for VAL_POT(HMI will read from this register such as number display?).

Why 40001 and 40002? Because in Delta HMI register address, address 0 will be 40001, so if you need to access register 10, it will be 40011 in Delta HMI. and the data will be WORD.

Hop it will help.

Thanh Nguyen

Hi JPrust,

Maybe you will need this line of code:
Code: [Select]

modbus_configure(&Serial, 19200, SERIAL_8N2, DEVICE_ID, TxEnablePin, HOLDING_REGS_SIZE, holdingRegs);
// modbus_update_comms(baud, byteFormat, id) is not needed but allows for easy update of the
// port variables and slave id dynamically in any function.
modbus_update_comms(19200, SERIAL_8N2, 1);


As you declared in your code, register of VAL_LED is READ register (address 0) and VAL_POT(address 1) is WRITE register. So, in HMI you can access with address 40001 for VAL_LED (HMI write value into this register such as button input) and 40002 for VAL_POT(HMI will read from this register such as number display?).

Why 40001 and 40002? Because in Delta HMI register address, address 0 will be 40001, so if you need to access register 10, it will be 40011 in Delta HMI. and the data will be WORD.

Hop it will help.

Thanh Nguyen

Hi vietnam friend you made the tube modbus communication dop panel, send me the arduino library
Mail.:  ismailsef@gmail.com

Send me the dop panel delta display software + arduino libraries + circuit diagram

ismailsinapli

Hi my  friend you made the tube modbus communication dop panel program send me the arduino library

https://youtu.be/94DY74uyIJk

solar_eta

Hi, I'm beginning to get very frustrated with loading modbus on to arduinos. I've used them for a number of years but now I need to use the 485 protocol.

After various false starts with the old libraries that the internet throws up I have just come across this thread and the 'simple-modbus-master' libraries. So I'm trying to use 'SimpleModbusMasterV2rev2' and 'SimpleModbusSlaveV10'. The examples given seem to be a compatible pair designed to talk to each other, something sadly lacking in the other things that my trawl has thrown up

However, I can't get the thing to compile for a Leonardo.

The Slave code fails with @C:\Applications\Arduino\arduino-1.6.8\libraries\SimpleModbusSlaveV10\examples\SimpleModbusSlaveArduino\SimpleModbusSlaveArduino.ino: In function 'void setup()':

SimpleModbusSlaveArduino:83: error: cannot convert 'Serial_*' to 'HardwareSerial*' for argument '1' to 'void modbus_configure(HardwareSerial*, long int, unsigned char, unsigned char, unsigned char, unsigned int, unsigned int*)'

  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);


Ive also tried IDE 1.8.9


Now early on in this thread JUGmobile says

'Leonardo as master:
In SimpleModbusMaster.cpp few lines of code needs to be changed. Since Leonardo uses Serial.xxx command for communicating over USB with computer, and Serial1.xxx for TX1/RX1 for communication with other arduinos (including this modbus protocol), the Serial.xxx needs to be changed to Serial1.xxx.'


Leonardo as slave:
In SimpleModbusSlave.cpp few lines of code needs to be changed. Exactly the same solution. Serial.xxx needs to be changed to Serial1.xxx.


What is unclear is does this change have to be made in the sketch or the library code. The only mention of Serial in the slave example is

"modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);"

So does &Serial need to become &Serial1. Or have I got to dismantle the .h and .cpp files?

Go Up