PDA

View Full Version : Background Script/Sequence modified to execute when vixen is running 24/7



tom4writer
11-30-2011, 11:18 AM
I had borrowed some the the background script code I found in the forums. It worked as long as I restarted vixen once a day. My show computer is running 24/7 with Vixen also running. So the problem I found is that the sample scripts store the date & time in a variable. Once the day changes at midnight the inner while loop will never fire again since the start/stop time contains the date of when Vixen was last started.

Here's my modified code. Let me know if you spot any issues



void Start() {

Off (All);

// started with the basic samples from DIYC. Modifed to just look at the time and ignore the date.
// Since this is running 24/7 after midnight the start and stop variable contaied a date from the previous day
// and the while loop wouldn't fire any more without restarting vixen





TimeSpan now = DateTime.Now.TimeOfDay; // define variable and load it with current time (No Date)

TimeSpan start = new TimeSpan(16, 30, 00); // Start time of Evening
TimeSpan end = new TimeSpan(23, 45, 00); // End Time of Evening

TimeSpan start2 = new TimeSpan(5, 30, 00); // Start time of Morning
TimeSpan end2 = new TimeSpan(6, 45, 00); // End Time of Morning

// Original code
// DateTime now = DateTime.Now; //get the current Date & Time
// The DateTime constructor goes (YYYY, MM, DD, HH, MM, SS)
// DateTime start = new DateTime(now.Year, now.Month, now.Day, 16, 30, 00);
// DateTime end = new DateTime(now.Year, now.Month, now.Day, 23, 45, 00);
// Added a second set of date and times (Morning)
// DateTime Mornstart = new DateTime(now.Year, now.Month, now.Day, 5, 30, 00);
// DateTime Mornend = new DateTime(now.Year, now.Month, now.Day, 7, 00, 00);


// Define the collection variables
ChannelCollection MiniTreesRed;
ChannelCollection MiniTreesGreen;
ChannelCollection MiniTreesWhite;
ChannelCollection MiniTreesRedR;
ChannelCollection MiniTreesGreenR;
ChannelCollection MiniTreesWhiteR;
ChannelCollection RoofReds;
ChannelCollection RoofGreens;
ChannelCollection RoofWhites;
ChannelCollection MegaTreeAll;


// Group items into collection
MiniTreesWhite = Channels(Tree1_White,Tree2_White,Tree3_White,Tree4 _White,Tree5_White,Tree6_White,Tree7_White,Tree8_W hite);
MiniTreesRed = Channels(Tree1_Red,Tree2_Red,Tree3_Red,Tree4_Red,T ree5_Red,Tree6_Red,Tree7_Red,Tree8_Red);
MiniTreesGreen = Channels(Tree1_Green,Tree2_Green,Tree3_Green,Tree4 _Green,Tree5_Green,Tree6_Green,Tree7_Green,Tree8_G reen);
//Reversed Order to chase backwards - ** Doesn't work as expected **
MiniTreesWhiteR = Channels(Tree8_White,Tree7_White,Tree6_White,Tree5 _White,Tree4_White,Tree3_White,Tree2_White,Tree1_W hite);
MiniTreesRedR = Channels(Tree8_Red,Tree7_Red,Tree6_Red,Tree5_Red,T ree4_Red,Tree3_Red,Tree2_Red,Tree1_Red);
MiniTreesGreenR = Channels(Tree8_Green,Tree7_Green,Tree6_Green,Tree5 _Green,Tree4_Green,Tree3_Green,Tree2_Green,Tree1_G reen);


RoofReds = Channels(MstrBed_Roof_Red, UpBedRoof_Red, GarageRoof_Red);
RoofGreens = Channels(MstrBed_Roof_Green, UpBedRoof_Green, GarageRoof_Green);
RoofWhites = Channels(MstrBed_Roof_White, UpBedRoof_White, GarageRoof_white);

MegaTreeAll = Channels(MT0_White, MT22_Red, MT45_White, MT67_Green, MT90_White, MT112_Red, MT135_White, MT157_Green, MT180_White, MT202_Red, MT225_White, MT247_Green, MT270_White, MT292_Red, MT315_White, MT337_Green);

while(true) { // Loop forever - This keep the script executing

while((now.CompareTo(start) >= 0 && now.CompareTo(end) <= 0) || (now.CompareTo(start2) >= 0 && now.CompareTo(end2) <= 0)) // only turn on lights between the star/stop times
{

now = DateTime.Now.TimeOfDay; //update the current time


// run around the mega tree, turning on the mini trees & roof lines to match the color (except white)
On (Channels (MiniTreesWhite), At(85));
On (Channels (MT0_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesRed), At(85));
On (Channels (RoofReds), At(85));
On (Channels (MT22_Red), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT45_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesGreen), At(85));
On (Channels (RoofGreens), At(85));
On (Channels (MT67_Green), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT90_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesRed), At(85));
On (Channels (RoofReds), At(85));
On (Channels (MT112_Red), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT135_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesGreen), At(85));
On (Channels (RoofGreens), At(85));
On (Channels (MT157_Green), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT180_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesRed), At(85));
On (Channels (RoofReds), At(85));
On (Channels (MT202_Red), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT225_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesGreen), At(85));
On (Channels (RoofGreens), At(85));
On (Channels (MT247_Green), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT270_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesRed), At(85));
On (Channels (RoofReds), At(85));
On (Channels (MT292_Red), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesWhite ), At(85));
On (Channels (MT315_White), 0, 100, For(500).Milliseconds, Wait);
Off (All);
On (Channels (MiniTreesGreen), At(85));
On (Channels (RoofGreens), At(85));
On (Channels (MT337_Green), 0, 100, For(1000).Milliseconds, Wait);
Off (All);


