Programming advice
Apprentice
Posts: 12
Hi,
I tried to create a virtual 'STOP' button in Netlinx & TP4 for a screen switch that doesn't have the physical wiring of a stop button using Screenstop_Ver1. However, that didn't work compared to Screenstop_ver2.
In the case of Screenstop_Ver1, the if(button.input.channel=BnScreenUp) command was used. The result was the "stop" button worked for the RelScreenDown, interrupting the ON time but this did not work for the RelScreenUp - channel switched off after 'wait' set time.
However the "stop" button worked for Ver2 with both relay channels stopped when btn selected. This was after i eliminated the the if(button.input.channel=BnScreenUp) and simply switched of both relay channels for up & down without determining which is operating.
Is there something which should be done in Ver1 such that the stop will work with if(button.input.channel) command?
Thanks.
Joe
I tried to create a virtual 'STOP' button in Netlinx & TP4 for a screen switch that doesn't have the physical wiring of a stop button using Screenstop_Ver1. However, that didn't work compared to Screenstop_ver2.
In the case of Screenstop_Ver1, the if(button.input.channel=BnScreenUp) command was used. The result was the "stop" button worked for the RelScreenDown, interrupting the ON time but this did not work for the RelScreenUp - channel switched off after 'wait' set time.
However the "stop" button worked for Ver2 with both relay channels stopped when btn selected. This was after i eliminated the the if(button.input.channel=BnScreenUp) and simply switched of both relay channels for up & down without determining which is operating.
Is there something which should be done in Ver1 such that the stop will work with if(button.input.channel) command?
Thanks.
Joe
0
Comments
No, it's perfectly ok to have IF/ELSE statements within the SWITCH/CASE, but you must test the proper variables to get the results you desire. First look at the three case statements:
What's inside the third case will only be executed when button.input.channel = BnScreenStop. So, it makes absolutely no sense to test if button.input.channel = BnScreenUp inside that case because you KNOW that the test result is false (or = 0). That was Dave's point supra.
Another thing you should look at is that you are turning on relay channels that don't, at first blush, make any sense. Those are:
[dvRelay,BnScreenUp]
and
[dvRelay,BnScreenDown]
Maybe your intent is to track the status of the relays; if so, just check the status of the actual relays rather than a surrogate.
Third, you are turning what appear to be latching relays on without checking to see if the opposite relay is already on. Perhaps you are using mutually_exclusive, though I doubt it because then you wouldn't be able to turn off both relays at the same time with simple "off" commands.(see "TOTAL_OFF). I've been told that you can damage some screen control systems if you turn on both the up and down motors at the same time though I've never actually seen this happen. In any event, I doubt if you want both relays to be on at the same time and I think it's best to prevent it.
How to fix this?
Testing button.input.channel seems fine to me. When it is the screen up button,
1. send the down relay an off command -- if it's already off this won't hurt.
2. turn on the up relay
3.wait 10 seconds and turn off the up relay
4. handle feedback to the TP as desired. One easy way (and the preferred way of many) to do this is to put the following statements in DEFINE_PROGRAM
[vdvVTP,BnScreenUp] = [dvRelay,RelScreenUp]
[vdvVTP,BnScreenDown] = [dvRelay,RelScreenDown]
Do the opposite for the BnScreenDown case.
For the BnScreenStop case, just turn both relays off. If you want to only send one off command to the relays, test relay status instead of the button.input.channel value.
Here it is:
I put the To command in there because it seems the most appropriate feedback for the stop button -- I see no reason to latch it.
Something to notice about the above code (and also your example 1) -- by using the Else construction, the Off[dvRelay,RelScreenDown] command will be executed even if the relay is not on, so long as the up relay is not on either. In this example, it doesn't matter, but
you have to make sure that the code represents your intent. My guess is that the intent you had when you designed this out would have better been expressed with Else If like so:
[...]
Else If([dvRelay,RelScreenDown])
but I'm not sure.
But, as I said, for this particular example, there's really not much point in testing the relay status inside your stop case--just turn both relays off.
I haven't actually compiled the above, so forgive me if there are any typos I missed.
Thank you for the detailed explaination & the important code. It works!
Regards
Joe