Dynamically change D:P:S
criss87
Posts: 32
Hi there!
I currently set up some classes in an university, because all the room are almost the same and are coupled together like one master room with it's slave one, i try to make just one file that autoset all matrix inputs and outputs based on the system number of all the ni3100 we got.
In the same manner, i try to change some virtual device, i tryed this in the define_start session where i set a dev variable to 33001:1:102 on system 101, 33001:1:101 on system 102 and so on.
Of course this compile correctly but is not working because i didn't specify that device in the define_device section.
Is there a way to add/modify a device d:p:s dinamically in code ?
Any help will be appreciated!
Criss
I currently set up some classes in an university, because all the room are almost the same and are coupled together like one master room with it's slave one, i try to make just one file that autoset all matrix inputs and outputs based on the system number of all the ni3100 we got.
In the same manner, i try to change some virtual device, i tryed this in the define_start session where i set a dev variable to 33001:1:102 on system 101, 33001:1:101 on system 102 and so on.
Of course this compile correctly but is not working because i didn't specify that device in the define_device section.
Is there a way to add/modify a device d:p:s dinamically in code ?
Any help will be appreciated!
Criss
0
Comments
Personally, I find it easier to make the project-specific things like device assignments an INCLUDE, and just change that and recompile.
This makes using the DEFINE_COMBINE method that Dave talked about a much faster change and much less likely to negatively affect a users ability to use the system during a switch.
It's kind of cool but I can't think of anything I'd use it for but maybe it could work for what you're trying to do.
Diagnostic print out and strings received from devices after dvDynamic_DPS changed to a different dev:
Criss,
Here's some example code that I developed to be able to switch between different projector modules and port connection types without having to resend a compiled program to the master. (I used several variables I read from a config file placed on the master to change connection ports and projector brand/type) I think you should be able to adapt this technique to suit your needs. The important thing you were probably missing with your dev variable is that you need to call REBUILD_EVENT() after changing a dev variable that is used for a module or something set at compile time.
Thanks,
Jeff Beam
DEFINE_DEVICE
dvNULL = 0:0:0
DEFINE_VARIABLE
DEV dvCMDS_PROJ_1_DEV_ARRAY[] = { dvNULL }
DEV dvIP_Projector_1_ARRAY[] = { dvNULL }
DEV dvW_IP_Projector_1_ARRAY[] = { dvNULL }
DEV dvCOMM1_DEV_ARRAY[] = { dvNULL }
DEV dvCOMM2_DEV_ARRAY[] = { dvNULL }
DEV dvCOMM3_DEV_ARRAY[] = { dvNULL }
DEV dvCOMM4_DEV_ARRAY[] = { dvNULL }
DEV dvCOMM5_DEV_ARRAY[] = { dvNULL }
(***********************************************************)
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
DEFINE_CALL 'PROJECTOR_1_OFF_1_MIN'()
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER=0'"
}
DEFINE_CALL 'PROJECTOR_1_OFF'()
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER=0'"
WAIT 50 { SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER=0'" }
}
DEFINE_CALL 'PROJECTOR_1_ON'()
{
SEND_COMMAND dvTP_ARRAY,"'PAGE-PROJ_WAIT'"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER=1'"
WAIT 50 { SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER=1'" }
SEND_COMMAND dvTP_ARRAY, "'@TXT',31,sPROJECTOR_1_NAME_TEXT,' is warming up.'"
nPROJECTOR_1_POWER_STATUS_COMP = 255
WAIT_UNTIL(nPROJECTOR_1_POWER_STATUS = 1)
{
IF(nProjPowerOnSource)
{
nSOURCE_SELECTED = nProjPowerOnSource
CALL 'PAGE_FLIP'(nProjPowerOnSource)
CALL 'SOURCE_SELECTED' (nProjPowerOnSource)
}
}
}
DEFINE_CALL 'PROJECTOR_1_INPUT'(INTEGER INP)
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'INPUT=',ITOA(INP)"
}
DEFINE_CALL 'PROJECTOR_1_VIDEO_MUTE'(INTEGER INP)
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'MUTE_VIDEO=',ITOA(INP)"
}
DEFINE_CALL 'PROJECTOR_1_VIDEO_FREEZE'(INTEGER INP)
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'FREEZE=',ITOA(INP)"
}
DEFINE_CALL 'PROJECTOR_1_VIDEO_ASPECT'(INTEGER INP)
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'ASPECT=',ITOA(INP)"
}
DEFINE_CALL 'PROJECTOR_1_VIDEO_AUTO_ADJUST'
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'AUTO_ADJUST=1'"
}
DEFINE_CALL 'POLL_PROJECTOR_1_POWER'()
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'POWER?'"
}
DEFINE_CALL 'POLL_PROJECTOR_1_LAMPTIME'()
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1], "'LAMPTIME?'"
}
(***********************************************************)
(* STARTUP CODE GOES BELOW *)
(***********************************************************)
DEFINE_START
CREATE_BUFFER dvCMDS_PROJ_1_DEV_ARRAY[1],uBUFFER_PROJECTOR_1
SET_LENGTH_STRING(uBUFFER_PROJECTOR_1,0) // CLEAR OUT ANY JUNK
CREATE_BUFFER vdvIP_CMDS_1,uBUFFER_IP_1
SET_LENGTH_STRING(uBUFFER_IP_1,0) // CLEAR OUT ANY JUNK
SWITCH(nPROJECTOR_1_IP_CONNECT)
{
CASE 2: // PROJECTOR WITH BUILT IN ETHERNET
{
SWITCH (nPROJECTOR_1_TYPE)
{
CASE 0: // DEFAULT TO EPSON IF NOT SET
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvIP_CMDS_1_1
dvIP_Projector_1_ARRAY[1] = dvIP_Projector_1
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'MODEL=',sPROJECTOR_1_MODEL"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'WARMTIME=',ITOA(nProjector_1_WarmTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'COOLTIME=',ITOA(nProjector_1_CoolTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
}
BREAK
}
CASE 1: // EPSON
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvIP_CMDS_1_1
dvIP_Projector_1_ARRAY[1] = dvIP_Projector_1
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
WAIT 5
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'MODEL=',sPROJECTOR_1_MODEL"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'WARMTIME=',ITOA(nProjector_1_WarmTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'COOLTIME=',ITOA(nProjector_1_CoolTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
}
BREAK
}
// CASE 2: // SANYO
// {
// dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_2
// dvCOMM1_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM2_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM3_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM4_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// WAIT 5
// {
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'IP_MODE=1'"
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
// }
// BREAK
// }
// CASE 3: // NEC
// {
// dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_3
// dvCOMM1_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM2_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM3_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM4_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// WAIT 5
// {
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'IP_MODE=1'"
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
// }
// BREAK
// }
// CASE 4: // HITACHI
// {
// dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_4
// dvCOMM1_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM2_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM3_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// dvCOMM4_DEV_ARRAY[1] = vdvPROJECTOR_1_DUMMY
// WAIT 5
// {
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'IP_MODE=1'"
// SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
// }
// BREAK
// }
}
IF(LENGTH_STRING(sPROJECTOR_1_IP)){ SEND_COMMAND vdvIP_CMDS_1_1,"'IP_ADDRESS=',sPROJECTOR_1_IP" }
ELSE{ SEND_COMMAND vdvIP_CMDS_1_1,"'IP_AUTO_CONNECT=0'" SEND_COMMAND vdvIP_CMDS_1_1,"'IP_AUTO_RECONNECT=0'" }
SEND_COMMAND vdvIP_CMDS_1_1,"'IP_PORT=',ITOA(nPROJECTOR_1_IP_PORT)"
SEND_COMMAND vdvIP_CMDS_1,"'IP_AUTO_CONNECT=0'"
SEND_COMMAND vdvIP_CMDS_1,"'IP_AUTO_RECONNECT=0'"
}
CASE 0: // SERIAL PORT
{
SWITCH (nPROJECTOR_1_TYPE)
{
CASE 0: // DEFAULT TO EPSON IF NOT SET
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_1
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'MODEL=',sPROJECTOR_1_MODEL"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'WARMTIME=',ITOA(nProjector_1_WarmTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'COOLTIME=',ITOA(nProjector_1_CoolTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
}
BREAK
}
CASE 1: // EPSON
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_1
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5
{
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'MODEL=',sPROJECTOR_1_MODEL"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'WARMTIME=',ITOA(nProjector_1_WarmTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'COOLTIME=',ITOA(nProjector_1_CoolTime)"
SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"
}
BREAK
}
CASE 2: // SANYO
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_2
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5 {SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"}
BREAK
}
CASE 3: // NEC
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_3
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5 {SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"}
BREAK
}
CASE 4: // HITACHI
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_4
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
dvCOMM5_DEV_ARRAY[1] = dvNULL
WAIT 5 {SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"}
BREAK
}
CASE 5: // 3M SCP
{
dvCMDS_PROJ_1_DEV_ARRAY[1] = vdvCOMMAND_PROJECTOR_5
dvIP_Projector_1_ARRAY[1] = dvNULL
dvW_IP_Projector_1_ARRAY[1] = dvNULL
dvCOMM1_DEV_ARRAY[1] = dvNULL
dvCOMM2_DEV_ARRAY[1] = dvNULL
dvCOMM3_DEV_ARRAY[1] = dvNULL
dvCOMM4_DEV_ARRAY[1] = dvNULL
dvCOMM5_DEV_ARRAY[1] = dvPHYSICAL_PORT_PROJECTOR_1
WAIT 5 {SEND_COMMAND dvCMDS_PROJ_1_DEV_ARRAY[1],"'REINIT='"}
BREAK
}
}
SEND_COMMAND vdvIP_CMDS_1_1,"'IP_AUTO_CONNECT=0'"
SEND_COMMAND vdvIP_CMDS_1_1,"'IP_AUTO_RECONNECT=0'"
SEND_COMMAND vdvIP_CMDS_1,"'IP_AUTO_CONNECT=0'"
SEND_COMMAND vdvIP_CMDS_1,"'IP_AUTO_RECONNECT=0'"
}
}
REBUILD_EVENT()
DEFINE_MODULE 'Epson_Projector_Comm' COMM1_1(vdvCOMMAND_PROJECTOR_1,dvCOMM1_DEV_ARRAY[1])
DEFINE_MODULE 'Sanyo_Projector_Comm' COMM2_1(vdvCOMMAND_PROJECTOR_2,dvCOMM2_DEV_ARRAY[1])
DEFINE_MODULE 'NEC_Projector_Comm' COMM3_1(vdvCOMMAND_PROJECTOR_3,dvCOMM3_DEV_ARRAY[1])
DEFINE_MODULE 'Hitachi_Projector_Comm' COMM4_1(vdvCOMMAND_PROJECTOR_4,dvCOMM4_DEV_ARRAY[1])
DEFINE_MODULE '3M_SCP_Projector_Comm' COMM5_1(vdvCOMMAND_PROJECTOR_5,dvCOMM5_DEV_ARRAY[1])
DEFINE_MODULE 'IP_Wrapper_Serial_Comm_Module' IP_COMM1(vdvIP_CMDS_1,vdvIP_COMM_1_MOD_DEV,dvW_IP_Projector_1_ARRAY[1])
DEFINE_MODULE 'Epson_IP_Projector_Comm' IP_COMM1_1(vdvIP_CMDS_1_1,dvIP_Projector_1_ARRAY[1])
#IF_DEFINED
#IF_NOT_DEFINED
QUESTION: Is there a way to add/modify a device d:p:s dinamically in code ?
ANSWER: Yes. You can create a variable DEV, set the D:P:S of the variable device at runtime, and then use the REBUILD_EVENT() function to rebuild the event table.
Step #1: Declare your variable device.
Step #2: In DEFINE_START check what the system number is of the master running the code to determine what virtual D:P:S to assignto the variable device. Assign the variable device a D:P:S and immediately rebuild the Event Table.
Please let me know if this was what you were after?
You can pass d.p.s info across masters in command strings and create event tables for devices on other systems without declaring them locally. Reading the device info from a database then populating the device arrays dynamically during runtime works too.