Home AMX User Forum NetLinx Studio

DATA_EVENT ONLINE: and DEV Arrays

Greetings,

I have a system with ten of the same serial devices connected to ten serial ports in a Netlinx based system. All of the devices are in a DEV array. Is there a way to do a DATA_EVENT ONLINE: for all ten devices in a single online event for the DEV? I need to SET_BAUD for all ten ports and I like my code short.

Thanks!

Comments

  • alexanboalexanbo Posts: 282
    Something like this should work:
    dvArray[] = {dv1,dv2,dv3}
    
    DATA_EVENT[dvArray]:
    {
      ONLINE:
      {
        SEND_COMMAND DATA.DEVICE,"'SET BAUD XXXXXXXX'"
      }
    }
    
  • DHawthorneDHawthorne Posts: 4,584
    If you make a device array, you can treat the array itself as a device, and any action taken on the array apply to every device in it. Likewise for events; any time an event occurs for any member of the array, an event for the array will occur as well. If you need to single out a specific member of the array in an event, you can use the GET_LAST function to do so.
  • DATA_EVENT ONLINE: and DEV Arrays

    Dave is absolutely correct with respect to GET_LAST() use in events with device arrays with one exception. Do not use GET_LAST() on DEV or DEVLEV arrays in a LEVEL_EVENT - it will not work correctly. You can use GET_LAST() on only the integer LEVEL in a LEVEL_EVENT but GET_LAST() does not work correctly on the DEV or combined DEVLEV components. This has been a problem for a long time and does not appear to be likely to be fixed anytime soon.
  • DHawthorneDHawthorne Posts: 4,584
    Dave is absolutely correct with respect to GET_LAST() use in events with device arrays with one exception. Do not use GET_LAST() on DEV or DEVLEV arrays in a LEVEL_EVENT - it will not work correctly. You can use GET_LAST() on only the integer LEVEL in a LEVEL_EVENT but GET_LAST() does not work correctly on the DEV or combined DEVLEV components. This has been a problem for a long time and does not appear to be likely to be fixed anytime soon.
    This is true and I had entirely forgotten about it because I almost never use DEVLEV or DEVCHAN arrays for any reason anymore. I make two arrays for my event handlers, a DEV array for the devices, and an INTEGER array for the channels, levels, or variable text addresses. Then I make the event in the form of <event_type>_EVENT [dvDevArray, iIntArray], and break out the individual elements with GET_LAST. For simplicity I'll make a local or stack (preferred, but not always feasible) straight off the bat to index them with, as so:
    BUTTON_EVENT [dvDevArray, iButnArray]
    {
        PUSH :
        {
            STACK_VAR INTEGER iDevIdx
            STACK_VAR INTEGER iButnIdx
    
            iDevIdx = GET_LAST(dvDevArray)
            iButnIdx = GET_LAST(iButnArray)
        }
    }
    

    From there, all your individual device references will be dvDevArray[iDevIdx], and your button press channels iButnArray[iButnIdx] (though I usually leave my references relative, except for feeback, and just work with iButnIdx directly).
  • DATA_EVENT ONLINE: and DEV Arrays

    Dave,

    I generally do the same thing - separate arrays for the DEVs and for the Channels, Levels, etc. Occasionally I will use a DEVCHAN or DEVLEV array but generally only for relays or contacts. The wierd thing about the LEVEL_EVENT bug is that it affects the DEV component of the event regardless of whether a DEV array is used in conjunction with explicit levels or an array of levels or a DEVLEV array is used instead. Avoiding the use of the DEVLEV does not solve the problem.

    At first, when I experienced the problem, I was using a DEVLEV array and thought separating the devices and levels into their own arrays would solve the problem. The GET_LAST() on the level works fine but the GET_LAST() on the DEV or DEVLEV component will almost always yield the wrong device. I say almost since GET_LAST() will sometimes return a non-zero value but it will be the last DEV that triggered a Button, Channel, or Data event for that same DEV array. Before I tracked this down, a couple of programs had some very interesting results to say the least. Tech Note 486 has all of the details for anyone that is interested.

    Reese
  • TurnipTruckTurnipTruck Posts: 1,485
    Does anyone know exactly why or when the GET_LAST bug occurs with respect to DEV arrays? Are there any Tech Notes on it?

    In a program that I just finished, I have ten serial devices in a DEV array. I am using GET_LAST from their DEV array to determine which device a string came from and then place it in the correct message array location. It seems to work fine.

    Thanks!
  • DATA_EVENT ONLINE: and DEV Arrays

    The GET_LAST() problem on DEV and DEVLEV arrays only occurs with LEVEL_EVENTs. See AMX Tech Note 486 for more information. Use of DEV or DEVCHAN arrays with other event types works fine.
Sign In or Register to comment.