this expression works perfectly
toFloat({[.]1_00})/100
but is the syntax for this expression correct?
if ({[.]1_00},>1)
toFloat({[.]1_00})/100
???
the tag i am converting to a float, changes back to “0” as soon as ignition reads it, and i am trying to prevent the converted float from being set back to “0” so i was thinking if the tag that the expression is >1 then go ahead an convert, otherwise maintain your previous converted value.
by the way, the tag i am reading will never be less than 50.00
No the expression will be something like:if({[.]1_00}>1, toFloat({[.]1_00})/100, {[.]1_00})
when i do it that way, i get a red “x” on the corner of my tag
Just talked to you on the phone about your issue. Post the outcome here when you get a chance.
same results, even when i select the tag with insert tag icon method
if({[.]1_00}>1, toFloat({[.]1_00})/100, {[.]1_00})
You still get the red error. If it is a tag right click on it and hit the tag diagnostics and let us know the output.
RuntimeException: Type mismatch in operation ‘Greater Than’: expected ‘Number’, found ‘String’
Ignition v7.5.3 (b1163)
Java: Sun Microsystems Inc. 1.6.0_31
i am converting a string to a number…if that matters
So the “1” immediately after the greater than sign is implicitly/explicitly a string? If so, that needs to be changed to some sort of number (float, int, etc).
the tag’s value that this expression tag is looking at is a string value. it is either 000000 for zero or maybe 003400 to represent 340.00
the expression work just fine when only
toFloat({[.]1_00})/100
is used to convert the string to a float.
the problem i am trying to work around is that after the device recognizes that the string has been read, that register gets set back to 000000, and i want the expression tag to maintain the numerical value until it recieves another number greater than 000000 to convert, not reset back to 000000 like the actual device’s tag.
so i was thinking it wouldn’t reset…or convert the string to a float, if the string it was trying to convert is larger than 1
i think if i change the first tag to int4 instead of string this may work, my red x has disappeared.
i will test and report my results, but the red “x” is now gone
You can leave the original tag as a string if you like, and then cast the string into a float when using the expression. If you enter 001100, it will convert it to 1100 when using toFloat. For example:
if(toFloat({[.]1_00})>1, toFloat({[.]1_00})/100, toFloat({[.]1_00}))
Would return 11 if the original tag was 001100 (i.e., 1100).
This isn’t related to your expression, but it is relevant. I noticed you said that the value you’re reading resets to zero after being read.
You’re going to want to create a scan classes that uses polled reads instead of subscriptions and make sure the SQLTag(s) for these value(s) that reset belong to this scan class.
Otherwise you’re destined for a world filled with heartbreak, pain, and missing values.