Page 1 of 1

Modbus TCP Master Slave read

Posted: Tue Oct 05, 2021 12:23 pm
by jollybv
Hi Guys

I'm really battling trying to read the values from the slave in the master, I have searched and searched and watched Ben's modbus videos but can seem to get it right. It is probably something really simple but cant figure it out. In the modbus slave I SetAnalogInput (0, feedback) see below
Modbus slave.png
Modbus slave.png (269.44 KiB) Viewed 2885 times
then in the master i read analog ID 0, address 0 , count 1 if that returns a 0, then I call GetResponsInt(0) and pass that to a numeric indicator (see below)

Modbus TCP Master.png
Modbus TCP Master.png (82.95 KiB) Viewed 2885 times
I'm able to turn the system on, change the probes and change the set value (SV) from app developer, I'm just not able to read the temperature (PV) from the slave on the master.

Re: Modbus TCP Master Slave read

Posted: Wed Oct 06, 2021 10:18 am
by BenR
Hello,

The GetResponseInt function requires a parameter of 3 to pull out the first data value. That's the position of the first data byte in the slave reply.
IndexParam.jpg
IndexParam.jpg (25.99 KiB) Viewed 2858 times
You should also be able to see the data flowing back and forth in the console if you want to debug if the slave is replying correctly. Hopefully this helps.

Re: Modbus TCP Master Slave read

Posted: Wed Oct 06, 2021 4:33 pm
by jollybv
Hi Ben

Thanks for the reply I have changed it to 3 If i look in the console it all looks fine so what it looks like it is that I'm not putting the data in the SetAnalogInput(0,PV)
console 1.png
console 1.png (29.76 KiB) Viewed 2824 times
Is there a step I'm might be missing that i should do before I call the ModbusSlave1::SetAnalogInput(0,PV)? or can i call it anywhere in the slave program by itself

I have made a master and slave examples to try see what I'm doing wrong
PID_APP_1.fcsx
(29.49 KiB) Downloaded 106 times
modbus_ analog_ receive.fcfx
(33.04 KiB) Downloaded 102 times

Re: Modbus TCP Master Slave read

Posted: Thu Oct 07, 2021 10:51 am
by BenR
Might be worth looking at the TCP/IP tabs of the console and there you can see the data bytes going back and forth.

Program looks ok to me and yes the set value in the slave can be done at any time.

It might be worth loading the slave with a known value e.g. 0x5859 (ASCII XY) after initialising the Modbus and then you can try and pinpoint where the comms is breaking.

Re: Modbus TCP Master Slave read

Posted: Thu Oct 07, 2021 2:20 pm
by jollybv
Hi Ben

If I'm understanding you I loaded SetAnalogInput(0,0x5859) strait after I initialize the modbus slave then check at the TCP/IP In the console to see if I get the XY. What I am getting on the numeric indicator in app developer is Error every time I call the SetAnalogInput(0,0x5859) but every time I call the SetAnalogInput(0,PV) I get 0.00

the only thing i am getting in the TCP/IP console is NULL
TCPIP.png
TCPIP.png (16.74 KiB) Viewed 2809 times
What I have noticed is that when I put a value say of 35 where 0x5859 I do not get the Error displayed on the numeric indicator just 0.00 Is this not a fault in the ESP-32 WROOM component?
I have also tried putting the SetAnalogInput(0,35) in a loop straight after I initialize the modbus TCP slave and set the data every 3 seconds with no luck :?

I would really like to solve this problem as I want to test the project out on my still over the weekend

Re: Modbus TCP Master Slave read

Posted: Fri Oct 08, 2021 10:32 am
by BenR
Ok thanks,

I'll try and replicate the problem here for you and see how I get on.

Re: Modbus TCP Master Slave read

Posted: Fri Oct 08, 2021 10:59 am
by BenR
I've had a go and it seems that the Analogue input is working but is currently only passing the MSB byte, the LSB byte is being passed as 0.

Seems the RegCount is being read as number of bytes and setting this to 2 allows the full 16-bit data to be received.

ModbusMaster.fcsx
(11.08 KiB) Downloaded 104 times
ModbusSlave.fcfx
(27.51 KiB) Downloaded 112 times

I'll get this fixed for you.

Edit, seems to be fixed now via the update system, let me know how you get on.

Re: Modbus TCP Master Slave read

Posted: Fri Oct 08, 2021 3:21 pm
by jollybv
Thanks Ben

It seems to be working now :) I did go and try the library update but no updates yet