Home AMX User Forum AMX General Discussion

Novice Programmer?

Title says everything but I need a little help. I have a camera at the front door connected to a matrix switch. I would like to have the TV jump to component_2, switch to camera for 10 sec and then jump back to the TV when the door bell is pushed. I currently have a PUSH command to switch while watching...

PUSH [TOUCH_PANEL, 69] (* BUTTON 69 WAS PRESSED ON TOUCH_PANEL *)
{
SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"
{
SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
}
}

I have one wire to ground and the other connected to channel 1 on device 17 and the other end connected to the door bell. This seems to work in a test run when I contact the wires

(* DOOR BELL RING, FRONT DOOR CAMERA *)

IF ([SENSORS,1]=1)
{
{
SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
}

SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"

WAIT 100
SEND_COMMAND LCD_TV,"'SP',SOURCE"
WAIT 30
SEND_COMMAND LCD_TV,"'SP',SOURCE"
}

However when in constant contact it seems to be in a loop switching back and forth continuously. Any help would be much appreciated.

Thanks,

Paul

Comments

  • HedbergHedberg Posts: 671
    thepainter wrote: »
    [...]
    However when in constant contact it seems to be in a loop switching back and forth continuously. Any help would be much appreciated.

    Thanks,

    Paul

    Is this an Axcent controller?

    A closure on your IO port should appear as a push (assuming input set "LOW"). So, try this:
    PUSH[17,1]
    PUSH [TOUCH_PANEL, 69]  (* BUTTON 69 WAS PRESSED ON TOUCH_PANEL *)
       {
         SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"
       {
         SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
       } 
       }
    

    this will cause the code to be executed when the PUSH occurs either as a result of the TP button being pressed or by the IO port being shorted by your doorbell. It will occur every time the button is pressed so if someone keeps pressing and releasing your doorbell, it will repeat.
  • I'm using a NI-3000 but I have been practicing my code starting from scratch reading up on the Axcent Manual so I have a mix of the old with the new right now. I tried the PUSH[17,1] but that didn't seem to work, it didn't loop but it also didn't switch to the component input. I'm not sure what you meant by this .... (assuming input set "LOW")...... please excuse my ignorance, I'm just getting my feet wet.

    Paul

    PS - Thanks for the quick response.


    Hedberg wrote: »
    Is this an Axcent controller?

    A closure on your IO port should appear as a push (assuming input set "LOW"). So, try this:
    PUSH[17,1]
    PUSH [TOUCH_PANEL, 69]  (* BUTTON 69 WAS PRESSED ON TOUCH_PANEL *)
       {
         SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"
       {
         SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
       } 
       }
    

    this will cause the code to be executed when the PUSH occurs either as a result of the TP button being pressed or by the IO port being shorted by your doorbell. It will occur every time the button is pressed so if someone keeps pressing and releasing your doorbell, it will repeat.
  • Paul,

    I think that you need to use a channel_event for this. It could look something like this:

    (where dvIO = 5001:17:0)

    CHANNEL_EVENT [dvIO,1]
    {
    ON:
    {
    DO_PUSH(TOUCH_PANEL,69)
    }
    }

    I am making an assumption that the doorbell button being pushed will turn on the IO port 1 when the doorbell butoon is pressed, and turn it off when the dorbell button is released.

    In that case, the channel_event will register that channel 1 for port 17 is on and will execute whatever code you want. If it does exactly the same thing as a panel push of button 69 you could get away with the DO_PUSH statement. If you are a real die-hard type, you could just duplicate the code here. Instead of doing either of these, I would probably create a DOORBELL() function and call it from both the channel event and the button push.
  • HedbergHedberg Posts: 671
    Oh, it's a Netlinx box. You said that the IO ports were device 17. But if you're using a Netlinx box, then the device is, as Danny points out, not 17, but 5001:17:0. So, the push (if that's the way you want to do it) would be:

    push[5001:17:0,1]
    {
    (do something)
    }

    If you look in the manual for any of the masters (NI3000, for example) you'll find information about how IO ports work. It explains that IO ports may be set to logic 'HIGH' or logic 'LOW'. basically, if your IO port light lights when the circuit is closed, it's set to logic 'LOW'. 'HIGH' and 'LOW' have to do with what voltage applied to the IO ports register as a push.

    Also, you'll find that IO ports, when used as inputs, function just like touch panel buttons and register pushes and releases and button events. To the best of my knowledge, you can't trigger a channel_event with an IO port just as you can't trigger a channel_event with a button press.

    Try the following code and short out IO ports to ground and see what happens:
    define_event
    
    button_event[5001:17:0,1]
    button_event[5001:17:0,2]
    button_event[5001:17:0,3]
    button_event[5001:17:0,4]
    button_event[5001:17:0,5]
    button_event[5001:17:0,6]
    button_event[5001:17:0,7]
    button_event[5001:17:0,8]
    {
      push:
      {
        send_string 0,"'Register a PUSH on IO channel ',itoa(button.input.channel)"
      }
      release:
      {
        send_string 0,"'Register a RELEASE on IO channel ',itoa(button.input.channel)"
      }
    }
    


    Normally you would define a device constant in define_device and use that in your button event, or push statements, rather than specifying the device out. From the code snip you posted, I think you already understand that.

    Also, the string to o will appear in a telnet session if you "msg on". Also, in Netlinx Studio diagnostics if you allow internal diagnostic messages. Also, you can see the IO channel pushes in Netlinx Studio if you "Enable Push Message Status Bar Display" and also in notifications.
  • Jorde_VJorde_V Posts: 393
    thepainter wrote: »
    Title says everything but I need a little help. I have a camera at the front door connected to a matrix switch. I would like to have the TV jump to component_2, switch to camera for 10 sec and then jump back to the TV when the door bell is pushed. I currently have a PUSH command to switch while watching...

    PUSH [TOUCH_PANEL, 69] (* BUTTON 69 WAS PRESSED ON TOUCH_PANEL *)
    {
    SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"
    {
    SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
    }
    }

    I have one wire to ground and the other connected to channel 1 on device 17 and the other end connected to the door bell. This seems to work in a test run when I contact the wires

    (* DOOR BELL RING, FRONT DOOR CAMERA *)

    IF ([SENSORS,1]=1)
    {
    {
    SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
    }

    SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"

    WAIT 100
    SEND_COMMAND LCD_TV,"'SP',SOURCE"
    WAIT 30
    SEND_COMMAND LCD_TV,"'SP',SOURCE"
    }

    However when in constant contact it seems to be in a loop switching back and forth continuously. Any help would be much appreciated.

    Thanks,

    Paul

    The way I would do it is this:
    IF ([SENSORS,1]==1) // Not necessary, but the extra = is easier to read
    {
      SEND_STRING MATRIX,'[PT1O03I05]' (* CAMERA FRONT DOOR , COMPONENT 2 *)
      SEND_COMMAND LCD_TV, "'SP', COMPONENT_2"
      WAIT 100
      {
         SEND_COMMAND LCD_TV,"'SP',SOURCE"
         WAIT 30{
             SEND_COMMAND LCD_TV,"'SP',SOURCE"
         }
      }
    }
    
  • [QUOTE=Hedberg;42145 To the best of my knowledge, you can't trigger a channel_event with an IO port just as you can't trigger a channel_event with a button press..[/QUOTE]

    I use channel_event with the IO port quite a bit.
  • HedbergHedberg Posts: 671
    I use channel_event with the IO port quite a bit.

    I looked at this last night before I posted on it and I had myself convinced that I couldn't get a channel event to trigger based on opening and closing contacts on an IO port. Obviously, I was wrong. If an IO port is set to "low" logic, both a channel_event "on" and a button_event "push" occur when the port is shorted to ground. When opened, an "off" and a "release" occur. If the port is set to logic high, the channel_event on and off do not occur and the push and release on the button_event are reversed: push when contact is broken and release when contact is made.

    I don't know that there's an advantage to using either the button_event or channel_event for watching an IO port using "low" logic. Guess it's just what somebody's used to.
  • Thanks so much for all the responses. I think I may have over simplified what I would like to accomplish.
    Channel_event works and my original sample works (SENSORS = 5001:17:0). My problem, which I have just now figured out is that I am not using a 'Doorbell' I have a 'Doorphone' (Avaya System)for my doorbell so when the button is pushed it actually leaves it on for 'x' secs so I can answer from the phone to see/hear who is at the door. After 'x' secs. it will revert back to original state. (I'll have to read the manual to find out how long). So I am thinking the looping would last for the 'x secs' and then work as expected. Does this make sense? If so how could I code this? Thanks again for the responses.

    Paul

    PS - Everything worked as expected when I manually touched the wires (like a doorbell) I was so happy, but then hit a snag with the above scenerio when I hooked up directly.
  • HedbergHedberg Posts: 671
    If you use an event, either a channel_event or a button_event, the code contained in the event will only run once. The code runs when the state changes -- either when there is a push or when the channel changes from off to on (or on to off).
Sign In or Register to comment.