Modbus TCP Master Slave read

Post Reply
jollybv
Posts: 45
http://meble-kuchenne.info.pl
Joined: Mon Mar 08, 2021 11:25 am
Has thanked: 17 times
Been thanked: 1 time

Modbus TCP Master Slave read

Post 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 439 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 439 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.

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: Modbus TCP Master Slave read

Post 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 412 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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel

jollybv
Posts: 45
Joined: Mon Mar 08, 2021 11:25 am
Has thanked: 17 times
Been thanked: 1 time

Re: Modbus TCP Master Slave read

Post 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 378 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 12 times
modbus_ analog_ receive.fcfx
(33.04 KiB) Downloaded 19 times

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: Modbus TCP Master Slave read

Post 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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel

jollybv
Posts: 45
Joined: Mon Mar 08, 2021 11:25 am
Has thanked: 17 times
Been thanked: 1 time

Re: Modbus TCP Master Slave read

Post 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 363 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

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: Modbus TCP Master Slave read

Post by BenR »

Ok thanks,

I'll try and replicate the problem here for you and see how I get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: Modbus TCP Master Slave read

Post 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 18 times
ModbusSlave.fcfx
(27.51 KiB) Downloaded 17 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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel

jollybv
Posts: 45
Joined: Mon Mar 08, 2021 11:25 am
Has thanked: 17 times
Been thanked: 1 time

Re: Modbus TCP Master Slave read

Post by jollybv »

Thanks Ben

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

Post Reply