private bool ConnectToValidator(int attempts, int interval) { // setup the timer reconnectionTimer.Interval = interval * 1000; // for ms // run for number of attempts specified for (int i = 0; i < attempts; i++) { // reset timer reconnectionTimer.Enabled = true; // close com port in case it was open Hopper.SSPComms.CloseComPort(); // turn encryption off for first stage Hopper.CommandStructure.EncryptionStatus = false; // if the key negotiation is successful then set the rest up if (Hopper.OpenComPort(textBox1) && Hopper.NegotiateKeys(textBox1) == true) { Hopper.CommandStructure.EncryptionStatus = true; // now encrypting // find the max protocol version this validator supports byte maxPVersion = FindMaxProtocolVersion(); if (maxPVersion >= 6) { Hopper.SetProtocolVersion(maxPVersion, textBox1); } else { MessageBox.Show("This program does not support validators under protocol 6!", "ERROR"); return(false); } // get info from the validator and store useful vars Hopper.SetupRequest(textBox1); // check unit is valid type if (!IsUnitValid(Hopper.UnitType)) { MessageBox.Show("Unsupported type shown by SMART Hopper, this SDK supports the SMART Hopper only"); Application.Exit(); return(false); } // inhibits, this sets which channels can receive coins Hopper.SetInhibits(textBox1); // enable, this allows the validator to operate Hopper.EnableValidator(textBox1); return(true); } while (reconnectionTimer.Enabled) { Application.DoEvents(); Thread.Sleep(1); // Yield to free up CPU } } return(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; }