dynamic device passed to module
jgreer9514
Posts: 23
I have 3 display modules where I am trying to choose one of them to use in the main program. All 3 modules are loaded in the program. Each module has a virtual device passed into it rather than the actual serial port. I am trying to reassign the device Id passed into the module after the NI has booted. What I am finding is that since the Define_Start has already run that by simply re-assigning the device id from vdvDisplay1(33100:1:0) = dvDisplay(5001:1:0) after boot up that the module is not going to get the update.
I have used Define_Combine but it has a drawback, you cannot see what is being sent and received over the actual serial port. The virtual simply echos what you sent. Not what I'm going for.
The only way I think I can get this to work is value to a persistent variable and do an IF/Else when the modules are being instantiated on startup. So after the uer selects the display type it would then force a reboot.
Is there another way?
I have used Define_Combine but it has a drawback, you cannot see what is being sent and received over the actual serial port. The virtual simply echos what you sent. Not what I'm going for.
The only way I think I can get this to work is value to a persistent variable and do an IF/Else when the modules are being instantiated on startup. So after the uer selects the display type it would then force a reboot.
Is there another way?
0
Comments
Hmm..
Please post the code. That might help to diagnose the problem.
dvDisplay = dvProjector1
SEND_COMMAND vdvDEVICE,'REINIT'.
If it is your module? Program it to use the REINIT command. Just put all of the code that is in the online event and place it in the data_event command handle. So if find_string(data.text,'REINIT',1) run the code that was in the online event.
See the second post in this thread: http://www.amxforums.com/showthread.php?t=6123
I use this same method to choose between modules. Where two rooms are almost identical except for different displays for example, it often makes sense to load identical code to the master and determine which module/s to make active at runtime based on a config file/IP address/data from a GPS attached to the master/whatever. Generally, the memory/performance penalties associated with this scenario do not pose a problem.
The way I do it is as follows:
* Set dev variables passed to the modules to 0:0:0 in define_variable section
* Assign real devs to them at runtime if the module is to be made active
* Have a timeline in the module which triggers a rebuild_event() and any necessary online event code when the value of the dev variables change. The rebuild_event() statement is critical to force the module to see events which occur on the devices passed into the module as parameters after changing their value.
Won't work with AMX modules obviously, as I doubt they support this form of dynamic assignment for the module vdev. You may be able to assign a real vdev to them and just update the physical device at runtime and do a send_command 'REINIT', but I don't use AMX modules on the whole and haven't tried it...
All modules I have coded, each has an Initilization virtual command to resetup the port settings.
I guess my question is once a module is instantiated is it possible for the Data event section to retrigured when assigning a new device?
Here is an example of what I'm trying to do.
DEFINE_DEVICE
dvDisplay = 5001:1:0
vdvDisplay1 = 33100:1:0
vdvDisplay2 = 33101:1:0
vdvDisplay3 = 33102:1:0
DEFINE_START
DEFINE_MODULE 'NEC LCD' NEC (vdvDisplay1, dvTP_NecArray, vdvNecInterface)
DEFINE_MODULE 'LG' LG2 (vdvDisplay2, dvTP_LgArray, vdvLgInterface)
DEFINE_MODULE 'Philips' PHILIPS (vdvDisplay3, dvTP_PhilipsArray, vdvPhilipsInterface)
// button event tried within the module the device defined in the module for testing purposes
IF(button press for NEC)
{ vdvDisplay1= dvDisplay
SEND_STRING vdvNecInterface, "'INITIALIZE'"
}
I tried this inside the module for a test with a rebuild events and it still did not work. The Data Event of the module continued to stay the vdvDisplay1 device.
I believe Rebuild_events() only updates the button events which would just be the touch panel array, not the actual device.
The only route I can see if passing the actual port into each module and having a boolean value that essentially disables/enables the entire module. I could atleast send a virtual command to turn on a module or turn it off.
You already defined vdvDisplay1=33100:1:0 in the define_device section. vdvDisplay1 is now not a variable. You should do this
DEFINE_VARIABLE
dev vdvDisplay1 , vdvDisplay2 , vdvDisplay3
DEFINE_START
vdvDisplay1 = 33100:1:0
vdvDisplay2 = 33101:1:0
vdvDisplay3 = 33102:1:0
Then....
IF(button press for NEC)
{ vdvDisplay1= dvDisplay
SEND_STRING vdvNecInterface, "'INITIALIZE'"
}
I had hundreds of Elmo Cameras I needed to control but I did not want to use 100's of modules for all of the cameras. So this is how I did it.
I am still getting an assignment error on the variable but it looks like it is working. I am having a problem with my queue and buffers that is compounding trying to solve this. Save that headache for another day. Turning off the module approach I mentioned earlier is working without impacting the queues. I think I'll pick this up another day.
DEFINE_DEVICE
dvDisplay = 5001:1:0
vdvNoDevice = 33100:1:0
DEFINE_VARIABLE
DEV vdvDisplay1, vdvDisplay2, vdvDisplay3
DEFINE_START
vdvDisplay1 = vdvNoDevice
vdvDisplay2 = vdvNoDevice
vdvDisplay3 = vdvNoDevice
DEFINE_MODULE 'NEC LCD' NEC (vdvDisplay1, dvTP_NecArray, vdvNecInterface)
DEFINE_MODULE 'LG' LG2 (vdvDisplay2, dvTP_LgArray, vdvLgInterface)
DEFINE_MODULE 'Philips' PHILIPS (vdvDisplay3, dvTP_PhilipsArray, vdvPhilipsInterface)
// button event tried within the module the device defined in the module for testing purposes
IF(button press for NEC)
{ vdvDisplay1= dvDisplay
SEND_STRING vdvNecInterface, "'INITIALIZE'"
In the device notifications I can see the port 5001:1:0 being re-initalized with port speeds. I see the commands being sent out and the response coming back. Just my queue is not picking up the response back, ughhh.... Something is out of sync.
Not sure where your queue operates within your code. Be aware that rebuild_event() operates with limited scope - calling rebuild_event() within a module will not refresh the event table entries for other modules or your main program. You'll need to call rebuild_event() in multiple places if there is more than one portion of the program referencing the device that is being updated.
This is the general scenario I use within my modules to achieve what you're trying to do (the waits probably aren't necessary in most situations):
Just a thought about why I wasn't getting any feedback. I am using Create_Buffer under the define start of the module and use the buffer to tie what was sent/received. By using the INITIALIZE virtual command I cannot re-create the buffers to the new devices. Have you had this problem?
That rings bells I just rewrote my feedback parsing routine to provide the functionality of the master managed buffer to get around it. I assume I'm paying a performance penalty, but it hasn't been an issue so far.