Сonverting values

Good day!
We came another question.
Our function in the element is invoked as follows

runScript(concat("app.DMK.convert(",toStr({Power Supply /DMK32 First Power input/Active power of phase L1}),")"))

We need to return the element itself Decrease the number of such in 1000, as it can be done without making addenda in the function.

can be passed to the function parameter More like so

def convert(inputValue, inputParam): if inputParam == 1: outputValue=int(str((hex(inputValue))[:-4]),16)/1000 else outputValue=int(str((hex(inputValue))[:-4]),16) return outputValue
But unfortunately, this design does not work
Another problem is the value of type int, because if for example 21300 / 1000 = 21.3, and the function returns 21

The problem is solved!
Function

def convert(inputValue,inputParam): return float(int(str((hex(inputValue))[:-4]),16)) / inputParam
The function call

runScript(concat("app.DMK.convert(",toStr({inputValue}),",1000",")"))

[Fix]
Function

def convert(inputValue,inputParam): return float(inputValue >> 16) / inputParam
The function call

runScript(concat("app.DMK.convert(",toStr({inputValue}), ",", toStr(1000),")"))

After you define the function as described in the previous post, periodically get an error:

[code]Exception: Error executing expression binding on
First power input.Root Container.Power.Rated power .Rated power of phase L1.value
caused by ExpressionException: Error parsing script for runScript() expression: Traceback (innermost last):
(no code object) at line 0
OverflowError: integer literal too large

caused by Traceback (innermost last):

(no code object) at line 0

OverflowError: integer literal too large

Ignition v7.3.1 (b496)
Java: Sun Microsystems Inc. 1.6.0_24[/code]

In what may be the problem?

Sorry, I was on vacation yesterday. Let me look over what you’ve got, and I’ll post something up for you. :slight_smile:

I modified the function to change the order of magnitude as a function of the transmitted Parameters. as follows

def convert(inputValue,inputParam): return float(inputValue >> 16) / inputParam

The function call

runScript(concat("app.DMK.convert(",toStr({inputValue}), ",", toStr(1000),")"))

The converted value is divided by 1000
This method works, but occasionally an error


Exception: Error executing expression binding on
First power input.Root Container.Power.Rated power .Rated power of phase L1.value
   caused by ExpressionException: Error parsing script for runScript() expression: Traceback (innermost last):
  (no code object) at line 0
OverflowError: integer literal too large

   caused by Traceback (innermost last):

  (no code object) at line 0

OverflowError: integer literal too large


Ignition v7.3.1 (b496)
Java: Sun Microsystems Inc. 1.6.0_24

In what may be the problem?

Try:

def convert(inputValue,inputParam): return float(1L*inputValue >> 16) / inputParam

I think that occasionally it attempting to use the inputValue as an integer when it should be using it as a long integer. Multiplying by 1L should coerce the input to a long.

Nice use of a bit shift, by the way! :smiley:

Unfortunately did not help

All right, how about the previous one?

def convert(inputValue,inputParam): return float(int(str((hex(inputValue))[:-4]),16)) / inputParam

Or if looks too complex-- Not too complex for you to understand, just if it looks too busy:

def convert(inputValue,inputParam): return int(str((hex(inputValue))[:-4]),16) / float(inputParam)

Also, do you have an example of what input value does not work?

Managed to get rid of the error.
currently function looks like:

def convert(inputValue,inputParam): return float(long(inputValue) >> 16) /inputParam
Error stopped appearing after SalTag type has been changed to Float.

P.S.
Could you show a small example of how to use the script in the transation group to save data base the converted values.
:slight_smile:

Sure! I have a meeting to run off to, but I’ll put one together afterwords.

Here you go.