plc.myforum.ro Forum Index plc.myforum.ro
PLCs users www.plc.myforum.ro!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Display an integer value in an IO field with decimal places

 
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> SIEMENS SIMATIC HMI- Reg. U
View previous topic :: View next topic  
Author Message
valz
Member 3
Member 3
valz

Joined: 26 Jul 2015
Posts: 771

PostPosted: 14/03/2023 18:41    Post subject: Display an integer value in an IO field with decimal places Reply with quote

How do you display an integer value in an IO field with decimal places in WinCC Unified?
https://support.industry.siemens.com/cs/document/109816808/
You can use JavaScript in WinCC Unified PC Runtime to output an integer value in the IO field with decimal places.

Application case
A specific value is only handled in the PLC as an integer (a setpoint value, for example). However, this actually stands for a value with decimal places. The following shows how the integer value in an IO field can be output with decimal places corresponding to the actual value.

The following figure shows the integer value 124, which using a script is displayed with decimal places corresponding to the actual value of 12.4.

Display an integer value in an IO field with decimal places Display an integer value in an IO field with decimal places
Fig. 01

Procedure
To display an integer value with decimal places in an IO field using a script, you have to create an IO field. Select the IO field, click "Properties" and follow steps 1-8 as shown in the following figure:

Display an integer value in an IO field with decimal places Display an integer value in an IO field with decimal places
Fig. 02

In the "Mode" row, in the "Static value" column, click "Input/Output" and select "Output".
In the "Output format" row, in the "Static value" column, you select an output format for a floating-point value -> "{F}" (for the data type "Float"), for example. Details are available in the WinCC Unified Engineering manual (Defining the output format).
In the "Process value" row, in the "Dynamization" column, you select "Script".
Enter the following script:
Code:
01 export function EA_Feld_1_ProcessValue_Trigger(item) {
02 var value;
03 let tagl = Tags("Data_Integer_Value");
04 value = tagl.Read() / 10;
05    return value;
06 }


This script implicitly converts the integer value into a floating-point value by dividing it by the value "10". This causes the value in the IO field to be output as the data type "Float".
Click the "Alarm" icon and add a trigger.
In the "Trigger" field you select "Tags" as trigger.
Select the process variable "Data_Integer_Value".

In this way the IO field displays the corresponding integer values in Runtime with one decimal place.

Return of an input value via the IO field to the integer variable
If the operator changes the value using the same IO field, the input value should be written back to the integer variable.
To convert the input value from the "Float" data type back to an integer value, follow steps 9-12 as shown in the following figure:

Display an integer value in an IO field with decimal places Display an integer value in an IO field with decimal places
Fig. 03

9. In the "Mode" row, in the "Static value" column, you select the "Input/Output" mode. In the left column, click the small arrow next to "Process value".
10. In the "Change" row, in the "Dynamization" column, you select "Script".
11. Enter the following script:

Code:
01 export function EA_Feld_1_ProcessValue_OnPropertyChanged(item, value) {
02
03 let tagl = Tags("Data_Integer_Value");
04 tagl.Write(value * 10);
05
06 }


This script implicitly converts the entered floating-point value into an integer by multiplying it by the value "10". The "Write" command writes the input value back as an integer value.
Snippets
http://plc.myforum.ro/viewtopic.php?p=62469#62469
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> SIEMENS SIMATIC HMI- Reg. U All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro