Device comparison issues when device value is hard-coded
I normally never hard-code device numbers, but it happens on occasion, usually for testing. I ran across this bug.
I was writing some test code to check online events and was getting odd results. While doing an if (device.data == 0:1:2) I was getting an unexpected "true". It appears the "if" ONLY looks at device.number (ignoring device.port and device.system) when the device is a hard-coded value. If I define a device and use the device name everything works as expected, or simply enclosing the hard-coded device in parenthesis works around the problem as well.
Here is my final test code:
with the following in sString after the master comes onilne:
I was writing some test code to check online events and was getting odd results. While doing an if (device.data == 0:1:2) I was getting an unexpected "true". It appears the "if" ONLY looks at device.number (ignoring device.port and device.system) when the device is a hard-coded value. If I define a device and use the device name everything works as expected, or simply enclosing the hard-coded device in parenthesis works around the problem as well.
Here is my final test code:
define_variable
char sString[2000]
define_event
data_event [0:1:0]
{
online:
{
// without parenthesis
if (data.device == 0:2:1)
{
sString = "sString, 'Without parenthesis 0:2:1',
'==',
itoa (data.device.number), ':',
itoa (data.device.port), ':',
itoa (data.device.system), $0D, $0A"
}
if (data.device == 0:1:999)
{
sString = "sString, 'Without parenthesis 0:1:999',
'==',
itoa (data.device.number), ':',
itoa (data.device.port), ':',
itoa (data.device.system), $0D, $0A"
}
// with parenthesis
if (data.device == (0:2:1))
{
sString = "sString, 'With parenthesis (0:2:1)',
'==',
itoa (data.device.number), ':',
itoa (data.device.port), ':',
itoa (data.device.system), $0D, $0A"
}
if (data.device == (0:1:999))
{
sString = "sString, 'With parenthesis (0:1:999)',
'==',
itoa (data.device.number), ':',
itoa (data.device.port), ':',
itoa (data.device.system), $0D, $0A"
}
}
}
with the following in sString after the master comes onilne:
Without parenthesis 0:2:1==0:1:1 Without parenthesis 0:1:999==0:1:1
Comments