RPI modbus TCP

Moderator: Benj

EtsDriver
Valued Contributor
Valued Contributor
Posts: 410
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 328 times
Been thanked: 210 times
Contact:

RPI modbus TCP

Postby EtsDriver » Fri Jun 15, 2018 8:05 am

Hi!

After couple of tries, i think theres something wrong with the RPI tcp/ip component or modbus tcp component.

Whenever i try to establish connection between modbus master and rpi, the rpi seems to not pick up...

Not near my pc at the moment, so cannot attach example program.. Just take modbus tcp slave example, target raspberry pi 3, add rpi tcp/ip stack, attach to modbus tcp slave-->rpi stack.
Run on rpi and try to connect to modbus server using master simulator.

Port setup to 502(generic modbus port).
Ill just keep the good work up!

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Fri Jun 15, 2018 9:42 am

Hello,

There are problems with the Modbus TCP component at the moment, they work well in simulation but they have problems with embedded devices including the RPI. I have tried several workarounds but currently the solution eludes me. I'll keep trying.

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Fri Jun 15, 2018 11:28 pm

I've been thinking on it and think I have a solution. Hopefully I can have this running for you early next week.

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Apr 18, 2019 11:47 am

Hi,

I have also been trying to get this working, was the issue resolved?

Best Regards,

James

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Thu Apr 18, 2019 11:49 am

Hi James,

Yes this issue has been resolved. Can you post your program and I'll have a look for you.

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Apr 18, 2019 2:42 pm

Hi,

Thanks, please see attached.

Best regards,

James.
Attachments
remote.fcfx
(10.45 KiB) Downloaded 22 times

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Apr 25, 2019 7:55 am

Good Morning Ben,

Did you get a chance to take a look at this? Am i doing something wong or is there a bug?

Best Regards

James

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Thu Apr 25, 2019 1:16 pm

Hi James,

I've had a look at the program and coudn't see any major issues.

What are you using as the Master to generate the requests?

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Apr 25, 2019 2:51 pm

Hi Ben,

I use Abacom profilab, which connects fine but returns random numbers, not the values written to the registers.
https://www.electronic-software-shop.co ... anguage=en

The same software works fine using modbus serial. I have the same problem using arduino, see my other thread, hence now trying raspberry pi, who’s networking component is supported by yourselves.
I use the Abacom Profilab modbus tcp software extensively with commercial brain boxes ED series modules with no issues at all.
A good fee modbus test utility is qModMaster. http://domoticx.com/modbus-software-qmodmaster-windows/

In essence everything is proven. It’s just the modbus TCP component returns "random" values.

Best Regards

James

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Tue Apr 30, 2019 8:01 am

Hi,

To give some more information on this issue, I get exactly the same results in simulation, which i have to admit i did not try before :roll:

Capture1.PNG
Capture1.PNG (7.18 KiB) Viewed 1400 times


Capture2.PNG
Capture2.PNG (4.18 KiB) Viewed 1400 times


As you can see, both values should be "1". I am not sure where 27887 comes from?

What software are you using to test this, maybe i can try that?

Best Regards

James

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu May 02, 2019 7:56 am

Good Morning Ben,

Have you had a chance to look at this? Are you able to tell me what client you use for testing?

As it does not appear to work in simulation, and you cannot find an issue with my program, which essentially follows the example, can i assume this is a bug?

Sorry if this is not the correct way to get support on this issue!

Best Regards,

James.

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Tue May 07, 2019 1:02 pm

Hi James,

I used Flowcode to test the Modbus TCP master and slave working together. It might be worth trying this to see if it's any better.

As for the example you posted, can you confirm Analog1 and Binary1 have been loaded with 1's?

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Wed May 08, 2019 10:29 am

Hi Ben,

I will give a flowcode to flowcode link a try and see what that gives.

I have tried loading both analog and binary with different values, and they never resemble what I read. The exception is binary, which has a 50% chance of being right!

I say this as if I make repeated coil read requests, I get 0 and 1 returned on alternate reads, regardless of how the register has been set.

The analog seems to return a random number, again regardless of what has been set in the program. I can also read registers that are not there, for example if I try to read 10 registers; I get 10 different values back, despite only one register being defined. It is almost like there is a disconnect between the registers that are being written, and the memory located the server is reading values from.

I would just like to reiterate that this all works fine using modbus serial, it is only in the move to TCP that this issue has arisen.

Best Regards,

James

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Wed May 08, 2019 2:18 pm

Hi,

I have just found the component debug console, and this is what it is showing me. I am not sure what this means?
Attachments
Debug Capture.PNG
Debug Capture.PNG (43.86 KiB) Viewed 1310 times

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Wed May 08, 2019 2:58 pm

Hello,

Exception address means the address is out of range for the current Slave properties.

Try address 0 instead of address 1. Hopefully this will solve the problem.

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Wed May 08, 2019 3:05 pm

