What does this mean "Implicit Value Conversion"
Hey
I have a couple of channels in a project that tell me there is an implicit value conversion occurring. What I'm confused about is exactly what it means and why its a warning?
In the Qcode below:-
HydOilLowNCorNO is a digital parameter that determines whether the input condition is NC or NO which translates to if a logic 1 is good or bad.
MaintBypassSensorHydOilLow is a digital parameter that determines whether we should action the sensor inputs or simply ignore them. iI's used here in this channel and in an almost duplicate of the channel that deals with digital input HydOilLevelVeryLow which is the last switched step on the tank level sensor and which triggers an immediate idle down, and timed shutdown of engine
The Qcode is:-
TempResult:=0
If HydOilLowNCorNO Then TempResult:=Not(HydOilLevelLow) else TempResult:=HydOilLevelLow
If MaintBypassSensorHydOilLow then TempResult:=0
Result:=TempResult
The warning I get is that the bolded underline is an implicit value type conversion. What I struggle to understand is what is being converted? everything except the local variable TempResult is digital including the channel type IDC. There as far as I know is no way to declare a variable as specifically type digital and if I change line 1 to TempResult:=False then I get another implicit value type conversion warning for that line.
I know a warning isn't the end of the world but what do I need to do to get rid of the warning or produce better code? Is there a way to declare the local variable TempResult as type digital that Im simply not aware of?
Warnings in IQAN Design to me infer something is suboptimal but here I cant see what I should do to change that.
Customer support service by UserEcho
Hi Andy,
Your are correct, IQAN is warning that using numeric values as boolean or boolean values as numeric is suboptimal as you put it.
Hi
I have same issue (Implicit Value Type Conversion) when I update a project from Design 6.06 to Design 6.08.
Then, in my case, a lot IVTC warnings appear.
At Project Check component type 'Math Object' appear, but when I check it considers a IDC. See image below
Never the less the project is still functional as expected.
Ps.
We did not use Design 6.07, we moved from 6.06 to 6.08
Hi Tim,
Sorry, I did not read your comment in time, now I understand why.
Thanks
Ok lets take what is provided at face value "Using numeric values as Boolean, or boolean values as numeric should be avoided.......
I used numeric then I used the Qcode reserved words true and false. In both cases I got the same result. How else can one define a boolean value for a digital channel or variable within Qcode??
Andy
In your Qcode expression, the assignment of the value 0 to the variable TempResult is what gives it value type Integer.
The project check warns about the conversion on line two.
This assignment is made in two places, this is how the warning would look if you changed one to False:
If you change then also skip the assignment of Integer value 0 to the variable, IQANdesign will determine it is a Boolean:
By eliminating the step where the variable is assigned the value 0 every cycle, you also save a little processing time and memory.
An alternative approach could be to skip the "TempResult" variable; this is slightly more efficient:
Attached project file has these variants (and one optimized by using object list)
Avoid value type conversion in qcode.idsx
I am getting this same warning when I am attempting to perform boolean masking operations on a 16 bit binary value. The valve I am using provides a bit mapped 16 bit value for it's status. Any one of the 16 bits could be active at the same time, so I need to apply a boolean mask AND'ed against the 16 bit value so I can identify what the active errors are specifically. It seems ridiculous to flag the usage of a Boolean value and operation inside of a Integer Math Channel as an Implicit Type Conversion. There is NO type conversion. The value operated on is a 16 bit unsigned integer, ANDed with a boolean value. It seems that you should fix this as the warning is not valid/accurate in this case.
This is actually a very good example of where the warning implicit value type conversion helps in highlighting a problem.
In the example shown, your channel named "Internal error" will have the value 1 whenever any of the bits in the status word "LT_TRACK_ERROR_STAUS" is set.
The Boolean and operation does accept Integer values as input, any non-zero value is simply converted to True.
The result is Boolean, either False or True.
What you can use instead is bitwise and, band.
This takes integer as input and the result is an integer.
Better yet, in my opinion, is to directly extract the status bits. I would skip the 2-byte GPIN for status word and instead use 1-bit GPINs for each och the 16 error bits.