Modules, Virtual Devices & DevChans..
RichieG
Posts: 16
Hey guys..
I'm starting to take a more modular approach to my programming, (was inspired by some of the AMX modules for Polycom, which included a user interface module)., and i'm running into a few problems.
Basically, what all i really want to do, is have all my modules setup so that all I have to do is pass a Touch Panel and a Device to them, and they will be controlled to my standard.
ie..
In Main.axi
DEFINE_DEVICE:
dvTP = 10001:1:1 // Main touch panel functions
dvTP_ControlledDevice = 10001:2:1 // functions for the device i want to control..
dvControlledDevice = 5001:1:1 // actual RS232 port for device
DEFINE MODULE 'My Module' Blah (dvTP_ControlledDevice, dvControlledDevice)
in MyModule:
DEFINE_MODULE 'My Module' (dvTP, dvDevice)
ok.. so that all works fine...
Now suppose I want to declare a DEV_CHAN in the Module, which references dvTP..
ie..
DEFINE_VARIABLE
DEV_CHAN Interface_Buttons[] = {{dvTP, Button_1},
{dvTP, Button_2}}
This won't compile, because it claims that dvTP isn't a Constant.
So to get around this... i've put in :
DEFINE_DEVICE:
vdTP = 33001:1:1
DEFINE_VARIABLE
DEV_CHAN Interface_Buttons[] = {{vdTP, Button_1},
{vdTP, Button_2}}
DEFINE_COMBINE
(vdTP, dvTP)
Now, this compiles fine.. But i'm not extremely happy with it..
It basically means that i'm going to have to select a range of numbers for all my Virtual Devices (say.. from 35001 - 36000), and increment the number each time i add a new Module to my libary.
This is OK, but i would prefer a more dynamic way to do it.
Any ideas?
I'm starting to take a more modular approach to my programming, (was inspired by some of the AMX modules for Polycom, which included a user interface module)., and i'm running into a few problems.
Basically, what all i really want to do, is have all my modules setup so that all I have to do is pass a Touch Panel and a Device to them, and they will be controlled to my standard.
ie..
In Main.axi
DEFINE_DEVICE:
dvTP = 10001:1:1 // Main touch panel functions
dvTP_ControlledDevice = 10001:2:1 // functions for the device i want to control..
dvControlledDevice = 5001:1:1 // actual RS232 port for device
DEFINE MODULE 'My Module' Blah (dvTP_ControlledDevice, dvControlledDevice)
in MyModule:
DEFINE_MODULE 'My Module' (dvTP, dvDevice)
ok.. so that all works fine...
Now suppose I want to declare a DEV_CHAN in the Module, which references dvTP..
ie..
DEFINE_VARIABLE
DEV_CHAN Interface_Buttons[] = {{dvTP, Button_1},
{dvTP, Button_2}}
This won't compile, because it claims that dvTP isn't a Constant.
So to get around this... i've put in :
DEFINE_DEVICE:
vdTP = 33001:1:1
DEFINE_VARIABLE
DEV_CHAN Interface_Buttons[] = {{vdTP, Button_1},
{vdTP, Button_2}}
DEFINE_COMBINE
(vdTP, dvTP)
Now, this compiles fine.. But i'm not extremely happy with it..
It basically means that i'm going to have to select a range of numbers for all my Virtual Devices (say.. from 35001 - 36000), and increment the number each time i add a new Module to my libary.
This is OK, but i would prefer a more dynamic way to do it.
Any ideas?
0
Comments
DEFINE_DEVICE
vdTP = DYNAMIC_VIRTUAL_DEVICE
The DYNAMIC_VIRTUAL_DEVICE will create a virtual device in a range from 36865 and up. Adding more devices in this way will just add up to the 36865.
Hope this helps,
Marc
Well, there's a NetLinx subtelty at work here. Only constants are allowed in variable initializers. dvTP is not since it is a module parameter. Hence the complain.
What you can do:
DEVINE VARIABLE
DEV_CHAN Interface_Buttons[2];
DEFINE_START
Interface_Buttons[1].device = dvTP:
Interface_Buttons[1].channel = Button_1;
...
Unless you use REBUILD_EVENTS, the assignation HAS to happen in define start otherwise any events on the devchans won't work.
Hope this helps
Fred
As for modules I do the same thing. One INT array for buttons one DEV array for panels, then pass it on through.
I'll try a few things, and see what works best for me..
Lately it seems like many of the duet module I am using all have their virtual devices around the 40000:1:0 range.
The autopatch module help file says "NetLinx virtual devices for Duet modules are constrained to the range 41000:1:0 to 42000:1:0"
However tech note 310 says,"32768-36863 Virtual devices Actual range used by master"
Can someone explain what is going on here? What is the max value for virtual devices and can you only use 41000 up to 42000 for defining a virtual device for the autopatch module?
41000-42000 is the range for DUET virtual devices according to the DUET module docs that I?ve read although the sample code always seems to start at 41001.
Tech note 310 was written before the birth of DUET.
If you are using a DUET module then you have to use the DUET virtual device range. A Netlinx module has to use the Netlinx virtual device range. The system treats DUET virtual devices numbers differently then Netlinx virtual device numbers.
HTH
... thatch-roofed cottages ...
It is not very "Modular" to have your devchans declared inside your module. DHawthorne is correct!!!! Everything that needs to change, and or be flexable needs to be declared in your main program and passed into your module. Like DevChans, Device List, etc... DYNAMIC_VIRTUAL_DEVICE was developed for other reasons and I personally do not believe it should be used in a module except for that orginal purpose, which I wont discuss here...
// Pick your poison...
What about
Paul