Developing An ActiveX for WinCC Flexible

. Tuesday, August 4, 2009

Several months ago, a customer requested a product tracing system which should work with SIEMENS PLC.


They already had a WinCC flexible licence and requested the project in WinCC.


First of all, I could not find a way to use RS232 comm ports with WinCC, so I decided to use SAX Comm library for RS232 communication.


It was not possible because I could never be able to compile the software even without any script code in it. Just adding SAX Comm object was enough to crash WinCC development environment. WinCC was raising the following error:


“Fatal ERROR: screen item Screen_1 in screen Screen_1 contains inconsistent data and should be deleted.”



Then I tried to code my own ActiveX, embedded SAX Comm object and mapped some properties and events, however result did not changed, WinCC was still crashing.


I decided to walk step by step, I realised that WinCC had a really pain about ActiveX, so I have started with a totally empty ActiveX and successfully compiled the WinCC project.


Then I started to add properties one by one, and with the first property of ActiveX caused a crash again.


In WinCC programming manual, it says that it is possible to read and write a property of an ActiveX within a script, but it was not true.


Reading or writing a property inside a script directly causes a crash.


I have found that the only way to use properties of An ActiveX is using ‘Internal Tags’ of WinCC. If you want to send data inside of an ActiveX, you create an internal tag and assign it to the one of the properties of ActiveX.


With Internal tags, I was successful to get data from PLC to my ActiveX, however I realised the major problem when I finished developing my ActiveX, and it was not possible to send data from ActiveX to WinCC (so PLC)


It was not possible to send by properties, because assigning ActiveX property to an internal tag was working one way only. There was not any ‘direction’ option.


Then I tried to send data by triggering ActiveX events, it was possible to trigger events of ActiveX but it was not possible to send some data by parameters of event.


So I decided to use ActiveX events as digital outputs, I have used them without sending any parameters.


For Boolean data, triggering was not a problem; I have created 2 events for each Boolean output and altered a Boolean internal tag on those events.


My final challenge was sending an integer code to a test device. Boolean outputs were easy but of course it is not convenient to create 255 events for a byte value.


So I created following events for sending byte information to WinCC:

ResetByte()
SetBit_0()
SetBit_1()
SetBit_2()
SetBit_3()
SetBit_4()
SetBit_5()
SetBit_6()
SetBit_7()
ByteReady()

Created a dummy internal tag and wrote single line scripts for each event:


Sub ResetDummy
tgDummy = 0
End Sub


Sub SetDummy_0
tgDummy = tgDummy + 1
End Sub

Sub SetDummy_1
tgDummy = tgDummy + 2
End Sub

Sub SetDummy_2
tgDummy = tgDummy + 4
End Sub

Sub SetDummy_3
tgDummy = tgDummy + 8
End Sub

Sub SetDummy_4
tgDummy = tgDummy + 16
End Sub

Sub SetDummy_5
tgDummy = tgDummy + 32
End Sub

Sub SetDummy_6
tgDummy = tgDummy + 64
End Sub

Sub SetDummy_7
tgDummy = tgDummy + 128
End Sub
And finally, for ByteReady() event I have write the following code for sending output to PLC:


Sub SetByteOutput()
tgByteOutput = tgDummy
End Sub


As an example, if I want to send code 120 to the test device, I convert its value to binary:

120 decimal = 0111 1000 Binary.

And triggered following events consequently:

ResetByte()
SetBit_3()
SetBit_4()
SetBit_5()
SetBit_6()
ByteReady()


Conclusions: In my opinion, WinCC Flexible is giant software, occupies gigabytes of space in hard disk but does not worth its price. Its tools are a little bit limited and it is difficult to do following tasks:

- Query some value from database and make decisions according to records from database.
- Serial or Ethernet communications with any devices other than SIEMENS.
- Third party ActiveX, WinCC does not have any guarantee for third party ActiveX.


And WinCC Flexible is only convenient if you:

- Don’t have experience on programming
- Use WinCC as only HMI
- Don’t need complex operations controlled by PC
- Have patience and high budget at the same time.

2 comments:

Anonymous said...

Hi, Moosty! Thank you for this article. It was very usefull for us, but we do not have that programming manual, about whith you said. Can you give us a link? Thanks in advance.

jaydeeppanchal said...

can you describe how i canivx t use MSCOMM32.OCX acto send datas on serial port???

Post a Comment

Followers

Search This Blog

Comments

About Me

My photo
Automation engineer especially working on PC software development. Formerly I was coding on PLC, but now I am using mostly Visual Basic on PC.