// This function opens the com port and attempts to connect with the validator. It then negotiates // the keys for encryption and performs some other setup commands. private bool ConnectToValidator(int attempts, int interval) { // setup timer reconnectionTimer.Interval = interval * 1000; // ms // run for number of attempts specified for (int i = 0; i < attempts; i++) { // close com port in case it was open Payout.SSPComms.CloseComPort(); // turn encryption off for first stage Payout.CommandStructure.EncryptionStatus = false; // if the key negotiation is successful then set the rest up if (Payout.OpenComPort(textBox1) && Payout.NegotiateKeys(textBox1)) { Payout.CommandStructure.EncryptionStatus = true; // now encrypting // find the max protocol version this validator supports byte maxPVersion = FindMaxProtocolVersion(); if (maxPVersion >= 6) { Payout.SetProtocolVersion(maxPVersion, textBox1); } else { MessageBox.Show("This program does not support slaves under protocol 6!", "ERROR"); return(false); } // get info from the validator and store useful vars Payout.SetupRequest(textBox1); // check this unit is supported if (!IsUnitValid(Payout.UnitType)) { MessageBox.Show("Unsupported type shown by SMART Payout, this SDK supports the SMART Payout only"); Application.Exit(); return(false); } // inhibits, this sets which channels can receive notes Payout.SetInhibits(textBox1); // enable, this allows the validator to operate Payout.EnableValidator(textBox1); // enable the payout system on the validator Payout.EnablePayout(textBox1); return(true); } // Set timer reconnectionTimer.Enabled = true; while (reconnectionTimer.Enabled) { Application.DoEvents(); } } return(false); }
public void ConnectToSMARTPayout(TextBox log = null) { payoutConnecting = true; // setup timer, timeout delay and number of attempts to connect System.Windows.Forms.Timer reconnectionTimer = new System.Windows.Forms.Timer(); reconnectionTimer.Tick += new EventHandler(reconnectionTimer_Tick); reconnectionTimer.Interval = 1000; // ms int attempts = 10; // Setup connection info Payout.CommandStructure.ComPort = Global.ValidatorComPort; Payout.CommandStructure.SSPAddress = Global.Validator1SSPAddress; Payout.CommandStructure.BaudRate = 9600; Payout.CommandStructure.Timeout = 1000; Payout.CommandStructure.RetryLevel = 3; // Run for number of attempts specified for (int i = 0; i < attempts; i++) { if (log != null) { log.AppendText("Trying connection to SMART Payout\r\n"); } // turn encryption off for first stage Payout.CommandStructure.EncryptionStatus = false; // Open port first, if the key negotiation is successful then set the rest up if (Payout.OpenPort() && Payout.NegotiateKeys(log)) { Payout.CommandStructure.EncryptionStatus = true; // now encrypting // find the max protocol version this validator supports byte maxPVersion = FindMaxPayoutProtocolVersion(); if (maxPVersion >= 6) { Payout.SetProtocolVersion(maxPVersion, log); } else { MessageBox.Show("This program does not support units under protocol 6!", "ERROR"); payoutConnecting = false; return; } // get info from the validator and store useful vars Payout.SetupRequest(log); // check the right unit is connected if (!IsValidatorSupported(Payout.UnitType)) { MessageBox.Show("Unsupported type shown by SMART Payout, this SDK supports the SMART Payout and the SMART Hopper only"); payoutConnecting = false; Application.Exit(); return; } // inhibits, this sets which channels can receive notes Payout.SetInhibits(log); // enable payout Payout.EnablePayout(log); // set running to true so the validator begins getting polled payoutRunning = true; payoutConnecting = false; return; } // reset timer reconnectionTimer.Enabled = true; while (reconnectionTimer.Enabled) { if (CHelpers.Shutdown) { payoutConnecting = false; return; } Application.DoEvents(); Thread.Sleep(1); } } payoutConnecting = false; return; }