Virtual device ports in module.

I was writing a Netlinx module the other day and wanted to be able to use multiple ports on the virtual device that is passed to the module. Like the Duet modules use where they pulse a channel on different ports. I know that I can pass a device array, but I'd rather not. Am I just having a brain fart or is this not possible?

Comments

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 227
    I believe the command is something like "Set_Virtual_Port_Count" . The virtual device you are using it on needs to be online. It can be fiddly, especially if you are using "translate_device" in conjunction.
  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 446

    From NetLinx Keyword Help

    SET_VIRTUAL_PORT_COUNT
    Lets the programmer override the default number of ports that a virtual device maintains.

    By default every virtual device maintains the state of a single port (port 1).

    Syntax:

    SET_VIRTUAL_PORT_COUNT(DEV Device, INTEGER Count)

    Parameters:

    Device - the virtual device to modify.

    Count - the number of ports that the specified virtual device should maintain.

    Returns: None

    Example:

    SET_VIRTUAL_PORT_COUNT (dvVirtual,2) // 2 ports

    With regards to TRANSLATE_DEVICE, set_virtual_port_count needs to be applied to the dynamic virtual device and then translate_device applied to each port on the virtual device pair.

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 227
    By fiddly I mean timing for when you apply translate_device to the device pairs. Then you may also need to do rebuild_events depending on how you code your events. I wrote a module that could dynamically add devices based on some configuration commands to the module. I got it to work with a lot of tweaking. This was one of those "I wonder if I can get this to work" experiments. Although it was a production module that I used regularly I felt it was really edge of the envelope for what Netlinx is reasonally capable of. I will stop now before I get upset thinking about Cafe Duet support and what could have been.
  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 446

    Edge of the envelope is writing NetLinx programs with no defined devices and populating device arrays from configuration file data...

    Yup - that's a thing :-)

  • Danny CampbellDanny Campbell Senior Member Posts: 310

    Thanks guys!

  • John NagyJohn Nagy CineTouch Product Manager Posts: 1,479

    @HARMAN_icraigie said:
    Edge of the envelope is writing NetLinx programs with no defined devices and populating device arrays from configuration file data...

    Yup - that's a thing :-)

    Yep, it's the basis of CineTouch. Same for UI, Rooms, Users, features. All defined in data... the program is the same in every system, and the panels are the same for every room in every system... data rules.

  • fogled@mizzou[email protected] h4x354x0r Posts: 547

    ... the program is the same in every system, and the panels are the same for every room in every system... data rules.

    I was headed that way at one point in time, but then I kinda got my enthusiasm beat out of me, and now it seems like a waste of time to work on. The time to have developed an abstract Netlinx program system was 10+ years ago. I think John and a few others rode the wave. I just drowned.

  • viningvining X Member Posts: 4,344

    Depending how or where its used you might have to also rebuild_event() after the SVPC. Normally its done in define start but not always. My memories of such things are very faded.

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 446

    rebuild_event() can be called anywhere - the key is that it only takes effect on the elements that have been manipulated within that same scope.

    I settled on f-ing with the length array as that's what worked for me.

          {
               stack_var integer iLen;
    
               iLen = length_array(dvDevArray);
               set_length_array(dvDevArray, MAX_DEVS); // MAX_DEVS is theoretical max + 1
               dvDevArray[iLen + 1] = 10003:1:0;
               iLen++;
               set_length_array(dvDevArray, iLen);
               rebuild_event();
           }
    
  • richardhermanrichardherman not-so-junior member Posts: 179

    This is how I did it (in a module):

    (vdvDevice is the virtual that's passed into the module)

    DEFINE_DEVICE
    
    vdvCam = DYNAMIC_VIRTUAL_DEVICE
    
    DEFINE_FUNCTION fnBuildDeviceArray()
    {
        STACK_VAR INTEGER nCount
        SET_VIRTUAL_PORT_COUNT(vdvDevice,PORT_COUNT)
        SET_VIRTUAL_PORT_COUNT(vdvCam,PORT_COUNT)
        FOR(nCount = 1; nCount <= PORT_COUNT; nCount++)
        {
        vdvCamArray[nCount] = vdvCam.NUMBER:nCount:vdvCam.SYSTEM
        TRANSLATE_DEVICE(vdvDevice.NUMBER:nCount:vdvDevice.SYSTEM,vdvCam.NUMBER:nCount:vdvCam.SYSTEM)
        }
        SET_LENGTH_ARRAY(vdvCamArray,PORT_COUNT)
        REBUILD_EVENT()
    }
    

    As '@JasonS' noted, using TRANSLATE_DEVICE can be a bit tricky. Still hoping for some explanation about this, like some internal AMX document that magically appears. Hint... it's all a bit trail and error now.

  • viningvining X Member Posts: 4,344

    I believe if you do your SVPC in define_start or in a function called by define start with out any wait delays you don't need to rebuild the event table because the event tables aren't yet built but if you do it anywhere else in code after the event tables are built that's when you have to use rebuilt_event() otherwise you won't get what you want.

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 446

    @vining said:
    I believe if you do your SVPC in define_start or in a function called by define start with out any wait delays you don't need to rebuild the event table because the event tables aren't yet built but if you do it anywhere else in code after the event tables are built that's when you have to use rebuilt_event() otherwise you won't get what you want.

    If any named element (device, channel, level, etc) referenced in an event trigger is not defined (DEFINE_DEVICE, DEFINE_CONSTANT, DEFINE_VARIABLE) the event table will not be built and REBUILD_EVENT is required.

  • viningvining X Member Posts: 4,344

    Right but if you set your values in define start even though they’re not initialized with a value in define device, variable or constant you don’t need rebuild event. At least that’s my recollection but if your dynamically building arrays based on various conditions or events that are used in event tables then you do need to rebuild them each time values are changed. Most event tables for most people are static so the use of rebuild event isn’t necassary but there are times when they need to be dynamically modified during runtime in which case it is needed.

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 446

    This channel event never happens:

    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
        volatile dev vdvTEST_3;
    
    (***********************************************************)
    (*                 STARTUP CODE GOES BELOW                 *)
    (***********************************************************)
    DEFINE_START
        vdvTEST_3 = 33003:1:0;
    
    (***********************************************************)
    (*                  THE EVENTS GO BELOW                    *)
    (***********************************************************)
    DEFINE_EVENT
    
    channel_event[vdvTEST_3,0]
    {
        on:
        {
        amx_log(AMX_ERROR,"'channel_event[',itoa(channel.device.number),',',itoa(channel.channel),']'");
        }
    }
    
Sign In or Register to comment.