Home AMX User Forum NetLinx Studio

Multi control on relay card

Hi

I would like to know if is there an another away of select active to do control on relay card

I have to control six shade dc motor, up and down and stop when I need. I will use 5 relay for each motor shade. I would like program it as I can select a group of shade and press only one button to raise other button for down and other one for stop

any cue will be appreciate

Comments

  • DHawthorneDHawthorne Posts: 4,584
    If it's NetLInx you can group the relays in a DEVCHAN array.

    DEVCHAN dvcRelay1 = {dvRelayPort, 1}
    DEVCHAN dvcRelay2 = {dvRelayPort, 2}
    DEVCHAN dvcRelay3 = {dvRelayPort, 3}

    DEVCHAN dvcRelays[] = {dvcRelay1, dvcRelay2, dvcRelay3}

    Now, ON[dvcRelays] will turn all three relays on at once, etc.

    By the way, you can also create your DEVCHAN array without declaring each relay seperately -

    DEVCHAN dvcRelays[] = {{dvRelayPort, 1}, {dvRelayPort, 2}, {dvRelayPort, 3}}
  • DenisDenis Posts: 163
    Devchan

    Tanks DHawthorne

    But my real question is to do what I want I'm looking someting who can replace select active as:
    select`
          {
             active ([dvtp,1],[dvtp,2])
               {
              do this
               {
             active ([dvtp,1],[dvtp,5],[dvtp,6])
              {
               do that
              }
    }
    
    etc.....

    I have DC motor
  • champchamp Posts: 261
    The quickest way is to stack your button events

    BUTTON_EVENT [dvtp,1]
    BUTTON_EVENT [dvtp,2]
    {
    PUSH:
    {
    ON[dvBLIND1, DIR_UP]
    }
    }
    .
    BUTTON_EVENT [dvtp,1]
    BUTTON_EVENT [dvtp,5]
    BUTTON_EVENT [dvtp,6]
    {
    PUSH:
    {
    ON[dvBLIND2, DIR_UP]
    }
    }

    The above way is not good if you do it too often because you are creating multiple events for each button push, which can cause event stack overflows.
    Otherwise try using DEVCHANS for touch panel buttons
  • Denis wrote:
    select`
          {
             active ([dvtp,1],[dvtp,2])
    

    Assuming those are touch panels, you also want to avoid referencing channels on them in that fashion. If you want to know if a button is being held while running your mainline/feedback code, have a variable set on the push, cleared on the release - and test that variable instead.

    If you're trying to test if a button is lit, on the other hand, test the same thing that lit it up in the first place.

    People have experienced erratic behavior when trying to use the state of a button channel the way you have it shown above...

    - Chip
  • DenisDenis Posts: 163
    Need your advice

    Hi

    Is it possible to get advice from expert?

    To resolve my problem, I staked event handler, I isolated IF condition with pairs of {} and I would like to know if I can get problems in the futur. This code seem to work fine and do what I need. If I process with select active, I get a very long code to cover all possibility

    I created array nSTORES_PISCINE [6] ( french words meaning blinds in swimming pool)
    PUSH:
    	{
    	    {
    	    IF(nSTORES_PISCINE [1] = 1)	// UP SHADE WINDOWS # 1
    		{
    		OFF [dvSTORES_P_1,1]
    		OFF [dvSTORES_P_1,3]
    		ON  [dvSTORES_P_1,2]
    		ON  [dvSTORES_P_1,4]
    		OFF [dvSTORES_P_1,5]
    		OFF [dvSTORES_P_1,7]
    		ON  [dvSTORES_P_1,6]
    		ON  [dvSTORES_P_1,8]
    		}
    	    }
    	    {
    	    IF (nSTORES_PISCINE [2] = 2)	// UP SHADE WINDOWS # 2
    		{
    		OFF [dvSTORES_P_2,1]
    		OFF [dvSTORES_P_2,3]
    		ON  [dvSTORES_P_2,2]
    		ON  [dvSTORES_P_2,4]
    		OFF [dvSTORES_P_2,5]
    		OFF [dvSTORES_P_2,7]
    		ON  [dvSTORES_P_2,6]
    		ON  [dvSTORES_P_2,8]
    		}
    	    }
    	    {
    	    IF (nSTORES_PISCINE [3] = 3)	// UP SHADE WINDOWS # 3
    		{
    		OFF [dvSTORES_P_3,1]
    		OFF [dvSTORES_P_3,3]
    		ON  [dvSTORES_P_3,2]
    		ON  [dvSTORES_P_3,4]
    		OFF [dvSTORES_P_3,5]
    		OFF [dvSTORES_P_3,7]
    		ON  [dvSTORES_P_3,6]
    		ON  [dvSTORES_P_3,8]
    		}
    	    }
    	    {
    	    IF (nSTORES_PISCINE [4] = 4)	// UP SHADE WINDOWS # 4
    		{
    		OFF [dvSTORES_P_4,1]
    		OFF [dvSTORES_P_4,3]
    		ON  [dvSTORES_P_4,2]
    		ON  [dvSTORES_P_4,4]
    		OFF [dvSTORES_P_4,5]
    		OFF [dvSTORES_P_4,7]
    		ON  [dvSTORES_P_4,6]
    		ON  [dvSTORES_P_4,8]
    		}
    	    }
    	    {
    	    IF (nSTORES_PISCINE [5] = 5)	// UP SHADE WINDOWS # 5
    		{
    		OFF [dvSTORES_P_5,1]
    		OFF [dvSTORES_P_5,3]
    		ON  [dvSTORES_P_5,2]
    		ON  [dvSTORES_P_5,4]
    		OFF [dvSTORES_P_5,5]
    		OFF [dvSTORES_P_5,7]
    		ON  [dvSTORES_P_5,6]
    		ON  [dvSTORES_P_5,8]
    		}
    	    }
    	    {
    	    IF (nSTORES_PISCINE [6] = 6)	// UP SHADE WINDOWS # 6
    		{
    		OFF [dvSTORES_P_6,1]
    		OFF [dvSTORES_P_6,3]
    		ON  [dvSTORES_P_6,2]
    		ON  [dvSTORES_P_6,4]
    		OFF [dvSTORES_P_6,5]
    		OFF [dvSTORES_P_6,7]
    		ON  [dvSTORES_P_6,6]
    		ON  [dvSTORES_P_6,8]
    		}
    	    }
    	    {
    		WAIT 1
    	    	nSTORES_PISCINE [1] = 0
    		nSTORES_PISCINE [2] = 0
    		nSTORES_PISCINE [3] = 0
    		nSTORES_PISCINE [4] = 0
    		nSTORES_PISCINE [5] = 0
    		nSTORES_PISCINE [6] = 0
    	    }
    	 }
    
  • How about this.

    Denis,

    I think I can help you.

    First, the braces {} around each {IF{code}} are not required.

    Second, why is the variable nSTORES_PISCINE[] defined as an array or required in your program?

    Could your code be written like this?
    Define_Device
    dvSTORES_P_1  = 00301:1:0 // Relay Card 1
    dvTP          = 10001:1:0 // Touch Panel
    
    Define_Constant
    Integer nShadeUpButtons[] =  // Buttons to Control Shade Group Up
    {
      201, // Shade Group 1
      202, // Shade Group 2
      203, // Shade Group 3
      204, // Shade Group 4
      205, // Shade Group 5
      206  // Shade Group 6
    }
    
    Define_Event
    Button_Event[dvTP,nShadeUpButtons]
    {
      PUSH:
      {
        Switch(Get_Last(nShadeUpButtons)) // Index of button that is pushed
        {
          Case 1: // UP SHADE WINDOWS # 1
          {
            OFF [dvSTORES_P_1,1]
            OFF [dvSTORES_P_1,3]
            ON  [dvSTORES_P_1,2]
            ON  [dvSTORES_P_1,4]
            OFF [dvSTORES_P_1,5]
            OFF [dvSTORES_P_1,7]
            ON  [dvSTORES_P_1,6]
            ON  [dvSTORES_P_1,8]
          }
          Case 2: // UP SHADE WINDOWS # 2
          {
            // Code here  
          }
          Case 3: // UP SHADE WINDOWS # 3
          {
            // Code here  
          }
          Case 4: // UP SHADE WINDOWS # 4
          {
            // Code here  
          }
          Case 5: // UP SHADE WINDOWS # 5
          {
            // Code here  
          }
          Case 6: // UP SHADE WINDOWS # 6
          {
            // Code here  
          }
        }
      }
    }
    
    The button channel array nShadeUpButtons[] can be any channel numbers you like since it we are only looking at the index of the array in the Switch - Case section. Also, you do not need the variable nSTORES_PISCINE unless it is used elsewhere in your program.

    I hope this helps you.
  • GSLogicGSLogic Posts: 562
    Because you are using the same RELAY commands, if you use a DEV array you can do this code in just a few lines.


    DEV relays[] = {dvSTORES_P_1, dvSTORES_P_2, dvSTORES_P_3, dvSTORES_P_4, dvSTORES_P_5, dvSTORES_P_6}

    BUTTON_EVENT[dvTP,nShadeUpButtons]
    {
    PUSH:
    {
    STACK_VAR nIDX;
    nIDX = GET_LAST(nShadeUpButtons);
    OFF [RELAY[nIDX],1];
    OFF [RELAY[nIDX],3];
    ON [RELAY[nIDX],2];
    ON [RELAY[nIDX],4];
    OFF [RELAY[nIDX],5];
    OFF [RELAY[nIDX],7];
    ON [RELAY[nIDX],6];
    ON [RELAY[nIDX],8];
    }
    }
  • DenisDenis Posts: 163
    Selective shade buttons

    Hi guys

    Tanks for your advices and codes samples, but I tried both and they give same results. The reason why I used the braces {} around each {IF{code}} is to isolate each if itself.

    The goal what I'm looking for is if I choose shade one, shade 3 and shade 4, after selection I press up button and these 3 shades go up in the same time. I want to select any shade ( from 6 ) and when I press up or down button the shades selected move in the same time. If I use many relay cards, it's for I control DC motor and I needs reverse polarity to get up and down.

    (12 shades, 4 relays by shade )

    The code as I asked an expert advice, is the best I found to do what I need, but since I'm beginer in this world, I need to know if it's the best way take
  • Spire_JeffSpire_Jeff Posts: 1,917
    Denis,

    I can think of a different way to accomplish what you are trying to do, but it doesn't mean that it is any better than the way you have chosen. I don't see any problems with the code you have posted, and unless you are looking to do something else in addition to what you are already doing, I wouldn't change it. Basically, if it's not broken, don't fix it.

    Just my humble opinion,
    Jeff
  • HedbergHedberg Posts: 671
    A variation on what Gary Spaniola suggested which will check the status of your nSTORES_PISCINE array
    DEFINE_VARIABLE
    
    CONSTANT DEV vdvPiscineDevices[]=
    {
    	dvSTORES_P_1,
    	dvSTORES_P_2,
    	dvSTORES_P_3,
    	dvSTORES_P_4,
    	dvSTORES_P_5,
    	dvSTORES_P_6
    }
    
    
    
    PUSH:
    {
    	STACK_VAR INTEGER iIndx
    	FOR(iIndx = 1; iIndx < 7; iIndx++)
    	{
    		IF(nSTORES_PISCINE[iIndx])
    		{
    			OFF [vdvPiscineDevices[iIndx],1]
    			OFF [vdvPiscineDevices[iIndx],3]
    			ON  [vdvPiscineDevices[iIndx],2]
    			ON  [vdvPiscineDevices[iIndx],4]
    			OFF [vdvPiscineDevices[iIndx],5]
    			OFF [vdvPiscineDevices[iIndx],7]
    			ON  [vdvPiscineDevices[iIndx],6]
    			ON  [vdvPiscineDevices[iIndx],8]
    		}
    	}
    	WAIT 1
    	{
    		FOR(iIndx = 1; iIndx < 7; iIndx++)
    		{
    	  	   nSTORES_PISCINE [iIndx] = 0
                    }
            }
    }
    

    There are many ways to do this efficiently. the code above (which I've not checked) is the way that I would do it, but I don't think it's inherently better than a select active or switch case.
  • DenisDenis Posts: 163
    Error message

    Hi Hedberg

    I don't if it's me but I get this message

    "ERROR: (468): C10231: Cannot reference STACK_VAR [IINDX] inside a WAIT
    "
  • jjamesjjames Posts: 2,908
    STACK_VARs cannot be used inside WAITs, you'll need to change it to a LOCAL_VAR.
  • HedbergHedberg Posts: 671
    STACK_VARs cannot be used inside WAITs, you'll need to change it to a LOCAL_VAR.

    Right. I should have compiled the code to check.

    Another solution would be to take out the wait -- I don't think it's necessary. Also, the two loops could be combined -- turn off the flags in the same loop after they are tested.

    Sorry for the error and any confusion.

    Harold
  • One thing I see which can improve your function is instead of clearing the selected shades at the end of the push, use a timeline to clear the selections (nSTORES_PISCINE[]=0) after a certain period of time from the last button push on that page. In other words, it looks to me like you're selecting the shades, turning them on in the nSTORES_PISCINE array when they're selected, then turning them off after a button is pushed:
    WAIT 1
    nSTORES_PISCINE [1] = 0
    nSTORES_PISCINE [2] = 0
    nSTORES_PISCINE [3] = 0
    nSTORES_PISCINE [4] = 0
    nSTORES_PISCINE [5] = 0
    nSTORES_PISCINE [6] = 0

    But, if the client selects shades 1, 3, and 5, then pushes the down button, then decides to stop them halfway, the selections will have cleared after the down button was pushed. In order to hit the 'Stop', the client would have to re-select all the shades that are moving, then hit 'stop', which isn't very easy. You'd have to select a period of time for the selections to be active that's roughly equal to the length of time for the shades to go from full up to full down, to make sure the client will be able to stop them without re-selecting even as they get near the top or bottom of their travel. Plus, you can light up the selections on the touchpanel (turn the button ON to indicate that they're selected), and they'll turn off about when the shades land most of the time -- which would be pretty slick in my opinion.


    Besides that, you're code looks good. Harold's code is very efficient and would be my choice.


    --John
  • DenisDenis Posts: 163
    Sugestions

    Hi everybody

    Tanks for your sugestions, I will try them in few days. For the moment I have to prepare the " Festival Son & Image 2006" of Montreal www.fsiexpo.com

    I will continue this job when the preparation of this show will be complete
Sign In or Register to comment.