Home AMX User Forum NetLinx Studio

devchan array in modules?

I'm trying to create a devchan array in a module, using a device that is passed to the module rather than declared in it.
MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice)
DEFINE_DEVICE

DEFINE_VARIABLE
devchan dcChannels[] = {{vdvDevice,1},{vdvDevice,2},{vdvDevice,3},{vdvDevice,4}}
The compiler keeps complaining:"Initializer is not a constant". This seems to be due to vdvDevice being externally declared rather than in the DEFINE_DEVICE section of the module. The compiler works fine if I do the following:
MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice)
DEFINE_DEVICE
vdvLocalDev = 33001:1:0
DEFINE_VARIABLE
devchan dcChannels[] = {{vdvLocalDev,1},{vdvLocalDev,2},{vdvLocalDev,3},{vdvLocalDev,4}}
However, this does not achieve what I want - namely a devchan array for several channels on the device that is passed into the module. I was hoping for a devchan array solution so that later in my code I can do the following:
channel_event[dcChannels]{
 on:{
  //Do something
 }
 off:{
  //Do something else
 }
}
Any clues appreciated.

Roger McLean
Swinburne University

Comments

  • AMXJeffAMXJeff Posts: 450
    You can only create a devchan array with a constant dev. Since your passing in the dev into your module, that dev will never be a constant. You can either pass the entire devchan array into your module, or use an integer array inside your module instead of a devchan array.
    //OPTION 1
    MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice)
    DEFINE_DEVICE
    
    DEFINE_VARIABLES
    volatile integer nChannelList[] = 
    {
    	1,
    	2,
    	3,
    	4
    }
    
    DEFINE_EVENT
    
    channel_event[vdvDevice, nChannelList]
    {
    	on:
    	{
    		// do something with the code.
    	}
    }
    
    
    //OPTION 2
    MODULE_NAME='my module' (DEVCHAN dcChannels[], DEV dvDevice)
    DEFINE_DEVICE
    
    DEFINE_VARIABLES
    
    DEFINE_EVENT
    
    channel_event[dcChannels]
    {
    	on:
    	{
    		// do something with the code.
    	}
    }
    
  • annuelloannuello Posts: 294
    Fair enough. I guess it is possible to dynamically change the device outside of the module. I've never had the need to do such a thing, so I always thought they were constant. Nice to be corrected on that.

    I think I will use your first suggestion. It achieves what I was wanting to do.

    Thanks,
    Roger McLean
    Swinburne University
  • DHawthorneDHawthorne Posts: 4,584
    Another possibility is to populate the array in DEFINE_START rather than while initializing. You'll just need to give it a size dimension as big as the maximum size it might grow.

    But I prefer the separate device and channel array approach as well. I have found the DEVCHAN structure to be less useful than I thought it would. It's too limited in many cases.
  • annuello wrote:
    Fair enough. I guess it is possible to dynamically change the device outside of the module. I've never had the need to do such a thing, so I always thought they were constant. Nice to be corrected on that.

    I think I will use your first suggestion. It achieves what I was wanting to do.

    Thanks,
    Roger McLean
    Swinburne University


    It should be possible to change things dynamically. But read the help about REBUILD_EVENT before doing so.
Sign In or Register to comment.