Autor Thema: Help with Modbus TCP  (Gelesen 35094 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

Anders

  • Gast
Help with Modbus TCP
« am: 11. September 2011, 07:27:41 »
Hi all !
I am fairly new to CodeSys v2.3.9.26 and need a little help with using the OSCAT libraries.
What I want to do is to control to a few FESTO Vision-cameras by either Modbus or Telnet from a Kontron HMI-PLC through TCP/IP.

I have added the oscat network lib in Codesys library manager. To understand how to use these oscat libs i planed to take a look at the demo code. All I see in the DEMO-folder is alot of program names like "MB_SERVER_DEMO (PRG)" and its function block. I have read in this forum that the demo-code should be copied into your project. I dont see any demo code besides the variable declarations? Nor do I know howto copy the demo-code into my project.

Also, if I "rebuild all" codesys gives 110 errors in the oscat lib, these error comes from the demo-code. Does this mean that the demo-code must be deleted before I can use the network lib? If so, how do I delete the demo-code? I havent be able to find any way to edit the oscat lib, as in remove the demo-code, or see the actual real programming behind the FB:s. Note that Ive never made a lib or FB myself so I might be unaware of something really basic on how to deal with libraries.

If I understand this correctly "MB_SERVER (FB)" is what I should use to talk Modbus to the cameras? In order to do that I will also need "IP_CONTROL" from what I read in the .PDF ?
I added both of them to a POU, but besides that I am not sure what to do to get them working?

Best regards
Anders

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re:Help with Modbus TCP
« Antwort #1 am: 11. September 2011, 12:14:02 »
1. open the network.lib as project
2. edit the target system/configuration
3. check the needed librarys (library.jpg)
4. exclude all demo objects from build
5. compile the library

6. open your project
7. import the oscat librarys
8. import the module "MODBUS_SERVER_DEMO.EXP"
9. now you can edit the demo module



[gelöscht durch Administrator]

Anders

  • Gast
Re:Help with Modbus TCP
« Antwort #2 am: 11. September 2011, 17:22:53 »
Hi Peewit, thank you for helping!

>1. open the network.lib as project
>2. edit the target system/configuration
No problem

>3. check the needed librarys (library.jpg)
In your picture you have oscat.lib
That one i could not find, so i downloaded the oscat basic for codesys 2 from oscat.de downloadpage.

>4. exclude all demo objects from build
I found no way select that demo-folder for exclusion, so I deleted it and its objects.

>5. compile the library
These seems to be very big libs. It refuses to compile due to too many POUs. More than the PLC:s default value of 1024. I changed that to 2048 just to see if it would compile, and it did. 1034 POU:s reported. Tho I dont know if the PLC will crash if I change the number of POU:s or if i can keep it at 2048?
Another way would be to delete not needed stuff in the oscat basic lib? I assume i can do that the same way as with the demo code in network.lib
Not sure what safely can be deleted and what to keep, its a huge lib.


>6. open your project
>7. import the oscat librarys
>8. import the module "MODBUS_SERVER_DEMO.EXP"
I see you added the IP_CONTROL2 so I assume thats the one i want :-)

>9. now you can edit the demo module
How do I add the IP-adress 192.168.0.198 as a double word to the FB IP_CONTROL2 ?
Cant find any instructions on how to convert it.

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re:Help with Modbus TCP
« Antwort #3 am: 11. September 2011, 18:11:56 »
Zitat
>5. compile the library
These seems to be very big libs. It refuses to compile due to too many POUs. More than the PLC:s default value of 1024. I changed that to 2048 just to see if it would compile, and it did. 1034 POU:s reported. Tho I dont know if the PLC will crash if I change the number of POU:s or if i can keep it at 2048?
Another way would be to delete not needed stuff in the oscat basic lib? I assume i can do that the same way as with the demo code in network.lib
Not sure what safely can be deleted and what to keep, its a huge lib.

you can use the "oscat_basic_micro_332.lib"

http://www.oscat.de/community/index.php/topic,1292.msg7346.html#msg7346
download link    http://www.oscat.de/community/index.php?action=dlattach;topic=1292.0;attach=1736

------------------------------------------------

the modbus-tcp server act as "server"
you don't need any ip-address


any client send a request to the server and the server send the response (modbus-registers) return to the client

see document "Modbus_Messaging_Implementation_Guide_V1_0b.pdf"    chapter 1.2



what do you want ???

I think you need the modbus_tcp_client  module ?

FESTO Vision-cameras = MODBUS_TCP SERVER
HMI-PLC through TCP/IP = MODBUS_TCP CLIENT




[gelöscht durch Administrator]

Anders

  • Gast
Re:Help with Modbus TCP
« Antwort #4 am: 11. September 2011, 21:38:54 »
"oscat_basic_micro_332.lib" - Perfect, POU dropped to 343.

I thought the PLC would be Server, and the Cameras (will have three cameras total) slaves. It seemed logical that the PLC acted as Server and sent configuration data to the three slaves (cams). But I have no previous experience with Modbus and Visioncameras, so you are surely right that it is the three Cam:s that are Servers then.

