WinCC, integer, Nachkommastellen

kaputt

Level-1
Beiträge
100
Reaktionspunkte
10
Zuviel Werbung?
-> Hier kostenlos registrieren
Hi!
Excuse me for using English.

It goes about a complex FB (it's a self made HMI -profi- interface to a Sipart DR22 - (it was a LOT of work to make it function some 10 years ago)). This FB has an integer interface, also for the inputs for the sollwert and manual stellwert.

I use PCS7 to generate the interface variables for this FB (it's giving a structure, NOT allowing scaling of individual values:cry:).
Of course this give me problems with the decimals. It is easy to show an integer using x/10 in the IO field. But my problem is to input a setpoint value from this field from WinCC. I am totally ignorant on scripting, but I have imagined to use the mouseclick to copy the setpoint value into an internal real and use this to manipulate the value (i.e. multiply with f.x. 10) before it is copied back to the original setpoint. Okay, my scripting knowledge limit is exceeded by far...:sb8: . My intermediate solution is using stupid sliders for manipulating the sollwert/stellwert.

Have anyone of you solved this problem before?

MfG
Kaputt
 
Hi,
there are two ways to do this:

1. Variable scaling in variable properties

I don't know if this is possible if you are using PCS7, but with raw WinCC you change the datatype of your PLCs integer variable to "Float 32-Bit IEE". And set "Formatanpassung" (don't know how it's named in english version) to "FloatToSignedWord".
Check "liniear scaling" and set the range for process to 0..10000 and range variable to 0..1000 for factor 10.
Then you have nothing to do with scripting or something else.


2. Scripting in I/O field
Add a C-script to property "outputvalue" like this:
Code:
return GetTagSWord ("IntVarToScale") /10.0;

Add a C-script on event "inputvalue" like this:
Code:
/* Attention: atof excepts dot as decimal delimiter!
 * If you are using an english version you don't need this.
 * In german we must substitute "," with "." 
 */
char *st;
st = strstr(value, ",");
if (st != NULL) {
  *st = '.';
}

SetTagSWord("IntVarToScale", atof(value) * 10);
 
Zuletzt bearbeitet:
Zurück
Oben