WinCC OPC question

uptown47

Lifetime Supporting Member
Join Date
Feb 2008
Location
Over there, next to those boxes
Posts
1,146
Hi all,

There's a strange hybrid system at work that involves several PLCs talking to a PC running WinCC SCADA.

This PC, in turn, talks to another PC also running WinCC SCADA which, in turn, talks to another PLC.

The reason for this was that the original PC couldn't only talk to 5 PLCs at one time so another PC was installed to talk to the remaining PLCs on the system.

Anyhoo... I'm trying to get a tag from one PLC back to another PLC via the two PCs. (see diag below...)

attachment.php



In the second PC I have set up an OPC tag called "myTag" that has, as it's parameter, the name of the tag that I need to address from the first PC (i.e. a parameter of "firstPLC.thisTag" which - in the first PC - equates to DB100.DW0).

When I view the tag on the screen of the 2nd PC all is well. I change the value in the PLC and the value on the 2nd PC changes.

Now... my question is... how do I then 'send' that tag to my final PLC.

In other words, how do I push that 'tag' from the 2nd PC on to an address in the last PLC ?

I really hope that makes sense?

I'm sure I'm missing something simple but I'm struggling with this.

Many thanks for any help you can give me.

;-)

SCADA.jpg
 
No possibility to use the network to communicate directly between the PLC's?

If not, then you could always create a global script running on a set interval to write the value to the tag.
Get value from other WinCC, write to tag, write tag.

We've been doing this to get data from a 3rd party OPC to our S7 PLC's.
Just remember to write a decent script. If not done properly, you'll be eating up memory and it'll crash the PC in a matter of weeks.
 
Hi Jeebs,

Thanks for your reply. I would rather avoid going down the 'script' route if possible. It seems a bit over-complex for what I need (and I'm unfamiliar with scripting in WinCC).

I would have thought it should be easy enough to copy the value to a tag on the 2nd PC?

Is this not possible?

Thanks again for all your help.

** EDIT **

Also.. I don't suppose you would have a bit more detail on how I would write the script and how I would 'trigger' it.

I imagine that to keep the overhead down I would want a script that says...
If this tag has changed then write the tag to the PLC...

I know that in Citect you can set up the script to run every x seconds through a global menu. How is it done in WinCC ?

Many thanks
 
Last edited:
After some internet research I've set up a C script under the Action folder but it's not working, anyone any idea as to why not...:

Code:
#include "apdefap.h"
 
int gscAction(void)
{
#define TAG_0 "myOPCTag"
#define TAG_1 "myPLCTag"
 
WORD Temp1;
Temp1 = GetTagWord(TAG_0);
SetTagWord(TAG_1, Temp1);
 
return 0;
}

I've set it up (I think) to cycle every 10 seconds but it doesn't seem to be working?

I just copied the C code from another action script I found and changed the tags?

Does it need a different function name (i.e. NOT gscAction?). Or does it need to be 'called' from somewhere as well as setting up the Cyclic timer bit to 10seconds??

I've tried recompiling etc and rebooting the PC but still no joy....

Many thanks ;-)
 
WinCC Explorer > Global script > Right click on it and open c-editor or vbs-editor.
Create new action.
Write script.

To set the trigger, there's an icon of an old alarm clock or press CTRL+T.
You can select either a tag or a timer/interval.

As for the script:

SET variable_to_read = HMIruntime.tags("tagname1")
SET variable_to_write = HMIruntime.tags("tagname2")

variable_to_read.read //reads the value
variable_to_write.value = variable_to_read.value
variable_to_write.write //writes the value



Or you could just forget about the variables and use HMIRuntime.Tags("tagname").


What you want to do is so simple in WinCCFlex, I still find it odd that it's not directly possible in WinCC.


EDIT: Computer(in WinCC explorer) > Properties(double click on the server) > Start-up tab > Enable Global Script Runtime
 
Last edited:
Hello Up North,

Jeebs touched on this and I'm not certain whether it's absolutely necsessary or not but I've always thought that it is good form to set objects to "Nothing" once youve finished with them to ensure that they don't eat memory. Below is a VBS sub routine that declares some objects,uses them and then sets them to Nothing.

Nick

Code:
'***********************************************************
Sub CheckEdit_Part(Byval Item)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'\Check if the Displayed part has been edited \
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim vValue, TagName
Dim i, LineText, strDebug, bEdited
Dim objScreen
Dim objListBox 'As hmilistbox
Dim objCombo 'As hmicombobox
Dim objTag ,strTag, objTag2
 bEdited = False
 Tagname = "iFormula_Component_Number"
 Set objTag = HMIRuntime.Tags(TagName)
 objTag.Read
 Tagname = "Formula.Component" & CStr(item-1)
 Set objTag2 = HMIRuntime.Tags(TagName)
 objTag2.Read
 If objtag.Value = objtag2.value Then
  bEdited = bEdited
 Else
  bedited = True
 End If
 
 Tagname = "rFormula_Component_Share"
 Set objTag = HMIRuntime.Tags(TagName)
 objTag.Read
 Tagname = "Formula.Share" & CStr(item-1)
 Set objTag2 = HMIRuntime.Tags(TagName)
 objTag2.Read
 If objtag.Value = objtag2.value Then
  bEdited = bEdited
 Else
  bedited = True
 End If
 
 
 HMIRuntime.Tags("bPartNeedsSaving").write bEdited
Set objtag = Nothing
Set objtag2 = Nothing
Set objcombo = Nothing
Set objscreen = Nothing
End Sub
 
Hmmm, forgot about adding that.
But yes, that was what I was hinting at.
If you don't use it, depending on the amount of tags used, gscrt.exe can use up all (and I really mean all) of your memory.
 
Thanks for the info Nick. I did set my vars to "Nothing" after reading that in another post you helped me on (doing a similar thing) a few moons ago.

My code still isn't working and I'm wondering if I have to do something else to 'call' it. Here's my code so far:

Code:
Option Explicit
Function action
 
Dim variable_to_write
Set variable_to_write = HMIRuntime.Tags("myPLCTag")
 
Dim variable_to_read
Set variable_to_read = HMIRuntime.Tags("myOPCTag")
 
variable_to_read.Read
variable_to_write.Value = variable_to_read.Value
variable_to_write.Write
 
Set variable_to_write = Nothing
Set variable_to_read = Nothing
 
End Function

I have created a timer under Cyclic that is set to 10s.

I've written the OPC tag and PLC tag to the screen so I can see them change. The OPC tag changes fine but the PLC tag doesn't get written to?

Do I need to 'call' the 'action' Function like you would do in other scripting language i.e. action() ??

Or something like??

Many thanks

John ;-)
 
Last edited:
If that's a copy paste of the actual script, you might want to exchange variable.to.read.Value for variable_to_read.Value

If that's not it, you can check if gscrt.exe is running or not.
 
Jeebs, you're a genius. gscrt.exe wasn't running so I started it up in Task Manager and we're in business!!

So... next question is, how do I ensure that gscrt.exe starts up whenever the PC starts??

Thanks once again for your help. I would never have caught that gscrt wasn't running without it.

Cheers ;-)
 
It should start with the project.
Have you enabled Global script Runtime in the Computer properties?
It's in the Startup tab.

ProjectTree > Computer > Right frame, double click on computer listed as server > Startup (click yes if it asks) > Enable Global script Runtime > Reboot.
 

Similar Topics

Hello Guys, I am trying to test HMI in TIA Wincc Professional V13 with my virtual machine with Rslogix emulator. Wincc is using OPC to...
Replies
0
Views
1,384
Hi all! First of all, this is an amazing forum. I hope I can help someone someday. But now, I need help to set up an OPC server in order to...
Replies
1
Views
2,122
Have anyone tried to use the ChangeConnection system function with an OPC connection ? According to the help text, it appears the ChangeConnection...
Replies
1
Views
1,857
Anybody know how to setup WinCC 6.2 OPC to read data from AB Logix5000 controller? I'm aware there is a way to do this using rslinx as an opc...
Replies
2
Views
2,014
i have on the field ML1200 connected thorough serial port to audiotel mc39i gprs modem. i would like to transfer existing connection which goes...
Replies
2
Views
2,000
Back
Top Bottom