TIA copy boolean data to a word

Jonnie_R

Member
Join Date
Feb 2012
Location
Brecon
Posts
216
Hi,

I'm still at the beginning of my journey with TIA, and am doing something for which I'm sure there must be a better way than writing each bit individually.

I have a data type that I defined with 15 boolean tags in, however I want to pack these individual tags into a word inside a data block for the SCADA system to read, rather than individual bits.

To achieve this at the moment I am doing it bit by bit in ladder which just seems uneconomical, especially when I have to repeat this several times.

Please tell me there is a better way.

Thanks.

Edit: Found a way with a bit of Googling. Thanks if you looked anyway.
 
Last edited:
Please post your alternative for future reference.

I found a suggestion from a Googling that led me to create a function in SCL that takes 16 bits as inputs and outputs the word using the following simple code:

Code:
FUNCTION "BitsToWordL2" : Void
TITLE = PACK BITS TO A WORD
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : JRead
FAMILY : COGEN
VERSION : 0.1
//Pack bits into a word by taking inputs as bits and writing out to a word
   VAR_INPUT 
      bit00 : Bool;  
      bit01 : Bool;   
      bit02 : Bool; 
      bit03 : Bool;  
      bit04 : Bool; 
      bit05 : Bool;  
      bit06 : Bool;  
      bit07 : Bool; 
      bit08 : Bool;  
      bit09 : Bool; 
      bit10 : Bool;  
      bit11 : Bool;  
      bit12 : Bool;  
      bit13 : Bool;  
      bit14 : Bool;  
      bit15 : Bool;  
   END_VAR

   VAR_OUTPUT 
      "WORD" : Word;   // Output word from bits
   END_VAR


BEGIN
	// Pack bits to the word
	#WORD.%X0 := #bit00;
	#WORD.%X1 := #bit01;
	#WORD.%X2 := #bit02;
	#WORD.%X3 := #bit03;
	#WORD.%X4 := #bit04;
	#WORD.%X5 := #bit05;
	#WORD.%X6 := #bit06;
	#WORD.%X7 := #bit07;
	#WORD.%X8 := #bit08;
	#WORD.%X9 := #bit09;
	#WORD.%X10 := #bit10;
	#WORD.%X11 := #bit11;
	#WORD.%X12 := #bit12;
	#WORD.%X13 := #bit13;
	#WORD.%X14 := #bit14;
	#WORD.%X15 := #bit15;
	
END_FUNCTION

I also used the reverse to write out a word into bits.
 
For functions like this I use the AT view method.
Basically it allows you to declare an alternative data structure for the same memory area.

Below is an example. Notice that the starting addresses are the same (18.0 and 22.0), for subsequent data structures.

The caveat is that either the data must be non-optimised, or you have to select the retain to "Set in IDB".

In the TIA help system, search for "Overlaying tags with AT"

AT_in_FB_declaration.png
 
For functions like this I use the AT view method.
Basically it allows you to declare an alternative data structure for the same memory area.

Below is an example. Notice that the starting addresses are the same (18.0 and 22.0), for subsequent data structures.

The caveat is that either the data must be non-optimised, or you have to select the retain to "Set in IDB".

In the TIA help system, search for "Overlaying tags with AT"


Is AT command possible for every language on TIA or only for SCL as on classic?
 
Is AT command possible for every language on TIA or only for SCL as on classic?
If I recall, it is all languages, but for optimized blocks the retentive setting needs to be "set in IDB" for some reason.
 

Similar Topics

I have 2 TIA Wincc projects. One project is in TIA V17 Wincc Professional and other project is in TIA V15 Wincc Advance. How can I copy the Wincc...
Replies
1
Views
1,252
Hi everyone! I am working on a Siemens plc (1200/1500), and I have two instruction that i have to perform. A) data structure (40 bools, 40...
Replies
3
Views
2,477
All, We are looking into the best ways to protect IP in PLC/SCADA code and the latest offerings included with TIA portal seem much better than...
Replies
3
Views
3,948
Hi all, I am a bit crazy from behavior of WinCC (actually TIA 15). I have two opened projects and I need to copy some screen items (buttons, ...)...
Replies
3
Views
4,066
I am using v14 with a 1215 dc/dc/dc. I need to copy a 50 element array of strings to another 50 element array of strings. I can work it out for...
Replies
3
Views
4,072
Back
Top Bottom