Creating S7Plus Connection from code

Find and share HowTos to various installations / configurations!
5 posts • Page 1 of 1
Romero
Posts:27
Joined: Wed Jul 19, 2017 9:24 am

Creating S7Plus Connection from code

Post by Romero »

I'm on a project with a lot of differents PLC's and since WinCC OA can do it, i want to do the connection by code as well as the _address power config.

I´ve been trying for while creating a new S7Plus connection DP and then setting each DPE from i have seen on the online help and the PARA, copying the values to set from an already working connection.
Here is and example of the code i have been using on a click event in a button
[spoiler]

Code: Select all

main(mapping event)
{
  string conn_name = "TEST_CONN";
  
  dpCreate(conn_name, "_S7PlusConnection",1);
  
  dpSet("System1:"+conn_name+".Config.Address","192.168.104.95"); //IP Address Plc
  dpSet("System1:"+conn_name+".Config.AccessPoint","S7ONLINE");
  dpSet("System1:"+conn_name+".Config.PLCType",1);
  //dpSet("System1:"+conn_name+".Config.Password",);
  dpSet("System1:"+conn_name+".Config.LegitimationLevel",-1);
  dpSet("System1:"+conn_name+".Config.ConnType",0);
  dpSet("System1:"+conn_name+".Config.KeepAliveTimeout",20);
  dpSet("System1:"+conn_name+".Config.ReconnectTimeout",20);
  dpSet("System1:"+conn_name+".Config.EstablishmentMode",0);
  dpSet("System1:"+conn_name+".Config.SetInvalidBit",0);
  dpSet("System1:"+conn_name+".Config.TimeSyncMode",0);
  dpSet("System1:"+conn_name+".Config.Timezone",0);
  dpSet("System1:"+conn_name+".Config.TimeSyncInterval",86400);
  dpSet("System1:"+conn_name+".Config.UseUTC",1);
  dpSet("System1:"+conn_name+".Config.AcquireValuesOnConnect",1);
  dpSet("System1:"+conn_name+".Config.EnableStatistics",1);
  dpSet("System1:"+conn_name+".Config.ReadOpState",1);
  dpSet("System1:"+conn_name+".Config.StationName","TIA_Project|My_Station_Name");
  dpSet("System1:"+conn_name+".Config.DrvNumber",2);
  dpSet("System1:"+conn_name+".Config.CheckConn",0);
  
  //dpSet("System1:"+conn_name+".Config.ReduConnection.Address",);
  dpSet("System1:"+conn_name+".Config.ReduConnection.AccessPoint","S7ONLINE");
  dpSet("System1:"+conn_name+".Config.ReduConnection.SwitchCondition",3);
  //dpSet("System1:"+conn_name+".Config.ReduConnection.SwitchTaG",);
  
  dpSet("System1:"+conn_name+".Command.Enable",0);
  dpSet("System1:"+conn_name+".Command.GQ",0);
  dpSet("System1:"+conn_name+".Command.IGQ",0);
  dpSet("System1:"+conn_name+".Command.DoSwitchover",0);
  
  dpSet("System1:"+conn_name+".Browse.GetBranch","RequestPlcType", "TIA_Project", "1");
  dpSet("System1:"+conn_name+".Browse.NodePaths","My_Station_Name|272|192.168.104.95");
  //dpSet("System1:"+conn_name+".Browse.NodeComments",);
  dpSet("System1:"+conn_name+".Browse.SystemTypes","Station");
  //dpSet("System1:"+conn_name+".Browse.ValueTypes",);
  dpSet("System1:"+conn_name+".Browse.ItemLengths",-1);
  dpSet("System1:"+conn_name+".Browse.RequestId","RequestPlcType");
  
  
}
[/spoiler]

I did the dpset() sepparately just to test. The commented ones are empty DPE's so im not sure if i need to set those.

The result is that the connection is created however it cant detect the PLC type. The log viewer returns:

WCCOAui (1), 2017.08.09 09:22:53.868, CTRL, INFO, 0, , Detecting PLC type...
WCCOAui (1), 2017.08.09 09:23:03.743, CTRL, WARNING, 0, , Unable to autmatically detect PLC type
WCCOAui (1), 2017.08.09 09:23:05.868, CTRL, INFO, 0, , Reading S7DOS access points...
WCCOAui (1), 2017.08.09 09:23:26.272, CTRL, WARNING, 0, , Unable to read S7DOS access points

It does 9 attemps for each, auto and Access points. I saw that the value of System1:TEST_CONN.State.DrvType is SIM:1 instead of S7Plus:2 which is the value in working connection made from panels.

My first question is, can i actually do something like creating a connection like im trying to.
If the answer is yes, where is my mistake (or at least the more important one :blush: ).

Just ask me for the information i could miss.
Thank you so much for your time.

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: Creating S7Plus Connection from code

Post by fmulder »

Yes, it is possible to create your S7 device and/or any addresses from scripting. I couldn't tell you what your mistake is. I can only tell you how I would do it. There are 2 ways.

1) You can reverse engineer the script code in existing WinCC OA panels and scripts. Example: open the script library para.ctl and scan for the word 's7plus'
2) Let the Gedi show you how to do it

The second option would probably help you the best:

1) Create a new project
2) start the gedi and open the 'System Management'
3) Now go to the console and activate debug flag '-snd 2' on the Gedi (or also activate '-rcv 2')
4) Now do your configurations
5) Close the GEDI (otherwise you'r logviewer will fill up)
6) You can now look in the LogViewer and see exactly what dpSet()'s had done. You can see the sequence, the values and the order in which the standard panels do it.

You could now build your own script to mimic these dpSet()'s. Don't forget
7) Look in the help file. Referencde tables\\Datapoint configs\\_address. Here you can find the right datatype for each element. Make sure that you dpSet() with the right type of variable

Hope this helps

Share the fun
Frenk Mulder

Romero
Posts:27
Joined: Wed Jul 19, 2017 9:24 am

Re: Creating S7Plus Connection from code

Post by Romero »

First of all thank you Frenk for your very fast reply. I've never use the log this way and it has already help me in some other parts of the program.

It is more complicated than i thought. I'm new to WinCC OA and how it work. I'll use this method to mimic the process and solve the problem (even thought it's going to be a hard way :pinch: ).

Meanwhile i would like to know if someone has another approach to create massive amounts of connections for the S7plus driver.

Thank you in advance!

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: Creating S7Plus Connection from code

Post by Gertjan van Schijndel »

You do not need to set the 'Browse' (and 'Command') elements.

Perhaps the driver type is wrong because you set the driver number too late.

Another approach would be to export a connection and replace the values which differ with place holder. With scripting make a copy and replace the place holders with the new values and import it.

Romero
Posts:27
Joined: Wed Jul 19, 2017 9:24 am

Re: Creating S7Plus Connection from code

Post by Romero »

I tried setting only the 'Config' elements and the driver number at the beggining and it's working fine.

However i don't know how to export the connection so i couldn't try it.

Really thank you a lot Gertjan for the accuarate answer!
Best regards

5 posts • Page 1 of 1