HI,
Sorry, i just realised. I did it the other way around and requested adress 1 instead of 0 and now the console reports the correct value, but the master still reports a random number (26060) instead of 255

Debug Capture 3.PNG
Debug Capture 3.PNG (5.29 KiB) Viewed 1306 times
Debug Capture 2.PNG
Debug Capture 2.PNG (4.39 KiB) Viewed 1306 times

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu May 09, 2019 9:25 am

Hi Ben,
I have taken some steps to try and pin this issue down further.
1. I have modified my program to accept an binary and analog value from the master, then set those to be read back again in order to test the ability to write values master>slave. Up until now I have only tried to read values. I am happy to report that using the consol output I can see that this works fine, I can write values without issue, and these are read correctly in the console view. The consol also shows the correct values being given in response to the masters requests, however, the actual values read do not match those the consol says it is giving, as seen in pervious tests.
2. As per your suggestion I have written a modbus master flowcode program to write values to the slave, then attempt to read them back. The values are successfully written according to the slave consol, however the master consol actually says “no reply” although the values have been received and set by the slave. When the master attempts to read the values back, the master console again says no reply, and the values are not received, although the slave consol reports it has replied with the values written.
I certainly seems there is something wrong with reading values from the modbus slave. I have tried different clients, and they ether read nonsense, or reply with no connection.
I have attached both flowcode programs, I would be most grateful if you could take a look and see where I, or the software, is going wrong.

Best Regards

James
Master.PNG
Master.PNG (8.35 KiB) Viewed 1292 times

Slave.PNG
Slave.PNG (4.56 KiB) Viewed 1292 times
Attachments
remote_test.fcfx
(12.53 KiB) Downloaded 15 times

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu May 09, 2019 9:25 am

And the master program.
Attachments
remote_test_master.fcfx
(11.22 KiB) Downloaded 15 times

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Tue May 21, 2019 9:55 am

Hi!,

As suggested I have created a flowcode master/slave combo, which should work in simulation, please see above. I would be most grateful if somebody could take a look and confirm if this is a bug, or give me an idea where I am going wrong!

James.

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Wed May 22, 2019 3:25 pm

Hi James,

These are working well for me in simulation.

ModbusTCPMasterExample.fcfx
(10.45 KiB) Downloaded 38 times

ModbusTCPSlaveExample.fcfx
(11.03 KiB) Downloaded 33 times


I'm pushing these to the Wiki now as the files there do seem to have a problem in that they were missing the network comms components!?

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Fri May 24, 2019 6:10 pm

Hi Ben,

Thankyou, as you say, these examples work well together. I am trying to use them to see where i am going wrong, but am hindered by what really does seem to be a bug.

I load both examples and run them, everything is fine. if you stop the slave simulation, and restart it, it no longer works. i have to close the example, reload it, then it works again.

I can also get them to behave as my examples above, where the registers are actually written, but the master says no reply. Unfortunatly i have been unable to pin down the exact conditions when this happens, but reloading fixes it.

Hopefully you can recreate the "works once" issue above?

Best Regards

James

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Tue May 28, 2019 2:06 pm

HI,

Further to the above, I note that while your example writes a binary value maste>salve, it does not read it back.
If i add this line to your example to read the binary value back.

Capture1.PNG
Capture1.PNG (21.1 KiB) Viewed 1100 times


I get the reponse.

Capture2.PNG
Capture2.PNG (3.69 KiB) Viewed 1100 times


Which i think clearly shows there is an issue reading values.

I have put a lot of time into trying to pin this down, do you agree from my eamples that the modbus tcp slave component is not issuesing correct responses to master requests?

Best Regards,

James

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Jun 06, 2019 7:54 am

Hi Ben,

Sorry to nag but you did ask me to! Have you had a chance to look at this?

Best Regards

James
These users thanked the author jhill for the post:
Benj (Tue Jun 11, 2019 10:13 am)
Rating: 5.56%
 

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: RPI modbus TCP

Postby Benj » Tue Jun 11, 2019 10:24 am

Hi James,

Many thanks for keeping on with this and sorry for the delay. I've now managed to have a look and hopefully fixed the problem where we were getting incorrect reply. I've tested the readback of the various types of storage and all seem to be working fine now too. I've pushed the updated component to the v8 update system now.

As for stopping and restarting the sim I'm investigating this for you now to try and find where the problem could be. Edit this has now also been fixed :D
These users thanked the author Benj for the post:
jhill (Thu Jun 13, 2019 7:02 am)
Rating: 5.56%
 

jhill
Posts: 47
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: RPI modbus TCP

Postby jhill » Thu Jun 13, 2019 7:02 am

Good Morning!

Thats great news, thankyou! :D I will take a look today!

Best Regards,

James.
These users thanked the author jhill for the post:
Benj (Thu Jun 13, 2019 9:32 am)
Rating: 5.56%