Device comparison issues when device value is hard-coded

ColzieColzie Senior MemberPosts: 470
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:
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

  • rfletcherrfletcher Junior Member Posts: 217
    Huh, it wouldn't have even occurred to me that either data.device==0:1:2 or data.device==(0:1:2) would be valid code. I would have figured you'd need to either plug the numbers into a dev variable and compare that or run 3 comparisons against data.device.number, data.device.port, and data.device.system. I suppose it's exactly what you're doing in the define_device part of every program, but I'd never thought of hard coding a device using that syntax outside of define_device. It's always interesting to see the different approaches and methods we all find in the same language.
Sign In or Register to comment.