Home AMX User Forum NetLinx Studio

Dynamic Devices, would that work?

Hello to All,

recently discovered that a function does not return a DEV. this would work?

Simply ...

DEV myDEV_TEST = 301:1:0
...

DEFINE_FUNCTION INTEGER GET_DEVICE_NUMBER(DEV myDEV)
{
RETURN myDEV.NUMBER
}
DEFINE_FUNCTION INTEGER GET_DEVICE_PORT(DEV myDEV)
{
RETURN myDEV.PORT
}
DEFINE_FUNCTION INTEGER GET_DEVICE_SYSTEM(DEV myDEV)
{
RETURN myDEV.SYSTEM
}

...

DEFINE_FUNCTION TURN_ON(INTEGER myCANAL)
{
ON[GET_DEVICE_NUMBER(myDEV_TEST):GET_DEVICE_PORT(myDEV_TEST):GET_DEVICE_SYSTEM(myDEV_TEST),myCANAL]
}

Theoretically, it should be something Mounted Similar to "ON [301:1:0, XX]


Sorry, my English is Google.

Comments

  • Hi Anarckos,

    you could transform a DEV struct ot a string and then back to a DEV struct.

    Here is a quick solution:
    DEFINE_FUNCTION DevToStr(DEV dv, CHAR sToStr[])
    {
      sToStr = "ITOA(dv.NUMBER), ':', ITOA(dv.PORT), ':', ITOA(dv.SYSTEM)"
    }
    
    DEFINE_FUNCTION StrToDev(CHAR sFromStr[], DEV dv)
    {
      dv.NUMBER = ATOI(REMOVE_STRING(sFromStr,':',1))
      dv.PORT   = ATOI(REMOVE_STRING(sFromStr,':',1))
      dv.SYSTEM = ATOI(sFromStr)
    }
    
  • Hello, papadouk

    I liked the idea, I'll check if this solution fits well in my code.

    but would still like to find out if the code that I created would work.

    Thanks.
  • the8thstthe8thst Posts: 470
    Here is my Dev to Ascii function:
    define_function char[20] dpstoa(dev dvID)
    {
    	return "itoa(dvID.Number), ':', itoa(dvID.Port), ':', itoa(dvID.System)"
    }
    

    It might also work easier for you to build a device array with all of the possible devices the function could return and then have the function simply return an the index for the device in the array.

    It all depends on what you are using the function to accomplish.
  • the8thst wrote: »
    Here is my Dev to Ascii function:
    define_function char[20] dpstoa(dev dvID)
    {
    	return "itoa(dvID.Number), ':', itoa(dvID.Port), ':', itoa(dvID.System)"
    }
    

    It might also work easier for you to build a device array with all of the possible devices the function could return and then have the function simply return an the index for the device in the array.

    It all depends on what you are using the function to accomplish.

    the idea would be something like this. I was wanting to send a function name from the point of Light and he returned the Device and channel. whether it be dimmer or relay that is being controlled otherwise.
  • mushmush Posts: 287
    Anarckos wrote: »
    DEV myDEV_TEST = 301:1:0

    DEFINE_FUNCTION INTEGER GET_DEVICE_NUMBER(DEV myDEV)
    {
    RETURN myDEV.NUMBER
    }
    DEFINE_FUNCTION INTEGER GET_DEVICE_PORT(DEV myDEV)
    {
    RETURN myDEV.PORT
    }
    DEFINE_FUNCTION INTEGER GET_DEVICE_SYSTEM(DEV myDEV)
    {
    RETURN myDEV.SYSTEM
    }

    DEFINE_FUNCTION TURN_ON(INTEGER myCANAL)
    {
    ON[GET_DEVICE_NUMBER(myDEV_TEST):GET_DEVICE_PORT(myDEV_TEST):GET_DEVICE_SYSTEM(myDEV_TEST),myCANAL]
    }

    G'day Anarckos,

    Yes, this code works!

    Cheers
  • Tanks

    Tanks, Mush.
  • jweatherjweather Posts: 320
    Keep an array of possible devices, and just return an index to the desired device.
Sign In or Register to comment.