5/31/2012 2:44 PM | |
Joined: 2/16/2011 Last visit: 1/13/2025 Posts: 229 Rating:
|
Hello, I Found a "guide about TCP/IP connections between PC’s and PLC’s" fromRasmus Frederiksen. In the guide he explain how to comunicate via tcp/ip direct with a pc with sample codes to VB.net. Regards
AttachmentThe guide about TCPIP connections between PCs and Siemens PLCs.pdf (6853 Downloads) |
Gabriel de Oliveira |
|
This contribution was helpful to
21 thankful Users |
6/17/2012 7:47 PM | |
Posts: 12 Rating:
|
Great information you've got. Thanks for posting it. I've been looking for something like these. |
This contribution was helpful to
1 thankful Users |
12/17/2012 12:00 AM | |
Joined: 11/14/2010 Last visit: 9/20/2022 Posts: 52 Rating:
|
thanks Gabriel :) |
Ahmed Elsayed |
|
This contribution was helpful to
1 thankful Users |
5/16/2016 11:38 AM | |
Posts: 6 Rating:
|
Hi all, I'm using TIA V13 and a Siemens S7-1200. I looked at that VB code in the attached PDF. I prefer to use C# so I tried to understand the code and translate it. I also used the MS link below for the code to try establish the connection: https://msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx I have a few questions regarding this. 1.) Just curious whether the PC side must be client-socket or server-socket mode? (refer to the link) I assumed async server-socket. 2.) In the PDF the author only logs the data from the PLC to a file. I wish to do that but also to send data to the PLC as well (i.e. to have the PLC begin instructions remotely). Any ideas? |
5/16/2016 12:59 PM | |
Joined: 4/28/2015 Last visit: 4/19/2025 Posts: 10858 Rating:
|
Hello, if PC will be act as Server or Client depends to you, simply client will ask server for data, so f.ex. if you want monitor PLC, it's signals, analog values, save data to SQL table from your PC application, probably PLC will act as Server and your application as Client. In this system is also important who will initiate connection, so Client always initiate connection, Server is pasive-accept connections and answers to Client's requests. In your application create Socket and connect to Server (PLC). On both side you'll prepare some frames as you wish for Exchange data. But that not means that you cant send data from PLC to PC application, all depends as you define your system of handshake. In your PC application you have some read/write instructions to do that like on PLC. Update: also this can be helpful: https://msdn.microsoft.com/en-us/library/5w7b7x5f(v=vs.110).aspx Update2: look pls for some basics for TCP/IP communications, socket library. If you'll find SELECT command due OS versions, probably you'll think more why systems can be different on PC and PLC sides applications |
Last edited by: Duris_I at: 5/16/2016 1:01:19 PMLast edited by: Duris_I at: 5/16/2016 1:02:09 PMLast edited by: Duris_I at: 5/16/2016 1:06:07 PMLast edited by: Duris_I at: 5/16/2016 1:20:07 PMLast edited by: Duris_I at: 5/16/2016 3:01:40 PMWith best regards... |
|
This contribution was helpful to
1 thankful Users |
5/26/2016 11:20 AM | |
Posts: 6 Rating:
|
Thanks for the link and the help. It really explained things in a better sense. So now I am slightly wiser regarding the TCP procedures. If anyone else is trying to make sense of the PDF at the start of this thread - The way that the connection is set up is that the PC acts as a server (listens for incoming connections) and the PLC acts as a client (establishes a connection to an open port on a given IP). So when using the MS link I attached - one must configure the PC to be a async server. I set up the PLC program as illustrated in the PDF, except I used a push button to trigger the sending of data. When I open the TCP port on the server side (PC) I manage to make a connection. The PLC TCP block gives the status 0x7004. If I don't open the port on the server side then I don't get that status (I get 0x7001). However, when I send data I get the "busy" flag and "complete" flag but nothing shows up on the receiver side. I've attached my C# file if anyone has time to take a look at it. (Just note - it's currently a .txt because Siemens don't allow .cs files to be uploaded) The C# file allows one to configure either a client or server. The file is still a bit buggy - it sometimes throws random errors but continues to execute. I will upload a better one as I remove bugs. This file works fine for PC-PC connections. I haven't tried through a router. It also works fine using the local host 127.0.0.1. AttachmentProgram.txt (1365 Downloads) |
5/27/2016 2:16 PM | |
Joined: 4/28/2015 Last visit: 4/19/2025 Posts: 10858 Rating:
|
Hello, fine for better understanding. I've looked to your code, working on C/C++ not C#, code looking to me ok sometimes feel maybe complicated but this doesn't matter now, simply I expect functionality wnem you've post PC-PC functionality on local host f.ex. On PLC look pls to TCON,TSEND,TRCV,TDISCON instructions and also library version depended to PLC firmware! If you have PLC firmw. 4 I recommend to you v4 of instructions, look at right side on instructions window. Can you confirm now used instructions version? I'll be prepare TCON with all statically defined IPs and ports on both sides as you probably defined, TCP protocol. On PC start Server and on PLC triger TCON for connection. After DONE you can triger SEND buffer from PLC, check also DONE for success send. Frame must be received to Server - PC and showed on screen as you have in application. You can then f.ex. reset that REQ on SEND and set EN_R to true on TRECV, wait for data from Server. On PC trigger send buffer and check on PLC NDR bit for ON - received data. Reset EN_R and so on again as you wish. This must work without problems. Give info... |
Last edited by: Duris_I at: 5/27/2016 2:26:47 PMWith best regards... |
|
5/30/2016 11:22 AM | |
Posts: 6 Rating:
|
Hi all, Using the MS link and PDF do work. I was just foolish. I put "<eof>" in my PLC code as the end-of-file delimiter and the C# code was expecting "<EOF>". I didn't accommodate for my silliness with String handling in C#. So as a result, the connection existed and the data was correctly sent. But, I never displayed it because my C# program never knew what it was looking for. I did set up my DB's differently to the PDF. I've attached a PDF with my own setup. Please comment if you have some useful info. AttachmentTCP connection with PLC and PC.pdf (2138 Downloads) |
This contribution was helpful to
1 thankful Users |
5/30/2016 11:33 AM | |
Joined: 4/28/2015 Last visit: 4/19/2025 Posts: 10858 Rating:
|
Hello, pls look, how can you implement some drive character in string as you did - '<EOF>' ? This is 5 Byte String, not 1 byte as you need. Also better will be post info what you expect with that EOF (end of file) character, is CR or LF char? Simply you must build your String with some Byte representation, consider Array of Bytes or Chars, this can be better solution. |
With best regards... |
|
2/22/2018 4:01 PM | |
Posts: 2 Rating:
|
Hi Gabriel, Have you used this guide? I am trying to use it to read a tag in VB so I can log data to the PC from the PLC. However, my command prompt just stays stuck at "Waiting for connection from PLC". I am not able to move beyond this step. The post number in the PLC and the PC are matching and set to 2000 and the IP address of the PC is in the VB.net program. I am not sure where I am going wrong, I am trying to use the exact same code in this guide. Not too familiar with vb.net. Any help or thoughts will be appreciated. Thanks! |
Follow us on