Sign in to follow this  
Followers 0
italo2008

socket connection-rslogix5000: ladder logic with MSG instructions

14 posts in this topic

Hi (and sorry for my English....) I'm trying to establish a socket communication between a CompactLogix L43 (with 1768 eweb) and a pc. The pc is the server, eweb is the client. I want the PLC to send data to the pc, wich is waiting for incoming connections. So, what's the correct sequence of services that I have to write in ladder logic (using MSG instruction)? for example: a)open connection b)create socket c)write socket or a)create socket b)open connection c)write socket or others? and if is the pc that must send data to the PLC? thanks...

Share this post


Link to post
Share on other sites
A connection in this instance refers to a BSD socket library TCP connection, not the CIP term. So when you read the word "connection" in the manual with reference to Ethernet/IP, it is talking about the CIP interface. When you see the word "connection" in the sockets API chapter, it is referring to a BSD-style socket connection. So you first create a socket, then open a connection, and then read/write. Look at page 128 in the user manual for details. If you are using UDP, then see page 130. You do the same things except that you don't bother with opening/closing the connection (since UDP is connectionless). Either way, look for the ancient (early 90's) document on BSD sockets programming. For instance, this web site: http://www.frostbytes.com/~jimf/papers/sockets/sockets.html Sockets programming is very simple and obvious in the native language that it was developed in (K&R C). It makes less sense the further you move away from this. The BSD socket API is probably single-handedly one of the key reasons that the Internet came into existence. BSD sockets are easy to understand and program. The EWEB's module is necessarily "ugly" (sockets programming is a classic case of where BSD programming gets very ugly) but the basic concept is the same. You are manipulating a socket interface on a remote object in the EWEB module from MSG commands in the PLC. Think of it like viewing and interacting with the entire world from the end of a hose. You can do it but it is time consuming and ugly. Either way, it is probably far easier to just use the E-mail interface unless you are attempting to interface to something special that the PLC doesn't do. Any E-mail server running on the PC will take care of a lot of ugly details for you automatically. Polling the web pages from the PC side is also very simple. Lots of SOAP and RESTful type programming systems designed for the web (including code libraries in Python and Java) make interpreting the XML data files from the web server very simple to do. I know it sounds very clunky to use E-mail and web pages for this purpose but the reality is that LOTS of web applications work in exactly this manner because it turns out that the performance isn't nearly as horrible as it sounds. In fact, with the advent of COMET (which unfortunately you can't use in this case), you can actually "reverse" the connection on a web page...initiating action from the server rather than on the web browser. The only reason I'd attempt to use the sockets interface is if I'm trying to interface to a protocol that the PLC doesn't natively support and for some reason I can't have a PC involved as an intermediary. Usually I try to use a SCADA to do this and write all the code in the SCADA (where I can write native sockets code for instance) instead of in the PLC. Edited by paulengr

Share this post


Link to post
Share on other sites
thanks for all these informations, but I'm working at my thesis, and they asked me to test socket communication.... I know that it would be simpler using mail and custom web pages (I've buit some already). All I have is: LAN with -router -pc (with rslogix 5000) -compactLogix L43+EWEB I used java libraries for setting up a server waiting for socket connections on my pc, but I'm not able to write ladder logic to set up this connection.The only thing I can do is following the user guide, and this is what I've done so far: is it correct? I manually set "abilita_socket", and in this way those rungs are executed only once. I set all parameters like user guide says. The problem is that the ER tag of the 1st MSG instructionis is set, and it says "Connection Failure". What's the communication path that has to be set in the MSG configuration? is it correct?

Share this post


Link to post
Share on other sites
Only time for a quick look but your Eweb is not in your I/O configuration. Where is it at in your slots? I believe your path should be 1,1

Share this post


Link to post
Share on other sites
According to answer id 22562 on the knowledgebase http://www.rockwellautomation.com/knowledgebase/ the path should be the following: 1, 1, aaa.bbb.ccc.ddd where the aaa.bbb.ccc.ddd is the IP of your target PC.

Share this post


Link to post
Share on other sites
Bob I know the knowledge base has an example, tried to get it to work automatically but there is a hang up. It hangs up and does not complete the socket connection. This happens when I tried to connect, disconnect, and reconnect. Here is the file I modified have at it. Used the EWEB Visual basic app that they created to test the socket interface. Here it is too. my modified RSlogix application EWEB_SOCK_TCP_SERV_VER2_1V16.ACD see technote 32962 If you get it to work consistantly could you repost. I asked Rockwell about this and they never gave me an answer.

Share this post


Link to post
Share on other sites
Path 0,1 is incorrect, it will be 1,1 Bob: you don't add 2, <IP address> to the path as message sent to EWEB not to a remote device controlsdude: can you specify exact errors you are getting with server application and steps to duplicate them - I am not aware of any problems - all socket samples working just fine.

Share this post


