How to copy a Siemens data type tag to a DWord

Ken Roach

Lifetime Supporting Member + Moderator
Join Date
Apr 2002
Location
Seattle, WA
Posts
17,481
This feels like a simple, elementary question, but I am a Siemens novice and know there are experts here.

My S7-1500 project (TIA Portal v17) has an I/O device that uses some PLC Data Types, including one that holds Status Bits. The data type has 32 named BOOLs inside it.

I want to copy those 32 bits into a DWord type Internal Memory tag, for an HMI feature to read bit-by-bit. The HMI is actually the WinCC Unified View of Things webserver feature and I want to create a set of indicator boxes on screen so show the status of each Bit in the Status Bits tag.

What is the correct LAD instruction that will copy the contents of a PLC Data Type tag into a DWord tag ?
 
Example for 1 bit, repeat as required for all your named status bits. Other options when using non-optimised blocks and the AT instruction also possible.

x0.jpg
 
Last edited:
I ended up doing 32 rungs (and having to do it twice because I skipped over one in the selector).

The COP instruction does this with no data type dependencies in the Rockwell ControlLogix. I was hoping for a similar way to take the user defined structure that is 32 bits long and copy its values, bit-by-bit, into an atomic 32- bit datatype (a DWord).

Thanks for pointing out I can do it more readably with SCL, like this:

Code:
#HMI_Status_DWord.%X0 := #Status_Structure.Accelerating;
#HMI_Status_DWord.%X1 := #Status_Structure.AllowExceedingOfSoftwareLimits;
#HMI_Status_DWord.%X2 := #Status_Structure.BreakingResistorOverTempError;
#HMI_Status_DWord.%X3 := #Status_Structure.CommsError
#HMI_Status_DWord.%X4 := #Status_Structure.ControlVoltageError;
#HMI_Status_DWord.%X5 := #Status_Structure.CurrentLoopError;
#HMI_Status_DWord.%X6 := #Status_Structure.Decelerating;
#HMI_Status_DWord.%X7 := #Status_Structure.EncoderError;
#HMI_Status_DWord.%X8 := #Status_Structure.Error;
#HMI_Status_DWord.%X9 := #Status_Structure.FlashMemoryError;
#HMI_Status_DWord.%X10 := #Status_Structure.FollowingError;
#HMI_Status_DWord.%X11 := #Status_Structure.FunctionError;
#HMI_Status_DWord.%X12 := #Status_Structure.I2TError;
#HMI_Status_DWord.%X13 := #Status_Structure.InitialisationError;
#HMI_Status_DWord.%X14 := #Status_Structure.InPosition;
#HMI_Status_DWord.%X15 := #Status_Structure.ModbusSlaveError;
#HMI_Status_DWord.%X16 := #Status_Structure.MotorLocked;
#HMI_Status_DWord.%X17 := #Status_Structure.MotorSupplyDetected;
#HMI_Status_DWord.%X18 := #Status_Structure.NotUsed;
#HMI_Status_DWord.%X19 := #Status_Structure.NotUsed_2;
#HMI_Status_DWord.%X20 := #Status_Structure.NotUsed_3;
#HMI_Status_DWord.%X21 := #Status_Structure.OUT1;
#HMI_Status_DWord.%X22 := #Status_Structure.OUT2;
#HMI_Status_DWord.%X23 := #Status_Structure.OvercurrentError;
#HMI_Status_DWord.%X24 := #Status_Structure.OvervoltageError;
#HMI_Status_DWord.%X25 := #Status_Structure.OvervoltageError;
#HMI_Status_DWord.%X26 := #Status_Structure.ShortCircuitError;
#HMI_Status_DWord.%X27 := #Status_Structure.SoftwareLimitExceeded;
#HMI_Status_DWord.%X28 := #Status_Structure.STOError;
#HMI_Status_DWord.%X29 := #Status_Structure.TemperatureError;
#HMI_Status_DWord.%X30 := #Status_Structure.UndervoltageError;
#HMI_Status_DWord.%X31 := #Status_Structure.VoltageError;

The exercise also illustrated for me that the vendor of the ProfiNet device and example code chose the enumerated Status bit order more or less at random, rather than their inherent order in the device.
 
