Modbus TCP Implementation

daniel.kjellstrom
Posts: 9
Joined: Thu Nov 22, 2018 5:08 pm

Modbus TCP Implementation

Postby daniel.kjellstrom » Mon Feb 03, 2020 7:08 pm

Hi,

I'm trying to implement Modbus over TCP since I saw on the documentation that the TCP mode was already implemented as well as RTU and ASCII. When I tried to configure it I couldn't find any documentation and I read on one of the topics in this forum that back in July you guys were discussing about it. Now I saw that apparently it is coming out on v4.0. Is it correct? I'm running on the stable branch, would it be possible to access to an early implementation if I switch to the master branch? Is there anywhere I could find the configuration documentation?

Thank you very much in advance!
Cheers,

Daniel

harshal
Posts: 1
Joined: Wed Feb 26, 2020 1:34 pm

Re: Modbus TCP Implementation

Postby harshal » Wed Feb 26, 2020 2:04 pm

I am also looking for MODBUS TCP/IP protocol. Let us know if any update on this.

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus TCP Implementation

Postby ESP_alisitsyn » Mon Mar 09, 2020 2:51 pm

Hi @harshal, @daniel.kjellstrom,

I apologize for the delay with answer. There is a working version of Modbus TCP support in the ESP_IDF but it is still not released because of the testing issues. I propose to wait for official release. The TCP stack will use the same API with small modification in communication structure.

--
Alex

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus TCP Implementation

Postby ESP_alisitsyn » Fri Jul 24, 2020 5:47 am

HI harshal, daniel.kjellstrom,

I would like to inform you that Modbus TCP Master/Slave code has been merged and will be available at GitHub. There are example applications for master and slave with support of mDNS option to resolve slave IP addresses. The example test script can be used to check communication between master and slave over TCP (support Ethernet and WiFi phy interface).
Let me know if you have questions.

--
Alex

dkaufmann
Posts: 24
Joined: Wed May 17, 2017 9:06 am

Re: Modbus TCP Implementation

Postby dkaufmann » Tue Aug 18, 2020 6:42 am

Dear all,

I have 1 question. I have several Holding register areas but I cannot only define one.
For example
HREG area 1: 1000 to 1100
HREG area 2: 2000 to 2100
...

I could only find out how to set it up if all addresses are within 1 block.
Can you help me how to do it?
Best would be a general read and write callback for holding registers based on event where I can return a value based on the requested address.

best regards
DK

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus TCP Implementation

Postby ESP_alisitsyn » Wed Aug 19, 2020 8:02 am

Hi dkaufmann,

Could you tell me little bit more about your application? Is this Modbus master TCP or slave?

dkaufmann
Posts: 24
Joined: Wed May 17, 2017 9:06 am

Re: Modbus TCP Implementation

Postby dkaufmann » Thu Aug 20, 2020 9:39 am

Hi,

I use a Modbus TCP slave (server) and I have defined addresses of holding registers which are not within 1 address range:

For example
HREG area 1: 1000 to 1100
HREG area 2: 2000 to 2100
...
So between 1100 and 2000 are no valid addresses. So I wanted to create several holding register areas but it seems to be not possible.

This would be the holding register data_type declaration:

Code: Select all

#pragma pack(push, 1)
typedef struct
{
	uint16_t regs1000[100];	// 1000 - 1099
	uint16_t regs2000[100];	// 2000 - 2099 
	// ...

} holding_reg_params_t;
#pragma pack(pop)
How can I define the offset between regs1000 and regs2000?
I also tried to declare 2 types of holding registers, that I can specify different reg_area for each but it did not work because

Code: Select all

ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area1));
ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area2));
does not work as the second line replaces the first occurrence.

thank you for you assistance.

best regards
DK

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus TCP Implementation

Postby ESP_alisitsyn » Tue Aug 25, 2020 1:27 pm

Hi,

Currently the Modbus stack supports definition of only one registers descriptor per each register area. It is defined in mbc_slave.h::mb_slave_options_t::mbs_area_descriptors[] array. In order to realize this functionality the array or list of descriptors should be created per each register area type and assigned using the mbc_slave_set_descriptor(). In addition the r/w callback mbc_tcp_slave.c::eMBReg___CBTcpSlave() functions should be updated to check all available descriptors.
This change can be implemented later in future releases.

dkaufmann
Posts: 24
Joined: Wed May 17, 2017 9:06 am

Re: Modbus TCP Implementation

Postby dkaufmann » Tue Aug 25, 2020 3:05 pm

Hi,

thanks for the information. So it means currently my problem cannot be solved, right?
In my opinion it would be very helpful if there was a read and write callback function which is called on each read/write request from the master (independent if rd/wr single or multiple register). In the callback function a mapping for each address, which content should be returned. In the write callback routine, write functions can be called in order react on the write requests. Is that somehow possible to program using the Modbus TCP library from ESP-IDF?
Before I used Arduino IDE with Modbus TCP library from A. Emelianov (https://github.com/emelianov/modbus-esp8266) which has these callbacks. But I would like to get rid of the Arduino IDE as ESP-IDF component, so it would be nice if the ESP-IDF Modbus TCP library would offer read/write callbacks similar to this library from A. Emelianov. Do you agree?

thanks and best regards
Dominik

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus TCP Implementation

Postby ESP_alisitsyn » Fri Aug 28, 2020 8:45 am

Hi Dominik,

The current Modbus code uses similar approach with read/write register callback functions which are called from modbus function handler as described in post above but the difference is that they are specific for concrete Modbus port and defined in each Modbus controller mbc_%port%_%client_type%.c (example: mbc_serial_master.c). They are called on any read/write access of master/slave accordingly and mapping should be implemented there to support several address spaces for each register type. The current Modbus component uses different architecture compare to code you linked but this approach is similar. I agree it is better to implement them as part of common master or slave modules instead and it is possible to implement. I understand your request and will try to implement similar way. However it is added to queue for now.

Who is online

Users browsing this forum: Google [Bot] and 101 guests