## Forums

#### Guest

Welcome Guest, posting in this forum require registration.

 Pages: [1]
Author Topic: Return of CLOSEST incorrect?
nordic81
Member
Posts: 20
 Return of CLOSEST incorrect?on: March 25, 2019 (GMT)

Hi,
I’m trying to use the CLOSEST function for some custom PIDs as alarm triggers.
However the term CLOSEST(VAL{Engine Temperature}:1:0=1:140=0) returns either 0 for temperatures lower than 70°C and 140 for temperatures over 70°C.
That’s neither what I expected (1 and 0) not what I need for my equations.

What am i doing wrong? Is there a bug in the CLOSEST function working with integers?

Kind regards
nordic81

cintakc
Member
Posts: 1662
 Re: Return of CLOSEST incorrect?on: March 25, 2019 (GMT)

try this
LOOKUP(VAL{Engine Temperature}::0~70=1:71~140=0)

Capp777
Member
Posts: 2994
 Re: Return of CLOSEST incorrect?on: March 25, 2019 (GMT)

Quote from nordic81 on March 25, 2019
Hi,
I’m trying to use the CLOSEST function for some custom PIDs as alarm triggers.
However the term CLOSEST(VAL{Engine Temperature}:1:0=1:140=0) returns either 0 for temperatures lower than 70°C and 140 for temperatures over 70°C.
That’s neither what I expected (1 and 0) not what I need for my equations.

What am i doing wrong? Is there a bug in the CLOSEST function working with integers?

Kind regards
nordic81

End Quote.

Your equation has two test points 0 and 140.
If you enclose your integers in single quotes
0=’1′, the display will show 1. However an
alarm will still only see 0 or 140.

The wiki equation example shows value1 as
a string. The closest key value is returned.

Cintakc’s Lookup solution would be a better
choice.

nordic81
Member
Posts: 20
 Re: Return of CLOSEST incorrect?on: March 26, 2019 (GMT)

I must admit that I don’t understand why there’s a difference between the display values and values for calculations… Especially since the values for calculations are obviously the key parameters and not the measured values.

Either way, the suggested solution using the LOOKUP function works like a charm!

Thank you

 Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4