Link to post
Share on other sites
Again I stand corrected by those wiser and more experienced.

Share this post


Link to post
Share on other sites
This "connection failure" message is the connection between the PLC and the EWEB module. It is a CIP connection that the error message is referring to. It is NOT an indication of a connection failure (as in a socket connection) between the EWEB and your PC. This is why I stressed the difference. Second, you are not checking for DN bits and daisy chaining the MSG blocks. It might work that way but I'd rather make sure that one MSG block fires before launching another one especially because you need them to arrive at the EWEB module in a specific sequence in this case. To do this, use the "DN" bit in the message control block of one MSG command as an input condition to the next one (XIC xxx.DN). I realize that you can probably queue up the MSG blocks and 99.9% of the time, nothing bad will happen. Don't know why but most plants where I work at always tend to end up with the 0.1% case. So I always program conservatively especially when it comes to communications. Edited by paulengr

Share this post


Link to post
Share on other sites
Contrologix Processor with the EWEB module = TCP Server Port 10002 Laptop using the EWEB Sockets Test Application = TCP Client using Port 10002 Modified the example program EWEB_SOCK_TCP_SERV_VER2_1.ACD to version 16 and changed the firmware of the EWEB module to 4.3 Also modified the program where the plc will automatically delete all sockets, create socket, and open connection, then I have to try to connect from the EWEB test app by pushing the "TCP Client" button. This follows the example as shown in "EWEB Sockets Test Programs.pdf". This part works the first time. Problem occurs when I try to disconnect and reconnect the TCP Client. Or go through the same above example, sometimes it works and other times it does not work. Question: Is there a timing diagram or some delays that need to happen between steps? Not sure how to make this bullet proof? Not sure what the Instance number actually means? Also, there is no documentation on what ports can be used and what ports can not be used? These are the questions I asked AB but no response. case number 6349364

Share this post


Link to post
Share on other sites
I deleted post I had earlier today as I misunderstood what sample you have. If you are looking for a TCP server sample then you should be using TN 33672 and test application assosiated with it TN 32962 is for demonstration purposes only, to show you instruction sequence and can't be used in real appllications as it does not have any error handling or out of sequence events. As paulengr said - it does not check MSG DN bits and any errors. What ports to use? have you try to google it? - it is up to you - these are Ethernet rules have nothing to do with EWEB. Page 143 of the user manual tells you what ports are in use by the EWEB - all other numbers are up to you. What is Instance Number? In general Instance is a key part of CIP specification and is a pointer to the memory location of the specific object. In case of sockets Instance refer to a "memory location" where socket was created. Again, this described in the user manual page 143. Edited by Contr_Conn

Share this post


Link to post
Share on other sites
Any port can theoretically be used. However, there are standards for port numbers. For instance, the default port for a web server is 80. http://www.networksorcery.com/enp/protocol/ip/ports00000.htm Generally ports 0-1023 are considered special. On some operating systems, only programs with system administrator privileges can listen on those ports. It prevents some malicious behavior. For instance, user-level programs could pretend to be E-mail servers, redirect remote logins to other places or steal passwords, or all kinds of other mischief. So except for "standard" server applications, user programs use port numbers 1024 and higher. For this reason, bear in mind your target audience if you ever publish your code to someone else. If you expect them to be running a server and have administrative privileges, then you'd normally want to pick a relatively unused port in the range of 0-1023. If the intended target is a user-level program, then something in the range of 1024-65535 should be used. As to timing, the timing is built into the MSG block configuration. You can monitor progress using the .EN, .DN, and .ER status bits of the MSG control data. If the MSG block fails, you'll get a .ER. If it succeeds, you'll get a .DN. While the MSG block is in progress (waiting to complete), .EN will be set. Once a MSG block fails, you usually need to clear the .ER bit before trying again. The TCP session is different. You have to monitor the status passed back by the EWEB module to determine whether an error occurred or not, because again you are working in the CIP world on the PLC side. You do not have direct program access to the TCP socket as a first-class object from the PLC side of things.

Share this post


Link to post
Share on other sites
I did monitor the dn, en and er bits in the message instructions to move on to the next procedure in opening and closing the socket. The problem is not in sending the data but in opening and closing the socket consistantly. But someone deleted the code i posted so you could not do an analyst since you seem more versed then I am on Msg instructions and socket functionality. Here is the code again. Your comment about not being able to monitor the status passed back is the problem with what I was trying to say. Maybe the status of the module is the problem when opening and closing the socket. But then you say you do not have direct program access, so I am confused about how you monitor the state of the module from a CIP standpoint of view? Could you explain a little more what that means? EWEB_SOCK_TCP_SERV_VER2_1V16.ACD

Share this post


Link to post
Share on other sites
I did not go through your program, but as I said before, you should be using TN 33672 that already has all proper timing, sequence and error handling you need FYI: unlatching DN and ER bits is ILLEGAL in controllogix and can cause unpredictable operations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0