Home AMX User Forum NetLinx Studio

Referencing device via variable

Currently I have a button event with a line of code like this:
SEND_STRING dvScaler, "StringtoSend"

Is it possible to call the device (dvScaler) as a variable (I know it's a device variable, but I'd like to reference it by char)
dvScaler = 5001:6:1
CHAR cDeviceName = 'dvScaler'
SEND_STRING cDeviceName, "StringtoSend"

Note, this does compile, but throws a warning about char to integer, but will not execute properly

Comments

  • viningvining Posts: 4,368
    No you can't. A dev is a 3 part structure of integers (or longs) and you're trying to cram them into a single char.

    What could you possibly gain if you could do this?
  • HedbergHedberg Posts: 671
    jabramson wrote: »
    Currently I have a button event with a line of code like this:
    SEND_STRING dvScaler, "StringtoSend"
    

    Is it possible to call the device (dvScaler) as a variable (I know it's a device variable, but I'd like to reference it by char)
    dvScaler = 5001:6:1
    CHAR cDeviceName = 'dvScaler'
    SEND_STRING cDeviceName, "StringtoSend"
    

    Note, this does compile, but throws a warning about char to integer, but will not execute properly

    That should not compile, in my opinion. You are violating type rules -- twice.

    First, you are trying to assign a character variable as if it were an array. Probably what you want to do is:

    define_variable
    CHAR cDeviceName[] = 'dvScaler'

    That will remove the warning that you are seeing, but it will throw another when you get to your send_string because it is expecting a structure of type device and you are giving it an array of type character. I don't know why the compiler doesn't choke and puke at this. I can only assume that there is some allowance for old Axcess code where there was no type device and the compiler was expecting a single byte integer.

    The moral of this story is that you have to obey typing rules if you are going to get the system to do what you want. send_string and send_command expect an argument of type device so that's what you must give. You can name the variable anything you want, but it must be of type device which is a structure with a device number, port, and system -- all integers.

    If you want your send_string to work as written, try this instead:
    define_device
    
    dvScaler = 5001:6:0
    
    define_variable
    
    dev cDeviceName = dvScaler
    
    

    assuming that "stringtosend" works out to be some string.
  • Actually, the one instance I wish this worked is when debugging from a console. Taking jabramson's example, let's say I want to dynamically change what device "DEV DeviceName" is pointing to, but I want to change it from the console. I could set up a SEND_COMMAND that takes a string like, "'5001:6:0'", does some parsing and ATOIing to change the D:P:S for DeviceName. However while sitting in a Telnet session and the customer is on the phone panicking, I can't remember if dvScaler is 5001:6, or 5001:7. The console has knowledge of the name/D:P:S mapping:
    Welcome to NetLinx v3.60.453 Copyright AMX LLC 2010
    >ON[dvTPScaler, 2]
    Sending On[10001:6:1,2]
    


    It'd just be nice to have access to that while in NetLinx:
    In Telnet:
    >SEND_COMMAND vdv_Change_Device_By_DPS, "'5001:6:1'"
    >SEND_COMMAND vdv_Change_Device_By_Name, "'dvScaler'"
    
    In NetLinx:
    DATA_EVENT[vdv_Change_Device_By_DPS]
    {
        COMMAND:
        {
            STACK_VAR DEV dvNew;
            // DATA.TEXT = '5001:6:1'
            
            dvNew.NUMBER = ATOI(REMOVE_STRING(DATA.TEXT,':',1));
            dvNew.PORT = ATOI(REMOVE_STRING(DATA.TEXT,':',1));
            dvNew.SYSTEM = ATOI(DATA.TEXT);
    
            dvDeviceName = dvNew;
        }
    }
    
    DATA_EVENT[vdv_Change_Device_By_Name]
    {
        COMMAND:
        {
            STACK_VAR DEV dvMapped;
            // DATA.TEXT = 'dvScaler'
            
            dvMapped = Return_Device_From_Internal_Name_Map(DATA.TEXT);
            // dvMapped = dvScaler;
            dvDeviceName = dvMapped;
        }
    }
    
  • viningvining Posts: 4,368
    If you want to do this just create a virtual dev and in the data event's command handler create your own look up table for literal strings and a means to execute what ever commands you might want to execute. This one virtual can then control all the devs you want using literal strings and execute commands, button pushes, send strings, etc. You could even send this virtual a command to print out a list of all the literal strings in the look up table and what the D:P:S they reference are or any other info you might want to store and lookup through a telnet session.
  • DHawthorneDHawthorne Posts: 4,584
    From a telnet session, "send command dvScaler ..." will in fact work, I do it all the time. As long as you use the same name as defined in the program, the master will interpret it correctly. I add the caveat that you might need to compile with debugging information; I always do, so I couldn't be sure it works if you do not. I suspect it is needed, and that is where it gets the token from.
    Actually, the one instance I wish this worked is when debugging from a console. Taking jabramson's example, let's say I want to dynamically change what device "DEV DeviceName" is pointing to, but I want to change it from the console. I could set up a SEND_COMMAND that takes a string like, "'5001:6:0'", does some parsing and ATOIing to change the D:P:S for DeviceName. However while sitting in a Telnet session and the customer is on the phone panicking, I can't remember if dvScaler is 5001:6, or 5001:7. The console has knowledge of the name/D:P:S mapping:
    Welcome to NetLinx v3.60.453 Copyright AMX LLC 2010
    >ON[dvTPScaler, 2]
    Sending On[10001:6:1,2]
    


    It'd just be nice to have access to that while in NetLinx:
    In Telnet:
    >SEND_COMMAND vdv_Change_Device_By_DPS, "'5001:6:1'"
    >SEND_COMMAND vdv_Change_Device_By_Name, "'dvScaler'"
    
    In NetLinx:
    DATA_EVENT[vdv_Change_Device_By_DPS]
    {
        COMMAND:
        {
            STACK_VAR DEV dvNew;
            // DATA.TEXT = '5001:6:1'
            
            dvNew.NUMBER = ATOI(REMOVE_STRING(DATA.TEXT,':',1));
            dvNew.PORT = ATOI(REMOVE_STRING(DATA.TEXT,':',1));
            dvNew.SYSTEM = ATOI(DATA.TEXT);
    
            dvDeviceName = dvNew;
        }
    }
    
    DATA_EVENT[vdv_Change_Device_By_Name]
    {
        COMMAND:
        {
            STACK_VAR DEV dvMapped;
            // DATA.TEXT = 'dvScaler'
            
            dvMapped = Return_Device_From_Internal_Name_Map(DATA.TEXT);
            // dvMapped = dvScaler;
            dvDeviceName = dvMapped;
        }
    }
    
Sign In or Register to comment.