Пример #1
0
        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);
        }
Пример #2
0
        public void ConnectToHopper(TextBox log = null)
        {
            // setup timer
            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
            Hopper.CommandStructure.ComPort    = Global.ComPort;
            Hopper.CommandStructure.SSPAddress = Global.Validator2SSPAddress;
            Hopper.CommandStructure.BaudRate   = 9600;
            Hopper.CommandStructure.Timeout    = 1000;
            Hopper.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 Hopper\r\n");
                }

                // turn encryption off for first stage
                Hopper.CommandStructure.EncryptionStatus = false;

                // if the key negotiation is successful then set the rest up
                if (Hopper.OpenPort() && Hopper.NegotiateKeys(log))
                {
                    Hopper.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxHopperProtocolVersion();
                    if (maxPVersion >= 6)
                    {
                        Hopper.SetProtocolVersion(maxPVersion, log);
                    }
                    else
                    {
                        MessageBox.Show("This program does not support slaves under protocol 6!", "ERROR");
                        return;
                    }
                    // get info from the validator and store useful vars
                    Hopper.SetupRequest(log);
                    // inhibits, this sets which channels can receive notes
                    Hopper.SetInhibits(log);
                    // set running to true so the hopper begins getting polled
                    hopperRunning = true;
                    return;
                }
                // reset timer
                reconnectionTimer.Enabled = true;
                while (reconnectionTimer.Enabled)
                {
                    if (CHelpers.Shutdown)
                    {
                        return;
                    }
                    Application.DoEvents();
                }
            }
        }
Пример #3
0
        public void ConnectToHopper(TextBox log = null)
        {
            // setup timer
            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
            Hopper.CommandStructure.ComPort    = Global.ComPort;
            Hopper.CommandStructure.SSPAddress = Global.Validator2SSPAddress;
            Hopper.CommandStructure.Timeout    = 1000;
            Hopper.CommandStructure.RetryLevel = 3;

            // Run for number of attempts specified
            for (int i = 0; i < attempts; i++)
            {
                // reset timer
                reconnectionTimer.Enabled = true;

                // turn encryption off for first stage
                Hopper.CommandStructure.EncryptionStatus = false;

                // if the key negotiation is successful then set the rest up
                if (Hopper.OpenComPort(log) && Hopper.NegotiateKeys(log) == true)
                {
                    Hopper.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxHopperProtocolVersion();
                    if (maxPVersion >= 6)
                    {
                        Hopper.SetProtocolVersion(maxPVersion, log);
                    }
                    else
                    {
                        MessageBox.Show("This program does not support units under protocol 6!", "ERROR");
                        return;
                    }
                    // get info from the validator and store useful vars
                    Hopper.SetupRequest(log);
                    // check unit is valid
                    if (!IsHopperValid(Hopper.UnitType))
                    {
                        string s = "Unsupported unit type detected on the Hopper port, this SDK requires a SMART Hopper\n";
                        s += "on the Hopper port.";
                        MessageBox.Show(s);
                        return;
                    }
                    // inhibits, this sets which channels can receive notes
                    Hopper.SetInhibits(log);
                    // set running to true so the hopper begins getting polled
                    hopperRunning = true;
                    return;
                }
                while (reconnectionTimer.Enabled)
                {
                    if (CHelpers.Shutdown)
                    {
                        return;
                    }
                    Application.DoEvents();
                    Thread.Sleep(1); // Yield to free up CPU
                }
            }
            return;
        }