I have replace the Server demo-code with demo MB_CLIENT.
There is an instruction asking for the IP to the Modbus TCP-server. To start with I will enter one of the camera's IP there.

I will read the 50 pages manual 'Modbus_Messaging_Implementation guide' to gain a better general understanding of how Modbus works. Thanxs for the link.

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re:Help with Modbus TCP
« Antwort #5 am: 11. September 2011, 22:17:20 »
modbus serial = master/slave model

master     ->
               <-       slave

The MODBUS Serial Line protocol is a Master-Slaves protocol. Only one master (at the same time) is connected to the bus, and one
or several (247 maximum number) slaves nodes are also connected to the same serial bus. A MODBUS communication is always
initiated by the master. The slave nodes will never transmit data without receiving a request from the master node. The slave nodes
will never communicate with each other. The master node initiates only one MODBUS transaction at the same time.
---------------------------------------

modbus tcp = client/server model

client       ->
               <-           server

The MODBUS TCP messaging service provides a Client/Server communication between devices connected on an Ethernet TCP/IP network.
This client / server model is based on four type of messages:
• MODBUS Request,
• MODBUS Confirmation,
• MODBUS Indication,
• MODBUS Response

A MODBUS Request is the message sent on the network by the Client to initiate a transaction,
A MODBUS Indication is the Request message received on the Server side,
A MODBUS Response is the Response message sent by the Server,
A MODBUS Confirmation is the Response Message received on the Client side


[gelöscht durch Administrator]
« Letzte Änderung: 11. September 2011, 22:47:42 von peewit »

Anders

  • Gast
Re:Help with Modbus TCP
« Antwort #6 am: 12. September 2011, 01:06:34 »
Ahh, I see! The way you explain Modbus Serial is the way I thought it works. I had no idea that Modbus TCP is different from Modbus Serial. I thougt it was the same thing. Very good info, interesting to say the least  :)

Time to hook up the first camera and see what settings it got inside.
Next I think its time to have a go at that vmap stuff :)
Basically if that works.. (!) then they should be able to communicate... i think  ;D

AndersS

  • Gast
Re:Help with Modbus TCP
« Antwort #7 am: 13. September 2011, 17:48:11 »
Hi, dont know what happend to my first account "Anders" The username doesnt work  :'(
Also the site says i am on an blocked ip-range so I should contact 'us' to register.
The problem is... there is no email adress to write to 'us' so how are people supposed to do that?  ::)


Anywayz, back to the real problem & solution!  :)
This afternoon we got it working!!!!
I skipped the vmap-idea and will read/write directly to specific registers in the camera. That supposedly generates less traffic on the network, and seems simpler too.

I went through the trouble to re-register just to thank you properly for all your help Peewit. I dont think I'd get it working without your assistance, surely not this fast. So I just wanted to let you know it is very much appreciated. :D




Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re:Help with Modbus TCP
« Antwort #8 am: 13. September 2011, 23:11:39 »
thanks for the nice words


Offline tobias

  • Administrator
  • *****
  • Beiträge: 43
    • Profil anzeigen
Re:Help with Modbus TCP
« Antwort #9 am: 14. September 2011, 14:57:03 »
now your account should work fine

it is certainly not smart to use spam1 in your email address.

just to give you an idea: to keep this forum clean we need to delete over 90% of all registered accounts


AndersS

  • Gast
Re:Help with Modbus TCP
« Antwort #10 am: 14. September 2011, 23:33:35 »
Hi Tobias,
The first account still doesnt work, but this second one does so its good :)

I would have expected admins to read my first post, and from the content decide if its spam or genuine? Thats usually how it works from what I understand. But with 90%(!) spammers you might need to cut corners I suppose.
I use spam1@ as an account I can 'throw away' if it starts to pop in spam. I wasnt sure about this site so better to be on the safe side. Seems we both had the same idea  ;D

Best regards
Anders

Offline inovent

  • Newbie
  • *
  • Beiträge: 13
    • Profil anzeigen
Re: Help with Modbus TCP
« Antwort #11 am: 11. September 2012, 10:35:50 »
hi :-)
at first i have to say,  oscat is the best :-)

but there is still a little question:
 what is the difference between "R_ADDR" and "R_DATA_ADR"
i dont know what i have to put in there.
i want to read some registers (FC = 3) of an Pilz Pnozmulti.

can anyone give me a little example please

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re: Help with Modbus TCP
« Antwort #12 am: 11. September 2012, 11:41:15 »
R_ADDR:  Read command: MODBUS data point address from Pilz Pnozmulti

R_DATA_ADR: Read command: DATA data point address
                       defines where the read data is stored (offset lokal data structure)

Example
Command FC 3 (Read Register)
R_ADDR = 10
R_POINTS = 4
R_DATA_ADR = 5

Read the modbus register 10,11,12,13 from the device
and store the data in the local structure  on index 5

Register 10 = data[5]
Register 11 = data[6]
Register 12 = data[7]
Register 13 = data[8]