Home AMX User Forum NetLinx Studio

Odd channel behavior

for(nloop=length_array(HCS_Devices);nloop>0;nloop--)
		{
		if(HCS_Device_Stat[nloop] and HCS_Device_Count[nloop]<12 )
			{
			HCS_Device_Count[nloop]++
			[b]if(HCS_Device_Count[nloop]>11 and ![vdv_My_HCS, HCS_Devices_chan[nloop]])[/b]
				{
				on[vdv_My_HCS, HCS_Devices_chan[nloop] ]
				HCS_Device_Alarm_Sent_flag[nloop]=1
				}
			} // end if(HCS_Device_Stat[nloop])

I'm noticing some odd behavior that I dont understand.

In the example above the idea is that when I get a device offline during a poll, I increment it's count. When that count gets to 12 I turn on a channel on a virtual device. In the IF statement that is bolded, I also have a conditional that says If the channel is already on don't bother trying to turn it on again. (a one-time trap)

The problem is that the conditional is being ignored. The channel is clearly on in diagnostic, the variable tracking it shows it's on but the conditional statement fires anyway and the channel get's turned on again (this creating and error message sent out in another part of the code)

How am I being a bone-head?

Comments

  • I've had issues with using statements like ![dev,chan]. I think it is because there is not a condition there for the if statement to test. I bet if you were to say [dev,chan] = 1 or 0 instead of ![dev,chan] it would work like you expect it too.
  • PhreaKPhreaK Posts: 966
    ericmedley wrote: »
    The channel is clearly on in diagnostic, the variable tracking it shows it's on but the conditional statement fires anyway and the channel get's turned on again (this creating and error message sent out in another part of the code)

    Where's the code where you are tracking that channel state? I'd start by making sure that's rock solid.
  • ericmedley wrote: »
    			[b]if(HCS_Device_Count[nloop]>11 and ![vdv_My_HCS, HCS_Devices_chan[nloop]])[/b]
    

    I've seen peculiarities with the compiler before relating to ![dev,chan] logic. It shouldn't be necessary, but try it this way with some extra parentheses...

    if((HCS_Device_Count[nloop]>11) and (![vdv_My_HCS, HCS_Devices_chan[nloop]]))

    or try it as a two level if

    if(HCS_Device_Count[nloop]>11)
    if(![vdv_My_HCS, HCS_Devices_chan[nloop]])
Sign In or Register to comment.