Chase(MiniTreesWhite, Over(1000).Milliseconds,Wait);
Chase(MiniTreesRed, Over(1000).Milliseconds,Wait);
Chase(MiniTreesGreen, Over(1000).Milliseconds,Wait);
Off (All);

Chase(MegaTreeAll, Over(1000).Milliseconds,Wait);
Chase(MegaTreeAll, Over(1000).Milliseconds,Wait);
Chase(MegaTreeAll, Over(1000).Milliseconds,Wait);
Chase(MegaTreeAll, Over(1000).Milliseconds,Wait);
Chase(MegaTreeAll, Over(1000).Milliseconds,Wait);
Off (All);


// this was supposed to chase back and forth but it all runs the same direction
Chase(MiniTreesWhite, Over(1000).Milliseconds,Wait);
Chase(MiniTreesWhiteR, Over(1000).Milliseconds,Wait);
Chase(MiniTreesWhite, Over(1000).Milliseconds,Wait);
Chase(MiniTreesWhiteR, Over(1000).Milliseconds,Wait);
Off (All);

Chase(MiniTreesRed, Over(1000).Milliseconds,Wait);
Chase(MiniTreesRedR, Over(1000).Milliseconds,Wait);
Chase(MiniTreesRed, Over(1000).Milliseconds,Wait);
Chase(MiniTreesRedR, Over(1000).Milliseconds,Wait);
Off (All);

Chase(MiniTreesGreen, Over(1000).Milliseconds,Wait);
Chase(MiniTreesGreenR, Over(1000).Milliseconds,Wait);
Chase(MiniTreesGreen, Over(1000).Milliseconds,Wait);
Chase(MiniTreesGreenR, Over(1000).Milliseconds,Wait);


Off (All);


// Ramp(RoofGreens, 100,0, Over(10).Seconds);
// Ramp(RoofGreens, 0,100,Over(10.Seconds),Wait);

//On (ChannelRange (38,1), 0, 100, For(500).Milliseconds, Wait);
//Off (All);
//On (ChannelRange (39,1), 0, 100, For(500).Milliseconds, Wait);
//Off (All);


} // end loop of start/stop times

Off(MiniTreesWhite, For(60).Seconds,Wait); // wait 60 seconds before looping again
Off (All);


} // while true loop


Off (All);


} // Start

Aurbo99
12-02-2011, 10:40 PM
Here is my script, it runs 24/7 and will correctly shut down and start when programmed.

It has run for me without fail for the last 4 years..

As a bonus.. I included a working mod to allow you to run a LedTriks script which ran last year and shows no sign of stopping so far.



