Home AMX User Forum NetLinx Studio

Virtual Device ports

I'm a bit confused. Everywhere on the forum and Netlinx help it is stated virtual devices have only one port (unless adjusted by SET_VIRTUAL_PORT_COUNT).

I made a quick test code:
PROGRAM_NAME='Test'

DEFINE_DEVICE

vdvDevice1	=	33001:1:0
vdvDevice2	=	33001:2:0

DEFINE_START

DEFINE_EVENT

CHANNEL_EVENT[vdvDevice1,1]
{
    ON:
    {
	SEND_STRING 0, "'Port 1'"
    }
}
CHANNEL_EVENT[vdvDevice2,1]
{
    ON:
    {
	SEND_STRING 0, "'Port 2'"
    }
}

I pulsed both of the channels I defined and here is the DIAG ouput:
Line      1 (15:03:31.994)::  Port 1
Line      2 (15:03:31.994)::  Memory Available = 208963064 <18624>
Line      3 (15:03:36.850)::  Port 2

Why did it work?

Comments

  • GregGGregG Posts: 251
    Ports are automatically created for virtual devices when they are defined in DEFINE_START - If they are sequential and start from port 1.

    The main reasons to define them using SET_VIRTUAL_PORT_COUNT are if you will be using just higher port numbers without defining the lower ones, or if you will be calculating the ports in code and don't want to list them all in advance.

    As far as I can recall, I have never run into a case where I needed to use SET_VIRTUAL_PORT_COUNT.
  • GregG wrote: »
    Ports are automatically created for virtual devices when they are defined in DEFINE_START - If they are sequential and start from port 1.

    The main reasons to define them using SET_VIRTUAL_PORT_COUNT are if you will be using just higher port numbers without defining the lower ones, or if you will be calculating the ports in code and don't want to list them all in advance.

    As far as I can recall, I have never run into a case where I needed to use SET_VIRTUAL_PORT_COUNT.

    If this is true now I don't think it used to be.

    I had an issue way back when I first started programming with higher number virtual ports without calling set_virtual_port_count. Things like pushes worked but iirc levels and possibly feedback did not function correctly and the additional ports did not actually show up in the device tree. It's possible this has been changed though as that was maybe 8-9 years ago at this point (which is a terrifying thought).

    I'm curious if your additional ports are there without using set_virtual_port_count so let us know :)
  • If I recall correctly, by default there are 8 ports and 8 levels that are accessible on virtual devices, anything over 8 needs to be explicitly set using SET_VIRTUAL_PORT_COUNT or LEVEL_COUNT. This is the same for channels, anything over 255 needs to be set with SET_VIRTUAL_CHANNEL_COUNT

    Frank Krauch, AMX ACE
  • GregGGregG Posts: 251
    This works for both port 8 and port 9 on an NI700 and an NX1200 (and as far as I have experienced, always worked back to the time of the NXI):
    DEFINE_DEVICE
    
    vdvDevice1 = 33001:1:0
    vdvDevice2 = 33001:2:0
    vdvDevice3 = 33001:3:0
    vdvDevice4 = 33001:4:0
    vdvDevice5 = 33001:5:0
    vdvDevice6 = 33001:6:0
    vdvDevice7 = 33001:7:0
    vdvDevice8 = 33001:8:0
    vdvDevice9 = 33001:9:0
    
    DEFINE_EVENT
    
    Channel_Event[vdvDevice8,1]
    {
    	On: Send_String 0,'Port 8 - On'
    }
    Channel_Event[vdvDevice9,1]
    {
    	On: Send_String 0,'Port 9 - On'
    }
    

    And this also works on both masters (which I didn't expect, so it might be a new v4+ firmware feature):
    DEFINE_DEVICE
    
    vdvDevice8 = 33001:8:0
    vdvDevice9 = 33001:9:0
    
    DEFINE_EVENT
    
    Channel_Event[vdvDevice8,1]
    {
    	On: Send_String 0,'Port 8 - On'
    }
    Channel_Event[vdvDevice9,1]
    {
    	On: Send_String 0,'Port 9 - On'
    }
    

    I tried to downgrade to 3.x firmware in the NI700, but apparently that isn't supported. If I remember sometime over the weekend I'll give it a shot against an old NXI I have hanging around.
  • cmasoncmason Posts: 123
    Interesting.

    Thanks for the responses.

    I thought that defining them might have made the difference, but all of the documentation I have read, seemed so adamant about the limitations and never mentioned "unless defined".

    Perhaps AMX should/will generate definitive updated documentation about the current limitations on Ports, Channels, and levels.
  • From my experience, if using a device with a port greater than 1 as the lone device in an event, such as I've seen from the examples posted so far in this thread, NetLinx does "create" it as one would expect. However, if used in an array or some other defined at runtime method, NetLinx isn't as copacetic.
  • Joe HebertJoe Hebert Posts: 2,159
    SET_VIRTUAL_PORT_COUNT

    Consider the following code:
    DEFINE_DEVICE
    
    dvTP 		= 10001:1:0
    
    vdvPort1	= 33001:1:0
    vdvPort2	= 33001:2:0
    vdvPort3	= 33001:3:0
    
    DEFINE_VARIABLE
    
    DEV vdvPorts[] = {
       vdvPort1,
       vdvPort2,
       vdvPort3
    }
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,1] {PUSH: {SEND_STRING vdvPort1,"'Hey Port 1'"}}
    BUTTON_EVENT[dvTP,2] {PUSH: {SEND_STRING vdvPort2,"'Hey Port 2'"}}
    BUTTON_EVENT[dvTP,3] {PUSH: {SEND_STRING vdvPort3,"'Hey Port 3'"}}
    BUTTON_EVENT[dvTP,4] {PUSH: {SEND_STRING vdvPorts,"'Hey Ports'"}}
    


    Pushing Buttons 1,2,3 and 4 results in the following:
    Line      1 (11:32:47):: String To [33001:1:1]-[Hey Port 1]
    Line      2 (11:32:47):: String From [33001:1:1]-[Hey Port 1]
    Line      3 (11:32:51):: String To [33001:2:1]-[Hey Port 2]
    Line      4 (11:32:55):: String To [33001:3:1]-[Hey Port 3]
    Line      5 (11:32:58):: String To [33001:1:1]-[Hey Ports]
    Line      6 (11:32:58):: String From [33001:1:1]-[Hey Ports]
    Line      7 (11:32:58):: String To [33001:2:1]-[Hey Ports]
    Line      8 (11:32:58):: String To [33001:3:1]-[Hey Ports]
    

    Notice how only port 1 generates String To and String From.

    If you look at the online tree only 1 port shows up under 33001.

    Add the following code:
    DEFINE_START
    SET_VIRTUAL_PORT_COUNT (vdvPort1,3)
    

    Pushing Buttons 1,2,3 and 4 results in the following:
    Line      1 (11:35:03):: String To [33001:1:1]-[Hey Port 1]
    Line      2 (11:35:03):: String From [33001:1:1]-[Hey Port 1]
    Line      3 (11:35:06):: String To [33001:2:1]-[Hey Port 2]
    Line      4 (11:35:06):: String From [33001:2:1]-[Hey Port 2]
    Line      5 (11:35:09):: String To [33001:3:1]-[Hey Port 3]
    Line      6 (11:35:09):: String From [33001:3:1]-[Hey Port 3]
    Line      7 (11:35:12):: String To [33001:1:1]-[Hey Ports]
    Line      8 (11:35:12):: String From [33001:1:1]-[Hey Ports]
    Line      9 (11:35:12):: String To [33001:2:1]-[Hey Ports]
    Line     10 (11:35:12):: String From [33001:2:1]-[Hey Ports]
    Line     11 (11:35:12):: String To [33001:3:1]-[Hey Ports]
    Line     12 (11:35:12):: String From [33001:3:1]-[Hey Ports]
    

    Notice that all 3 ports generate String To and String From.

    If you look at the online tree all 3 ports show up under 33001.

    There is clearly a difference when you use SET_VIRTUAL_PORT_COUNT and if you don’t use it things may work fine perfectly for your situation but I would recommend following the protocol and add the 1 line of code just to avoid any gotchas down the road.
  • NZRobNZRob Posts: 70
    Interestingly - I am using a 12 port module and it works every time - thought I had a SET_VIRTUAL_PORT_COUNT in it but just looked after reading this and I don't have one.
  • That has been my past experience. If you don't set the virtual port count some things still work, but other things most definitely don't, and when you run into one of them it's a pain in the *** to figure out what's going on.
Sign In or Register to comment.