Module Creation Questions
Prodigal
Posts: 90
Hi there guys,
I'm trying to make my first modules, and I'm getting some troubles on doing them, since the info on Studio ain't that helpfull.
The situation is a module to a Box to TV Cable. The control is threw IR, altho it has a particularity of having different IR's for the same function. I have the logic already of how to deal with them, but since it's a bit complex and this project has like 7 Box's I wanted to make it on a module to keep it simpler.
So on the main code I have:
DEFINE_DEVICE
dev_PowerBox1 =5001:5:1
dev_PowerBox2 =5001:6:1
dev_PowerBox3 =5001:7:1
dev_PowerBox4 =5001:8:1
dev_PowerBox5 =5001:9:1
dev_PowerBox6 =5001:10:1
dev_PowerBox7 =5001:11:1
//TP'S
dev_TP_Controlo_Pbox1 = 10001:2:1
dev_TP_Controlo_Pbox2 = 10001:3:1
dev_TP_Crise_Pbox1 = 10002:2:1
dev_TP_Crise_Pbox2 = 10002:3:1
dev_TP_Formacao_Pbox1 = 10003:2:1
dev_TP_Formacao_Pbox2 = 10003:3:1
dev_TP_Formacao_Pbox3 = 10003:4:1
...
//Define_Module 'TVcaboBox' Name(dev touchpannel, dev Box, int Functions)
DEFINE_MODULE 'TVcaboBox' Box1(dev_TP_Control_Pbox1, dev_PowerBox1 , aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box2(dev_TP_Control_Pbox2, dev_PowerBox2, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box3(dev_TP_Crisis_Pbox1, dev_PowerBox3, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box4(dev_TP_Crisis_Pbox2, dev_PowerBox4, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box5(dev_TP_Form_Pbox1, dev_PowerBox5, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box6(dev_TP_Form_Pbox2, dev_PowerBox6, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box7(dev_TP_Form_Pbox3, dev_PowerBox7, aBtn_PB)
Inside the Module:
MODULE_NAME='TVcaboBox'(
dev dvTP,
dev dvBox,
integer Buttons[]
)
....
button_event[dvTP,Buttons] //Power Box Button Push
{
push:
{
integer index
index= get_last(Buttons)
SET_PULSE_TIME (pulse_time)
SWITCH (Buttons)
{
case 1: //Button 1
{
SWITCH(IR_DB_Counter_PB)
{
case 1: //Last IR file set was from Data Base A
{
pulse[dvBox, IR_PowerBox_1_B]
IR_DB_Counter_PB=2
}
case 2: //Last IR file set was from Data Base B
{
pulse[dvBox, IR_PowerBox_1_A]
IR_DB_Counter_PB=1
}
}
}
.....
So what I'm trying to do is to Pulse Each time from a Diferent IR data base.
Problem I'm finding:
-The controller doens't send any IR codes at all.
-The variable IR_DB_Counter_PB (wich keeps track of the DB thas was last used) is allways equal do 1, it never changes between 1 and 2 (A and , Each time a button is pressed it's allways on the value = 1. Is it cause the module doesn't save the values for the different Module calling instances?
Kinda stuck, and Studio Help file ain't helping that much :-\
I'm trying to make my first modules, and I'm getting some troubles on doing them, since the info on Studio ain't that helpfull.
The situation is a module to a Box to TV Cable. The control is threw IR, altho it has a particularity of having different IR's for the same function. I have the logic already of how to deal with them, but since it's a bit complex and this project has like 7 Box's I wanted to make it on a module to keep it simpler.
So on the main code I have:
DEFINE_DEVICE
dev_PowerBox1 =5001:5:1
dev_PowerBox2 =5001:6:1
dev_PowerBox3 =5001:7:1
dev_PowerBox4 =5001:8:1
dev_PowerBox5 =5001:9:1
dev_PowerBox6 =5001:10:1
dev_PowerBox7 =5001:11:1
//TP'S
dev_TP_Controlo_Pbox1 = 10001:2:1
dev_TP_Controlo_Pbox2 = 10001:3:1
dev_TP_Crise_Pbox1 = 10002:2:1
dev_TP_Crise_Pbox2 = 10002:3:1
dev_TP_Formacao_Pbox1 = 10003:2:1
dev_TP_Formacao_Pbox2 = 10003:3:1
dev_TP_Formacao_Pbox3 = 10003:4:1
...
//Define_Module 'TVcaboBox' Name(dev touchpannel, dev Box, int Functions)
DEFINE_MODULE 'TVcaboBox' Box1(dev_TP_Control_Pbox1, dev_PowerBox1 , aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box2(dev_TP_Control_Pbox2, dev_PowerBox2, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box3(dev_TP_Crisis_Pbox1, dev_PowerBox3, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box4(dev_TP_Crisis_Pbox2, dev_PowerBox4, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box5(dev_TP_Form_Pbox1, dev_PowerBox5, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box6(dev_TP_Form_Pbox2, dev_PowerBox6, aBtn_PB)
DEFINE_MODULE 'TVcaboBox' Box7(dev_TP_Form_Pbox3, dev_PowerBox7, aBtn_PB)
Inside the Module:
MODULE_NAME='TVcaboBox'(
dev dvTP,
dev dvBox,
integer Buttons[]
)
....
button_event[dvTP,Buttons] //Power Box Button Push
{
push:
{
integer index
index= get_last(Buttons)
SET_PULSE_TIME (pulse_time)
SWITCH (Buttons)
{
case 1: //Button 1
{
SWITCH(IR_DB_Counter_PB)
{
case 1: //Last IR file set was from Data Base A
{
pulse[dvBox, IR_PowerBox_1_B]
IR_DB_Counter_PB=2
}
case 2: //Last IR file set was from Data Base B
{
pulse[dvBox, IR_PowerBox_1_A]
IR_DB_Counter_PB=1
}
}
}
.....
So what I'm trying to do is to Pulse Each time from a Diferent IR data base.
Problem I'm finding:
-The controller doens't send any IR codes at all.
-The variable IR_DB_Counter_PB (wich keeps track of the DB thas was last used) is allways equal do 1, it never changes between 1 and 2 (A and , Each time a button is pressed it's allways on the value = 1. Is it cause the module doesn't save the values for the different Module calling instances?
Kinda stuck, and Studio Help file ain't helping that much :-\
0
Comments
Try using select/active instead
Yes you can stack switch/case statements. What does your integer array look like?
BUTTON_EVENT[dvTP,Buttons] //Power Box Button Push
{
push:
{
STACK_VAR INTEGER index
index= get_last(Buttons)
SET_PULSE_TIME (1)
SWITCH (INDEX) // DEPENDS ON IF YOU NEED THE POSITION OR THE ACTUAL BUTTON NUMBER
// IN YOUR SWITCH YOU HAD BUTTON
{
case 1: //Button 1
{
SWITCH(IR_DB_Counter_PB)
{
case 1: //Last IR file set was from Data Base A
{
pulse[dvBox, IR_PowerBox_1_B]
IR_DB_Counter_PB=2
}
case 2: //Last IR file set was from Data Base B
{
pulse[dvBox, IR_PowerBox_1_A]
IR_DB_Counter_PB=1
}
}
}
}
}
it really depends on what you need.
Tech Note 271 - Module Example
Tech Note 375 - How to Write Your Own Netlinx Modules
Thanks for the replies!
On my code the only I need is the position of the array pressed. But that part works fine.
By this piece of code, each time you pressed the same button, lets say the button on position [1] of the array, it woul send 1st from the DataBase A and after from DataBase B.
This code works on the main program, just doens't work on the module.
I can get the report on telnet saying that it is being pushed indeed, but allways the same DataBase. And the IR isn't being emitted.
My question was really to know if each instance of the module saves his variables values.
Or if each time I press a button, the module will allways start from scratch, and as such, the variable that decides between DataBase A, or DataBase B would allways be the Default Value = 1.