Monitoring IO ports using DEVCHAN or ??
Thorleifur
Posts: 58
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?
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?
0
Comments
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):
that's the way I do it, anyway.
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.
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.
DEFINE_PROGRAM
nIO1 = [dvIO, 1]
nIO2 = [dvIO, 2]
etc
then you can do something with variables nIO1 and nIO2
... 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?
Of course that's another reason to think about leaving the execution of the event in the button_event or channel_event.
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
... 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.