// The main program loop, this is to control the validator, it polls at // a value set in this class (pollTimer). void MainLoop() { btnRun.Enabled = false; textBox1.Clear(); Hopper.CommandStructure.ComPort = Global.ComPort; Hopper.CommandStructure.SSPAddress = Global.SSPAddress; Hopper.CommandStructure.Timeout = 2000; Hopper.CommandStructure.RetryLevel = 3; // First connect to the validator if (ConnectToValidator(10, 3)) { btnHalt.Enabled = true; Running = true; textBox1.AppendText("\r\nPoll Loop\r\n" + "*********************************\r\n"); } // This loop won't run until the validator is connected while (Running) { // poll the validator if (!Hopper.DoPoll(textBox1)) { // If the poll fails, try to reconnect textBox1.AppendText("Attempting to reconnect...\r\n"); if (!ConnectToValidator(10, 3)) { // If it fails after 5 attempts, exit the loop Running = false; } } // tick the timer timer1.Enabled = true; // update form UpdateUI(); // setup dynamic elements of win form once if (!bFormSetup) { SetupFormLayout(); bFormSetup = true; } while (timer1.Enabled) { Application.DoEvents(); Thread.Sleep(1); // Yield to free up CPU } } //close com port Hopper.SSPComms.CloseComPort(); btnRun.Enabled = true; btnHalt.Enabled = false; }
// The main program loop, this is to control the validator, it polls at // a value set in this class (pollTimer). public void MainLoop() { btnRun.Enabled = false; btnHalt.Enabled = true; Thread tNV11Rec = null, tHopRec = null; // Connect to the validators ConnectToNV11(textBox1); ConnectToHopper(textBox1); NV11.EnableValidator(); Hopper.EnableValidator(); // While application is still active while (!CHelpers.Shutdown) { // Setup form layout on first run if (!FormSetup) { SetupFormLayout(); FormSetup = true; } // If the hopper is supposed to be running but the poll fails if (hopperRunning && !Hopper.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to SMART Hopper\r\n"); // If the other unit isn't running, refresh the port by closing it if (!NV11Running) { LibraryHandler.ClosePort(); } hopperRunning = false; tHopRec = new Thread(() => ReconnectHopper()); tHopRec.Start(); } // If the NV11 is supposed to be running but the poll fails if (NV11Running && !NV11.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to NV11\r\n"); // If the other unit isn't running, refresh the port by closing it if (!hopperRunning) { LibraryHandler.ClosePort(); } NV11Running = false; tNV11Rec = new Thread(() => ReconnectNV11()); tNV11Rec.Start(); } UpdateUI(); timer1.Enabled = true; while (timer1.Enabled) { Application.DoEvents(); Thread.Sleep(1); // Yield so windows can schedule other threads to run } } //close com port LibraryHandler.ClosePort(); btnRun.Enabled = true; btnHalt.Enabled = false; }
// The main program loop, this is to control the validator, it polls at // a value set in this class (pollTimer). public void MainLoop() { this.Enabled = true; btnRun.Enabled = false; btnHalt.Enabled = true; // Connect to the validators (non-threaded for initial connect) ConnectToSMARTPayout(textBox1); ConnectToHopper(textBox1); // Enable validators Payout.EnableValidator(); Hopper.EnableValidator(); // While app active while (!CHelpers.Shutdown) { // Setup form layout on first run if (!FormSetup) { SetupFormLayout(); FormSetup = true; } // If the Hopper is supposed to be running but the poll fails if (hopperRunning && !hopperConnecting && !Hopper.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to SMART Hopper\r\n"); // If the other unit isn't running, refresh the port by closing it if (!payoutRunning) { LibraryHandler.ClosePort(); } hopperRunning = false; // Create and start a reconnection thread, this allows this loop to continue executing // and polling the other validator tHopRec = new Thread(() => ReconnectHopper()); tHopRec.Start(); } // Same as above but for the Payout if (payoutRunning && !payoutConnecting && !Payout.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to SMART Payout\r\n"); // If the other unit isn't running, refresh the port by closing it if (!hopperRunning) { LibraryHandler.ClosePort(); } payoutRunning = false; // Create and start a reconnection thread, this allows this loop to continue executing // and polling the other validator tSPRec = new Thread(() => ReconnectPayout()); tSPRec.Start(); } UpdateUI(); timer1.Enabled = true; while (timer1.Enabled) { Application.DoEvents(); } } btnRun.Enabled = true; btnHalt.Enabled = false; }
// The main program loop, this is to control the validator, it polls at // a value set in this class (pollTimer). public void MainLoop() { Enabled = true; // Connect to the validators ConnectToNoteValidator(textBox1); ConnectToHopper(textBox1); // Enable the validators Validator.EnableValidator(textBox1); Hopper.EnableValidator(textBox1); // While either one is still running while (!CHelpers.Shutdown) { // Setup form layout on first run if (!FormSetup) { SetupFormLayout(); FormSetup = true; } // If the hopper is supposed to be running but the poll fails if (hopperRunning && !Hopper.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to SMART Hopper\r\n"); hopperRunning = false; // If the other device has also stopped, close the port if (!validatorRunning) { LibraryHandler.ClosePort(); } // Create a reconnection thread, this allows this loop to continue executing // and polling the other validator Thread t = new Thread(ReconnectHopper); t.Start(); } // If the validator is supposed to be running but the poll fails if (validatorRunning && !Validator.DoPoll(textBox1)) { textBox1.AppendText("Lost connection to note validator\r\n"); validatorRunning = false; // If the other device has also stopped, close the port if (!hopperRunning) { LibraryHandler.ClosePort(); } // Create a reconnection thread, this allows this loop to continue executing // and polling the other validator Thread t = new Thread(ReconnectValidator); t.Start(); } UpdateUI(); timer1.Enabled = true; while (timer1.Enabled) { Application.DoEvents(); } } LibraryHandler.ClosePort(); btnRun.Enabled = true; btnHalt.Enabled = false; }