Modbus TCP Master Slave read

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jollybv
Posts: 125
http://meble-kuchenne.info.pl
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

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 2832 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 2832 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: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 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 2805 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.

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

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 2771 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 103 times
modbus_ analog_ receive.fcfx
(33.04 KiB) Downloaded 99 times

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 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.

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

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 2756 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: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 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.

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 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 102 times
ModbusSlave.fcfx
(27.51 KiB) Downloaded 108 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.

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

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