Last edited:
My understanding of serialize / deserialize is that those functions concern the difference between a array of boolean elements and a byte/word/dword with addressable bits.

That is a little different than what I have.

There is a user-defined data type tag that is part of the vendor-supplied ProfiNet example code and objects for a JVL MAC3000 servo motor with a MAC00-EP4 ProfiNet interface module.

That tag has named sub-elements that are all BOOL type; they indicate various fault or error conditions on a servomotor.

I am using the modern embedded webserver feature of the S7-1500 with TIA v17, which serves up a limited set of WinCC Unified objects and features. They call it "View-of-Things".

One of the limitations is that user-defined datatypes are not addressable.

I can read a DWord tag, land configure an indicator to show the state of each bit, i.e. HMI_Status_DWord.%X17.

But I can't address that same indicator to read StatusStructure.MotorSupplyDetected.

The brute force method works fine, but I was hoping there was a way to do it with a more elegant instruction.

I'm a complete novice with Siemens, so I'm just bumbling my way through the instruction set.
 
You could create a UDT for the sub-elements and assign it to the input tag for the JVL motor inputs.
 
I downloaded the JVL example project and it contains a UDT for the status bits. The example code does not use the process image inputs but there is nothing stopping you declaring a tag at the relevant address and using it.

jvl.jpg
 
In case it is not obvious from LD's last post..

You can simply define the relevant inputs as a series BOOLs and as WORDs or DWORDs using overlapping addresses.
I.e.
BOOLs "inp_144_0" .. "inp_147_7" : %I144.0 .. %I147.7
WORDs "input_word_144", "input_word_146" : %IW144, %IW146
DWORD "input_dword_144" : %ID144

So, if you have defined a series of Inputs by the UDT as BOOLs, you can manually add an alternative symbol for the same addresses as a DWORD.
Then simply copy the inputs as a DWORD to the desired target DWORD.

This 'trick' of overlapping symbols only works for Inputs, Outputs and Merker addresses. Not DB adresses.
 
One of the limitations is that user-defined datatypes are not addressable.

I can read a DWord tag, land configure an indicator to show the state of each bit, i.e. HMI_Status_DWord.%X17.

But I can't address that same indicator to read StatusStructure.MotorSupplyDetected.


This is kindof an end around your initial (and very valid) question of how do you smoosh a pile of bits into a DWORD, but:


Based on some quick dorking around, it looks like VoT is only blocked from input/output structures, not custom data types in DBs. Well, it lets you select tags from DB structures and it compiles, didn't get as far as actually downloading to a PLC and testing....



You could copy the input UDT to a DB and then have the HMI view it from there. Not necessarily easier than any of the other methods presented, but wanted to toss it out there.
 
Here I read from a memory area and write those bits to a DB that's structured.

I'm reading and writing bytes, but can be done with double words etc..

Code:
// Load DB Number
#DB := #DB_NUM;
// Load Offset
#READ := #OFFSET * 10;
#WRITE := (#OFFSET-1)*2;
// Read Values
#VALUE1 := PEEK_BYTE(area:=16#81, dbNumber:=0, byteOffset:= #READ);
#VALUE2 := PEEK_BYTE(area := 16#81, dbNumber :=0, byteOffset := #READ +1);
// Write Values
POKE(area:=16#84, dbNumber:= #DB, byteOffset:= #WRITE, value:= #VALUE1);
POKE(area := 16#84, dbNumber:= #DB, byteOffset := #WRITE + 1, value := #VALUE2);
 

Similar Topics

Hi! For my application (in an S7-317 plc) I want to create two DB's. These DB's are filled with an array of a certain UDT. (Array[1..100] of...
Replies
5
Views
14,826
Gents, I have a DB, that is an array of a UDT. This UDT has got a combination of INT's and REAL's. When an action is completed, I want to move...
Replies
11
Views
4,243
How do I move one byte of data in an array to a UDT that is one byte in length. AB would be a slam dunk on this with a simple Copy instruction...
Replies
22
Views
5,408
I am tying to find a way to copy 10 words from my input area into a structure I have mapped out for my device. What is the best/simplest way to...
Replies
5
Views
2,160
Hello! Is it possible to copy pointer's pointing address to any variable at Siemens step7? I mean I have pointer address to db block with...
Replies
14
Views
15,561
Back
Top Bottom