Home AMX User Forum NetLinx Studio

Monitoring IO ports using DEVCHAN or ??

I am using a Netlinx 3000 to monitor if zones in a security system are on or off. That is done by using relays connected to the IO ports. Trying to turn all lights off in the building if all zones are on guard.

I am trying something like:

if (IOzones are all ON)
{turn all lights off}

Has anyone done this (or similar) successfully using DEVCHAN or should I try another way?

Comments

  • HedbergHedberg Posts: 671
    Thorleifur wrote:
    I am using a Netlinx 3000 to monitor if zones in a security system are on or off. That is done by using relays connected to the IO ports. [...]
    Has anyone done this (or similar) successfully using DEVCHAN or should I try another way?

    First, the IO ports may function in one of two ways and the behavior is a little different depending on how they are configured. My recollection is that these are called HIGH and LOW, but check the NI3000 doumentation about the IO ports to be sure. Also, as to what these modes mean. I don't think the documentation is crystal clear, so, if you're like me, you may have to experiment a little to get the exact results you want.

    As for controlling lights based on IO port status, I have used button events to track the IO ports. When an IO port goes on, it generates a press, when it goes off, a release. You can use a devchan array for your button_event, but there are other, and in my opinion, easier to implement and understand) ways. Look at recent threads about button arrays to see what I mean -- same idea. "get_last" is your friend, though with IO ports you can use button.input.channel..

    You can also use channel events, but, depending on how things are configured, IO status is not always reflected in channel events the way I would anticipate. Check the doc where it says "Setting an input to ACTIVE HIGH will disable the ability to use that channel as an output."

    so, this is what it might look like (I haven't tested this exact code):
    integer nIOChan[] = {1,2,3,4,5,6,7,8}
    
    button_event[dvIO,nIOChan]
    {
      push:
      {
        switch(button.input.channel)
        {
           case 1:
           {  
              //do some stuff including tracking chan 1 status, if necessary
           }
           //etc
        }
      }
      release:
      {
         //do some parallel stuff, as required
      }
    } 
    
    

    that's the way I do it, anyway.
  • Thanks Hedberg

    I didn?t go very deep into the IO configuration cause it seems to be working correctly. I?ve been using them to turn on and off lights in each department when a single zone changes from On or OFF position. I was just having problems turning off lights in the common areas when there was no-one in the building, or on when someone entered the building.

    But this seems to be working perfectly with "get_last"

    This is what I did.. a bit edited.
    dvIO = 5003:17:1
    INTEGER IOchan[] = {1,2,3,4,5,6}
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvIO,IOchan]
    {
        push:
        {
    	STACK_VAR INTEGER Index
            Index = GET_LAST(IOchan)
    	switch(Index)
    	{
    	    case 1:
    	    {io1 = 1}
    	   //continued
    	}
        }
        release:
        {
    	STACK_VAR INTEGER Index
            Index = GET_LAST(IOchan)
    	switch(Index)
    	{
    	    case 1:
    	    {io1 = 0}
    	 //continued
    	}
    }
    
    

    And then I use Define_Call event and an if function to determine if any of the zones are in the OFF postition (In the channel_event. It may be a bit simple approach but it works).

    So thanks again Hedberg, thanks alot.
  • yuriyuri Posts: 861
    can't you do something like this in your DEFINE_PROGRAM:

    DEFINE_PROGRAM

    nIO1 = [dvIO, 1]
    nIO2 = [dvIO, 2]

    etc

    then you can do something with variables nIO1 and nIO2 :)
  • Yes, I could...

    ... but that would just be too simple ;)

    But this way is a bit more simple for now because I have to add some extra code to some cases. If zone 1 is on I can?t turn off some lights in zone 3 and etc.

    Isn?t it better also to use button events because then one does not load the Netlinx with too much to do, calculations and stuff? Same for call events?
  • viningvining Posts: 4,368
    If you wanted you could create a timeline to trigger the evaluation so instead of doing the evaluation on every pass of the program it can be done when appropriate for the situation, once a second, minute, 5 minutes, an hour, etc. Then inside the executing code put in further conditions to prevent executing the same event over and over again. You don't need to turn off the lights 50 times a day when they're already off.

    Of course that's another reason to think about leaving the execution of the event in the button_event or channel_event.
  • yuriyuri Posts: 861
    Thorleifur wrote:
    ... but that would just be too simple ;)

    But this way is a bit more simple for now because I have to add some extra code to some cases. If zone 1 is on I can?t turn off some lights in zone 3 and etc.

    Isn?t it better also to use button events because then one does not load the Netlinx with too much to do, calculations and stuff? Same for call events?

    still, using my method, you could create a timeline like vining said to check some variables against each other, and by that turn the light on or off...

    For as far as i can remember checking stuff like that in your DEFINE_PROGRAM is how i learned it in AMX class. You ALWAYS get the correct feedback, even when the controller went offline or something :)
  • I am already..

    ... using your method to do this. Just figuring out hte time-things. Havn?t used that before
    I still like Hedbergs method though. It?s a bit cleaner I think :)

    Thanks Yuri.
Sign In or Register to comment.