Technical Forum

SIMATIC WinCC

C Script - Read DWORD Tag and map to Binary Bits

Thread Starter: Chris White   Started: 4/26/2012 10:49 AM   Replies: 9

« Previous thread Next thread »
Page 1 of 1 (10 items)
  4/26/2012, 10:49 AM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hi all,

I want to create tag mappings to the PLC in a 32 bit U/S Integer and then once in WinCC, use C Script to map the individual bits to single Binary Tags (Internal) to save the licences on External Tags.

What script do I need to use to take a 32bit Integer and break it out into its individual binary bits, so that I can map them to their corresponding internal binary tags?

Cheers and many thanks! Rnf:lblSmileyTooltip_

Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
  4/26/2012, 11:09 AM
Joined 1/3/2006
Last visit: 6/18/2013
Posts: 549
Rating:
Rated: Outstanding [3.83 out of 5 / rated 29 time(s)]. (29) 
Rated: Outstanding [4 out of 5 / rated 2 time(s)]. (2) 
Hi,
You can access the individual bits like this:
Suppose you have DWORD tag having name "DWORD_your_tag"
Now to map individual bits do

DWORD_bit_0:=GetTagDWord("DWORD_your_tag") & 0x1 ;
DWORD_bit_1:=GetTagDWord("DWORD_your_tag") & 0x2 ;

Where
"DWORD_bit_0" and "DWORD_bit_1" are your internal bool tags.





=== Edited by manmeet @ 4/26/2012 11:39 AM [GMT ] ===


Top
Thank you for this post from:
  4/26/2012, 11:12 AM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Absolutely superb!!

Many thanks!! Rnf:lblSmileyTooltip_

Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
  4/26/2012, 12:13 PM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 

Hi there,

I'm getting a few errors... here is the code: -

#include "apdefap.h"

int gscAction( void )
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
// WINCC:TAGNAME_SECTION_END

// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END
{
HMI_STEST_20_00:=GetTagWord("HMI_STATUS_DW0") & 0x1 ;
HMI_STEST_20_01:=GetTagWord("HMI_STATUS_DW0") & 0x2 ;
}


HMI_STEST_20_00 and 01 are Binary Tags in the Internal Register.

Errors are: - <Ident> expected before =
                  <Ident> expected before <eof>


Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
  4/26/2012, 12:45 PM
Joined 1/3/2006
Last visit: 6/18/2013
Posts: 549
Rating:
Rated: Outstanding [3.83 out of 5 / rated 29 time(s)]. (29) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hi Chris,
 Use "GetTagDWord" and not "GetTagWord"

Also use only this and see:
BOOL z,w;
z=GetTagDWord("HMI_STATUS_DW0") & 0x1 ;
w=GetTagWord("HMI_STATUS_DW0") & 0x2 ;

SetTagBit("HMI_STEST_20_00",z) ;
SetTagBit("HMI_STEST_20_01",w) ;





=== Edited by manmeet @ 4/26/2012 1:16 PM [GMT ] ===


=== Edited by manmeet @ 4/26/2012 1:15 PM [GMT ] ===


Top
  4/26/2012, 1:33 PM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hi there,

I've done that but not getting much joy.

It warns that the conversion may loose information?

The script is running on a 1 second cyclic but I am not seeing the same value in the binary tag as the directly linked binary bit tag that is also mapped for comparison?

It wont let me use the HMI_STEST_20_00: statement because of the colon at the end?

So i've declared the tags as shorts above and removed the colons?

short HMI_STEST_20_00;
HMI_STEST_20_00=GetTagWord("HMI_STATUS_DW0") & 0x1 ;
SetTagBit("HMI_STEST_20_00",HMI_STEST_20_00);



=== Edited by Chris White @ 4/26/2012 1:33 PM [GMT ] ===



Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
  4/26/2012, 3:33 PM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 

Managed to sort this.

Realised it was the byte issue where the array in the S7 processor is Motorola format and the WinCC format is Intel so they are in reverse.

So avoid hastle and swapping things around, I am mapping the signals in byte tags.

So created a External "Byte Tag"  DB22,DBB0

Then completed the action script e.g.....

short ALM_00_00;
short ALM_00_01;

ALM_00_00=GetTagByte("AL_DB0") & 0x0001 ;
ALM_00_01=GetTagByte("AL_DB0") & 0x0002 ;

SetTagBit("ALM_00_00",ALM_00_00);
SetTagBit("ALM_00_01",ALM_00_01);

All working now!!


Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
Thank you for this post from:
  5/2/2012, 9:44 AM
Joined 10/11/2006
Last visit: 6/13/2013
Posts: 1750
Rating:
Rated: Outstanding [3.45 out of 5 / rated 77 time(s)]. (77) 
Users with special expertise supervising conferences
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hi,

I found the faq for bit operation in a dword

http://support.automation.siemens.com/WW/view/en/27039111
Top
Thank you for this post from:
  5/2/2012, 10:10 AM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
I think i'm happier with my...

short ALM_00_00=GetTagByte("AL_DB0") & 0x0001;
SetTagBit("ALARM_00-00",ALM_00_00);

Much tidier code to work with, and its in C Script which is more common throughout WinCC so ensures future engineers can work on it quickly.

I never use VB in WinCC unless its an absolute must, just crazy mixing two languages. I've also had more issues with VB code not working due to compatibility issues, version issues and so on.

Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
  5/2/2012, 10:12 AM
Joined 1/6/2012
Last visit: 10/18/2012
Posts: 50
Rating:
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Also for future reference - to address bits in a word the following codes are used: -

//Bit 0                    0x0001
//Bit 1                    0x0002
//Bit 2                    0x0004
//Bit 3                    0x0008
//Bit 4                    0x0010
//Bit 5                    0x0020
//Bit 6                    0x0040
//Bit 7                    0x0080



=== Edited by Chris White @ 5/17/2012 11:29 AM [GMT ] ===



Chris White
Control / Software Engineer - Ovivo Water (UK) Ltd.
* All views are my own and not neccesarily the views of Ovivo Water.
Top
Page 1 of 1 (10 items)
Actions