void Start()
{
System.Threading.Thread Triks = new System.Threading.Thread(LTC);

DateTime now = DateTime.Now; //get the current time
//We only want the background script to turn on while the current time is
//between 10:40pm and 5:25pm the next day
//The DateTime constructor goes (YYYY, MM, DD, HH, MM, SS)
DateTime start = new DateTime(now.Year, now.Month, now.Day, 22, 11, 00);
DateTime end = new DateTime(now.Year, now.Month, now.Day, 17, 25, 00);

while (now.CompareTo(start) >= 0 && now.CompareTo(end) <= 0)


Off(All);
// Declares variables
// **** Channel Specific ****

ChannelCollection RoofRed;
ChannelCollection RoofBlue;
ChannelCollection MiniTreeBlue;
ChannelCollection MiniTreeYellow;
ChannelCollection MiniTreeRed;
ChannelCollection MiniTreeGreen;
ChannelCollection MegaToppers;
ChannelCollection MegaRed;
ChannelCollection MegaBlue;
ChannelCollection MegaGreen;
ChannelCollection MegaYellow;
ChannelCollection Canes_A;
ChannelCollection Canes_B;
ChannelCollection HJ;
// Channel specific - Selected what channels to be in this group


RoofRed = Channels(Eves_A_Red,Eves_B_Red,Eves_C_Red,Eves_D_R ed,Eves_E_Red,Eves_F_Red,Eves_G_Red);
RoofBlue = Channels(Eves_A_Blue,Eves_B_Blue,Eves_C_Blue,Eves_ D_Blue,Eves_E_Blue,Eves_F_Blue,Eves_G_Blue);
MiniTreeBlue = Channels(Mini1_Blue,Mini2_Blue,Mini3_Blue,Mini4_Bl ue,Mini5_Blue,Mini6_Blue,Mini7_Blue,Mini8_Blue,Min i9_Blue,Mini10_Blue,Mini11_Blue,Mini12_Blue);
MiniTreeYellow = Channels(Mini1_Yellow,Mini2_Yellow,Mini3_Yellow,Mi ni4_Yellow,Mini5_Yellow,Mini6_Yellow,Mini7_Yellow, Mini8_Yellow,Mini9_Yellow,Mini10_Yellow,Mini11_Yel low,Mini12_Yellow);
MiniTreeRed = Channels(Mini1_Red,Mini2_Red,Mini3_Red,Mini4_Red,M ini5_Red,Mini6_Red,Mini7_Red,Mini8_Red,Mini9_Red,M ini10_Red,Mini11_Red,Mini12_Red);
MiniTreeGreen = Channels(Mini1_Green,Mini2_Green,Mini3_Green,Mini4 _Green,Mini5_Green,Mini6_Green,Mini7_Green,Mini8_G reen,Mini9_Green,Mini10_Green,Mini11_Green,Mini12_ Green);
MegaToppers = Channels(TreeTopper_White);
MegaRed= Channels(Mega_A_Red,Mega_B_Red,Mega_C_Red,Mega_D_R ed,Mega_E_Red,Mega_F_Red,Mega_G_Red,Mega_H_Red);
MegaBlue = Channels(Mega_A_Blue,Mega_B_Blue,Mega_C_Blue,Mega_ D_Blue,Mega_E_Blue,Mega_F_Blue,Mega_G_Blue,Mega_H_ Blue);
MegaGreen = Channels(Mega_A_Green,Mega_B_Green,Mega_C_Green,Me ga_D_Green,Mega_E_Green,Mega_F_Green,Mega_G_Green, Mega_H_Green);
MegaYellow = Channels(Mega_A_Yellow,Mega_B_Yellow,Mega_C_Yellow ,Mega_D_Yellow,Mega_E_Yellow,Mega_F_Yellow,Mega_G_ Yellow,Mega_H_Yellow);
Canes_A = Channels(CandyCane_A,CandyCane_C,CandyCane_E,Candy Cane_G,CandyCane_I,CandyCane_K,CandyCane_M,CandyCa ne_O,CandyCane_Q);
Canes_B = Channels(CandyCane_B,CandyCane_D,CandyCane_F,Candy Cane_H,CandyCane_J,CandyCane_L,CandyCane_N,CandyCa ne_P,CandyCane_R);
HJ = Channels(Wreath_A);

while(true) {

Triks.Start();
On(HJ, At(100));
On(MegaToppers, At(50));
On(RoofBlue, At(40));
// Ramp from 0-100% over the span of ten second and wait for it to complete.
Ramp(MegaBlue, 0, 30, Over(8).Seconds, Wait);
Ramp(MegaBlue, 30, 0, Over(8).Seconds, Wait);
Off(MegaBlue);
Ramp(MiniTreeRed, 0, 30, Over(8).Seconds, Wait);
Ramp(MiniTreeRed, 30, 0, Over(8).Seconds, Wait);
Off(MiniTreeRed);
Ramp(MiniTreeGreen, 0, 30, Over(8).Seconds, Wait);
Ramp(MiniTreeGreen, 30, 0, Over(8).Seconds, Wait);
Off(MiniTreeGreen);
Ramp(MiniTreeYellow, 0, 30, Over(8).Seconds, Wait);
Ramp(MiniTreeYellow, 30, 0, Over(8).Seconds, Wait);
Off(MiniTreeYellow);
Ramp(MiniTreeBlue, 0, 30, Over(8).Seconds, Wait);
Ramp(MiniTreeBlue, 30, 0, Over(8).Seconds, Wait);
Off(MiniTreeBlue);
Ramp(Canes_A, 0, 50, Over(8).Seconds, Wait);
Ramp(Canes_A, 50, 0, Over(8).Seconds, Wait);
Ramp(Canes_B, 0, 50, Over(8).Seconds, Wait);
Ramp(Canes_B, 50, 0, Over(8).Seconds, Wait);
}
Triks.Start();
now=DateTime.Now; //update the current time

}

void LTC()
{

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "C:\\LTC\\ltc.exe";
proc.StartInfo.Arguments = "C:\\LTC\\background.txt";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
}