COM31. TCP/IP - TSEND TRCV TCP Communication via Siemens S7-1200 S7-1500 PLC and TIA Portal

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone I will use two videos to show how can we do the TCP IP communication by using CMS i7 1200 PLC or i7 1500 PLC when we are talking about TCP communication there will be a couple keywords or terminologies firstly open IE communication or you will see open user communication OUC or the TCP communication they are talking about the same thing that means how can we use Siemens PLC to do the tcpip protocol to do the communication and I will use two videos to show how can we do this because it can based on two typical example program the first example program that came from this ID number and I will use this example key send c or t receive C and another reason I like to show this case because in this example it based on the ISO on TCP communication this example is not using TCP communication you have to modify or config something in the connection DB data area you need to change some parameter second example I will use this example this is a very famous Library so the first one I'll come outcome is one keyword terminologies from Siemens especially if you are using TCP to do a very large amount of data communication this outcome library is highly recommended so I will use this outcome to show how can we do the gcp communication I will use two videos in this video I will use this one so basically if you are using Siemens CPU communicate to another Siemens CPU for example i7 300 CPU or i7 1500 PLC 1200 PLC the all Siemens PLC communication each other highly recommend you can use ISO on TCP a common way if one Siemens PLC CPU need to communicate with other devices for example sensors or cameras some cameras or some devices does not provide ethernet IP communication or perfectly communication so you have to use a common protocol for example TCP to communicate with them basically the device or camera will run as tcpip server and the PLC side will run as a client the active site PLC will run as an active site and the second common question while we are using TCP communication how large amount of data in one connection we can communicate so I highly recommend you can read this ID number and here there are three documents we can read typically we can download this menu and this menu for example if you are using CMS i7 1500 PLC for the TCP communication the data size could be 64k bytes wow it's very large and more importantly the connection numbers so we'll see typically above 64. that means one CPU by using their integrated perfect night Port this one CPU can set up 64 connections if you are communicating with one devices sending and receiving you want to do the same time that means you have to set up two connections to one device so basically at least this one CPU can communicate with 32 devices at the same time so if you are using the SM 1200 PLC or some old style i7 300 PLC you can download this menu and we can see so in the past a typical 300 PLC 315 it can communicate basically 1400 bytes and 1200 PLC it can communicate 8K bytes 8 000 bytes this tcpip protocol and this maximum numbers of connection this is the eight and the greasings of using Siemens TCP communication you do not need to set up any hardware connection any hardware configuration you just a program and the active that resources connection resources and here we go okay so this is the connection resources and the data lens very important let's use this example this ID number analyze download this example so this example is based on the ISO on TCP IP connection we have two changes a little bit but very minor change and this OUC means open user Communication open IE communication or are we called TCP communication and let's shift to the Ki photo software okay after we've downloaded this example project we can unzip and when we open this we'll see this example project it was using TI portal version 15 but don't worry so we can use the higher version TI portal directly open this for example in this case I will use Tia portal version 17. okay I will use K portal version 17 to open this project okay after open the ti portal we can use the project open and then click the browse and the let's browse this project so here it was using version 15 let's open this project directly okay currently I'm using version 17. okay let's click this upgrade upgrade version 15 to version 17. and from here we can see this example project it provides 1500 PLC and 1200 PLC so in this case I'm using 1200 PLC program are compatible with 1200 PLC and 1500 PLC so not quite matter which kind of controller you are using okay in this case I'm using 1200 I can open this device configuration okay let's firstly change the hardware configuration according to your real Hardware currently I'm using 12 14 AC DC relay so I can change the hardware and I can do the right click and click this change device one bg40 okay and I can pick this hardware version version 4.5 because my Hardware that version is worse than 4.5 okay and click ok change the hardware the same as the real Hardware as you are using and because I'm using version 17 so this care portal version 17 need this wizard to go through this confidential PLC setting so basically I will open up everything so do not protect this PLC and I will allow everything and I will do the full access Okay click OK finish and then double click this ethernet port so you can set the IP address for your PLC controller so in this case my PLC IP address is 1.174 okay this is my PLC IP address and my PC IP address is 1.253 and make sure they are at the same subnet mask okay so the plcip address is 1.174 to do the tcpip communication except this IP address we do not need to do any other CPU Hardware connection configuration that's why the TCP communication here we called open user or open IE communication we do not need to do any other Hardware connection configuration and we can go to them ob1 Main and let's look at this example project and when we open this we will see and the program still it is using fbd so this call which is fine but when we open this we'll see the inside of the IFC send and the FC receive this style is fbd if you are comfortable with lighter logic so we can close it and we can change to ladder logic so we can right click click the properties and we can switch to the lighter logic then the logic can automatically change to the lighter logic still okay and go to the FC send go to the properties and change to the lighter logic okay and double click the send okay initially it has is a red mark here so don't worry we can firstly compile this okay we did some changes on hardware and this logic still and let's see if the system can automatically correct this okay there will maybe have some inconsistent problem but after the compare the system can automatically correct that so luckily the system can correct that okay so good in this program the key function is this network tool for send it is using key send underscore C so this function block came from the instruction and if we go to the communication open user communication and we will see key send underscore C so this function block is used to set up and establish a connection also will send the data so set up the connection and the sending data this function blocks does this two tasks and the T receive underscore C this function block also does two tasks set up the connection and the receiving data okay so if we go to the receive we will see the key function block there's a t receive C so using Siemens PLC to do the TCP communication this is the very common way because it's very easy send and receive that's it so the connection are built in into this send and receive another way basically you need four steps you need to do the connection at the first and then you need to do the send or receive after you finish a job if you need to disconnect the connection you can do the T connection disconnect so you need a full function block here this is the typical two main ways to do the TCP communication then let's reveal this example project let's go to the send the send area we can see it has this slightly logic here so the detail explanation I highly recommend you better read through the menu so if we go to this menu don't forget this menu came from this ID number okay and we can reveal this menu it only has 15 pages highly recommend you read the detail so there are a couple of spots I highly recommend you need to read the details firstly by default this example project is based on the ISO on TCP so you need to take care you need to change the sale for example in here in this connect if we are using the ISO on TCP the connection parameter the state type it will use the t-com IP RFC so you will see the existing example project is using this date type however in this video I'm going to show the tcpip communication so we need to use this t-com ipv4 I will show how to change it okay and other than this we also need to reveal the configuration for example the lens system set is zero look at this if a set area was optimized assessed then this lens need to set a zero so what does the meaning of this optimized assess that means for this send area this send the data if we right click go to this sending area we'll see this DB it doesn't have the absolute address that's because this db3 here this is the one optimized DB if we go to the properties if we go to the attribute so this is the optimized DB it optimized the DB the data in the optimized DB it doesn't have the absolute address so all those things you have to use the name okay you have to use the name so now there is all the common PLC logic they are using the tag based logic so where to see the absolute address so this way is optimized so we need to reset the zero right here okay and then another parameter is very useful is this c-o-n-t this command is to control the connection zero is disconnect one is establish the connection when the PLC start up or to the circle power so the first things we need to turn on this connection and after this connection is established then we can enable the receive enable the receive is basically receiving the data but before we receive the data we need to make sure the connection has been set up okay so we can use the status feedback to check the connection status okay and other than this en and the con T there's one another thing I like to discuss a little bit in this menu it doesn't explain but if you click the F1 help you will see this explanation ad hoc let's click the function F1 okay when you reveal the help from the ti portal you'll see for the T receive or key send it has two section for this help so basically we will select the second one because currently the CPU what I'm using that firmware is higher than 4.0 right so for this selection the first one that firmware is lower than 4.0 if you scroll down so for the tcpip the ad hoc mode so it's only available for the TCP protocol firstly and it is specially used for if the receiving area is dynamic for example in this case I'm going to use a software when software socket tool to run as TCP server every time when I send the data to the PLC PLC will receive the data I will send a different lens so in this case I need to turn on the ad hoc so this is the case every time the PLC need to receive the data dynamically the lens is dynamic but if your PLC is communicating with another controller and the both side Define the lens is a solid is fixed then you do not need to turn on this but that moment you need to change this lens for example if both sides Define we need to send 100 bytes so you can set 100 right here but if you are going to communicate with one PC 90 the lens is a dynamic so you need to turn on this so in this case I'm going to add one mode control for this ad hoc also so I'm going to open this generic data and also create one tag here floated and I will call that receive 80 Hawk okay this is the pool command let's connect to here okay this is the ad hoc so again you better reveal the detailed explanation from this menu also anytime you have Arrow from this test you better check the ti photo help click the F1 then you can find this help so and especially if you scroll down you will see those code so those code is easy for us to troubleshoot and find out the problem for this selection here the key com IP is used for ISO on TCP for the TCP communication we need to change to this t-com IP V4 enter okay this IP t-con waveform enter very carefully about this and also if we spend here there are a lot of parameter out here this is used for set up the connection for the send and the receive so this too is very important because those are the parameters so we better retain this parameter for example if we set up the IP address this target IP address and the port number so we better retain the parameter so and also for this connect we turn on the retain okay all right now let's drag this parameter to a watch list so it's easy for us to do the online commissioning okay so we can rename this watch list to TCP okay and then I can drag all those things connect send those parameter okay to here and uh remote IP address so let's drag this IP address to here and the port is very important okay drag this connect receive okay connect receive let's drag this create a new line here that's called This is the receive interface drag to here and remote address drag to here okay and a remote port okay especially this port I will explain this after okay this is actually very important most of cases if the new learner try to set up TCP connection wasn't successfully 90 caused by this okay all right we prepare this and also we'll see in the ob100 obl 100 is a startup the moment when the controller just boot up so the first run it will run the ob100 program it only run one time so usually we use for the initial parameters okay as we can see when the system poured up it will try to turn on the connection for the receive turned on and send the connection turn on and also it will turn on this enable if we go to the FC set okay this enable will control this that means by default The Descent will now be triggered but when the system when the controller boot up this connection sent it will turn on so the system will try to set up the t-cent connection okay and for the T receive we will also see here he received com receive when the system just boot up so disconnect this command will turn on the system will try to set up the connection where this receive Channel okay let's send and receive this is the individual two channels using this way the send and receive two channels will set up the connection respectively okay then let's go to this watch list so we definitely need to set up the parameter for this controller okay so now let me firstly download this controller okay let's download this controller after the download where you can start off the controller and go online and let's set up those parameters and here and this is a very important my PLC IP address is a 1.174 okay so let's load the program Okay click this consider as trusted controller okay because we are using the version 17 the version 17 need this security setting connect or receive they will turn on because this ob100 however currently all those parameters still zero so the connection is wrong so we can temporarily ignore that so let me click this go online so importantly we need to set up the connection parameter so for this T sent let's focus on the key send so firstly this interface ID the interface ID that means which Hardware Port we need to use for the connection so we need to go to the hardware and we click this port we will see this system constants and this port number this port is this rg45 port and this Hardware number is a 64. so when you do set 64. for that Port Okay so we can close it go back to the program and for this interface we'll set 64. meantime for the receiver we'll use the same port so we'll set 64 also okay transform and for the ID for the send we will use the ID number one and for the receive we will use another ID basically they are working immediately so for the receive we will use id2 okay and the connection type so the hex that's the B and if we switch to the dec 11 11 means TCP okay if we reveal the manual if we reveal this manual 2.6 for the t-com ipv4 this connection so what we'll see here the connection type 11 means TCP if for the UDP connection it will select the 19th this is the the decimal so here we need to select the 11 okay and then for the next active establish so we will select the true because currently for this mode I will use the PLC running as tcpip client to actively set up the connection with tcpip server so I will use one socket tool tcpip software running as server so in this case I was set this active established to true to actively set up the TCP connection for send and receive both ways we need to do this active this connection for the receive connection by default this is 11 no problem and for this active established we will select the true okay so both sides we need to say RTV established okay that means the PLC will run it as TCP client then the IP address in this case my target the tcip server is my computer so we will select the two decimal I can set here okay my computer IP address 192. 168. 168.1 Dot 253 okay and for the receive the same thing so where was the one dot two five three okay same IP address okay let's transfer okay we transfer those parameter and finally the important parameter is this port okay so in this case again send at the receive they are working respectively so for example for the remote this this PLC Target remote in this case this remote Port is my PC my socket tool TCP server Port so I can set for example 2000 under my local Port this is my plc okay for send I will set three thousand okay and then for the receive we will use another different port this you need to be very carefully most of cases if people doing this test if you decide this remote port for sender receive as the same port then when send and receive they set up the connection they will fight each other okay this is very important so we need to set a different port for example 2001 I will set for this receive area and the local port for this receive will aside a different parameter so 3001. okay so this local Port local Port is for PLC itself and this is remote Port remote Port is for the Target but for certain that they receive they are using the different port number okay otherwise they will fight each other okay so let's transfer all right we prepare those parameter and this is sent and receive so we can see this side and if we go to the T receive okay for the T receive there's one another parameter t hot so this 80 hard I need to set it to one so I can drag here okay and I can set this to one okay I can turn down to two okay after I prepare all those connection parameter then we can toggle this connection and then let's go back to the FC send again okay send the request he send the request but t-san request is waiting for this area so we can see the T sent the request is controlled by this connect firstly and that is using this 0.5 Hertz every two seconds it will turn on one time it will trigger this request okay now we prepared all those parameter and before that and the last firstly turn this off okay turn this off currently I haven't set up the TCP IPA server side yet okay the server side I will use one socket tool I will prepare this tool under this video and you can download this tool this tool name the sockey tool is very convenient okay okay this is this tcpip socket tool actually this software can run as TCP client or server or use the UDP communication but in this case we will test the TCP server this mode basically this is a typical mode when a PLC need to communicate with the PC or SQL or any other devices so basically the device inside will run as tcpip server side and in this case again so from this setting my PC my computer is running as TCP server and the IP address is 192.168.1 1.253 okay and the port so let's firstly test to the send this connection so while we are testing the send the remote Port that's the 2000 this remote means this PC okay so I will set 2000 here okay and before we turn on this listening so we need to temporally turn off the firewall okay let's go to the firewall and then go to this turn Windows Defender turn off your firewall okay don't forget this Okay click ok now we can test the send at first so now for this Ascent I can also turn on this monitor and firstly I can turn on this connection so let's start this listening and now it's waiting for the connection so from PLC side let's turn on this connect send around this connection let's turn on okay turn it up and then once we turn it on because there has a logic here now is triggering this T sent and we can see So currently the receive we turn it off but he sent set up this connection it saw this client 1.174 this is my PLC and now it's receiving nothing because our sending area now is zero so let's go to this connect set is this send the data send the data here so let me go to the send data okay and we can drag here we can drag carbon data so let's okay let's write here this is the set okay and here when we send the data to a PC this software is receiving the data as a string so the latter base so we will send a Char so let's switch to chart we select this chart okay and then here if we send a b c d okay and now let's transfer this okay this connection we turn it off because we have this setting here no worries so let's turn it on again here we set out the connection again and let's wait for a short moment okay we can see so it set up this connection immediately and then will trigger in the ascent so every time it triggers send we will see is keeping receiving this ABCD if now I sent one two three four okay set okay we disconnect sorry for this so let's connect again connect okay I'm gonna turn I'm gonna delete this area so they will not send any command every time we transfer the data here okay one two three four right so again if I send this time x y z o w okay and transfer so we'll see x y z is keeping sending this value okay this is set okay we tested successfully now let's turn it off turn it off we disconnect so once we disconnect we'll see it will show server closed and now we will test the receive so I will close this software and reopen this software okay select the server and the same IP address from this receive this second this remote IP address okay 192. 168.1.253 okay and this time the port we will see for the receive the remote Port will be 2000 watt instead of using 2000 2000 this remote Port belongs to the send test but now for the receive we will set this TCP server side to 2001. okay let's click enter start listening okay let's open the FC receive and let's monitor it okay I turn on this ad hoc and this lens is zero as required okay and now I will first click turn on this connect turn on disconnect and let's watch this Behavior this response okay we will see after two seconds so it shows it got this new client 1.174 from the plc okay and after it set up the connection we'll see this status shows 7004 okay and the 7004 if we go to the help if we go to this T receive health we can check the 7004 yes communication connection has been established okay so in the real case once you receive 7004 you can turn on this enable that means we enable the data transfer before we enable that now if I send everything for example XYZ if I send XYZ okay the receipt buffer will receive nothing okay let's prepare this receipt buffer okay receive buffer I will we will see this receipt buffers here we can right click go to definition or let's directly open this receive data this is receive data here this DB okay let's drag a couple data here okay receive data again I will transfer this to char and let's drag it to turn okay so now let me turn on this listening okay start listening and now with this parameter set up so let's turn on this connection first turn on this connection okay we got this 7004 again so it set up this connection and before we enable this receive let me send something so we'll see so let's check if this receipt buffer can receive something okay x y z for example send or a B said okay it cannot receive anything because we haven't enabled that yet but here if I enable the moment where I enable we will see XYZ and then a b let's receive buffer will show all the data we sent before that's because the TCP the socket it can buffer the data when it wasn't be enabled but when we set up the connection actually the hardware socket area has been working so when we send something even the logic side we haven't received the data to this buffer yet but Hardware buffer is working that's why once we turn it on all those data can show up but it will cause the problem that all the data will line up So eventually your data will show very Mass so this you need to be very carefully at the moment when you ready to enable you better reconnect because when we disconnect and reconnect that moment all the buffer will be removed will be clean so let me try this time so let's turn it off first turn off the enable and the last turn it off disconnect okay and now we can wipe out all those buffers okay I can call me Paris why pop all those buffer okay now I turn this buffer to zero now let's connect seven zero zero four so let's watch here okay it got a reconnect we can send something X Y Z again send we haven't enabled yet but this time I will now turn on my enable so I will firstly turn this off disconnect clean the buffer and then if I turn it on to reconnect again 7004 let's watch this new client show up okay now if I turn on this we haven't seen anything yet when the moment I turn it on we will see the buffer is still zero now it's actually waiting for the new command so this time if I send X Y Z first send okay we'll see XYZ okay this is I accidentally messed up here no worries I can delete this line zero one two three so X by Z Okay then if I send one two three four so let's see if one two three four will be shown here or over right here so if I send we'll see okay this time correctly always starting from zero one two three four okay again if I send say w y z send wyz will all write starting from zero all data will be all right this is something we need otherwise all the data every time I just connect with the previous data it will Super mess okay also need to be very carefully while uh communicating with this software because the lens is unpredictable it's Dynamic that's why this 80 hard we need to turn it on and turn on the connection okay so this is the very typical receive all right we just attached the send and the receive respectively but in the real case we need to send the receipt at the same time so how can we do that right so this will be two cases while cases if your device send that the receive has a different port like this case for the remote port for sending the receive typically the device will prepare two ports one percent once will receive like this case we can do this test another case if the device only provide one port but you still need to do the sender the receiver at the same moment how can we do that the basic idea is for sending the receive we can now turn on enable the connection for the sender received at the same moment basic idea is we turn on the connect for send at first and complete then we disconnect the send and then turn on the receive this going back and forth we need to do this send and the receive alternatively the key idea is the send and the receive cannot be on at the same moment otherwise they will fight in this remote Port because at this moment you'll remove poor only has one only has one number one port this is the tour scenarios okay here let me show the first scenario we have the different port respectively so while we're using this software how can we do that very easy we just turn on two times the software okay let me close this software let me reopen this software okay I can open this software two times all right here so one for the 2000 okay 192.168.1.253 okay and the port I can prepare this port for the send this channel just two thousand okay for This Server okay for the second for testing this receive I can send IP address 192.168.1.453 and this port I need to set this remote port 2001. okay 2001. okay we start listening and now we can turn on this receive first okay we turn on already we enable this receive connection that's why we can see for this 2001 this receive this connection they got connected let's clean out something after all we reboot this software so let me disconnect disconnect we'll see it's reacting that means actually it's fine this client this side this connection so let me reconnect again reconnect okay let's wait for this response okay now 7004 and the software also find this this channel connection okay now let me enable the receive and now let me send the new data let's say one a b c d send okay and let me scroll down and receive we'll see ABCD and the less than the one two three four seven one two three four okay also we'll see again this is the chart actually the data behind if we switch to the hacks is showing 31 if you search the Asic table we will see 31 hacks that means this chart number one okay and a b c d a b c d this a for the word for the hacks that means 41. okay if you find the Asic table you will find a that means this hacks 41. okay the receive is working now if we go back to the send and the last watch here So currently the send we haven't enabled that yet okay disconnect so if we turn on this connect return on this connect and let's watch here okay we will see it connected and this send the buffer XYZ W let's keep sending okay it keeps sending in the meantime for this received Channel we can send the same thing let's see if they are working at the same time so for the sending it keeps sending from the PLC to this TCP server okay let's leave it there and keep sending but for this receive area so we'll send the data from this this software to the PLC so we can send again so rst let's try send so we'll see rst okay very quick and uh six seven eight send six seven eight okay it can receive okay if we go back to the receive we'll see the receive it always busy because we keep enable that okay that's why it can receive anything when we send to this PLC okay okay you can receive now no problem all right this is the key idea when we're doing the standard receive at the same moment again the port they must be different otherwise the send and receive will fight each other for the support basically who will turn on the enable at first who will occupy the channel the port then you will find some cases maybe send this successfully but you cannot receive or some cases you can receive successfully but you cannot send that's the key reason you are using the same port and for the PLC is the same thing so for the sender receive we need to use the different port okay different port for the local Port three thousand for the Cent 3001 for the receive okay and again so like I showed I can disconnect this command the c1t to disconnect release the resource and release the buffer for the receive or for the tsen so if in case you are Target for sending receive they are using the same port for send and then receive you can now turn on this tc1t for the sender receive at the same time you better do a sequence logic send and once you send the complete then disconnect and then do the receive receive complete then go back to the send again doing this sequence all right this is the key cpip test for this T sent the T receive and this is a very important idea for the port and this connection parameter also for the receive if you are communicating with one PC this ad hoc is very important you need to turn it on before you turn on the cot set up the connection all right that's for today thank you for watching thank you for watching if you like this video please give me a sum up if you like to watch more videos in my Channel Please Subscribe and hit the Bell thank you for watching
Info
Channel: Electrical Automation Hands-On
Views: 7,264
Rating: undefined out of 5
Keywords: TCP, OpenIE, OpenUserCommunication, Siemens, PLC
Id: akoVQu1LzuY
Channel Id: undefined
Length: 48min 55sec (2935 seconds)
Published: Mon May 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.