Ejemplo n.º 1
0
        // 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()
        {
            // setup the timer
            reconnectionTimer.Interval = reconnectionInterval * 1000; // for ms

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

                // close com port in case it was open
                Validator.SSPComms.CloseComPort();

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

                // open com port and negotiate keys
                if (Validator.OpenComPort(textBox1) && Validator.NegotiateKeys(textBox1))
                {
                    Validator.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxProtocolVersion();
                    if (maxPVersion > 6)
                    {
                        Validator.SetProtocolVersion(maxPVersion, textBox1);
                    }
                    else
                    {
                        MessageBox.Show("This program does not support units under protocol version 6, update firmware.", "ERROR");
                        return(false);
                    }
                    // get info from the validator and store useful vars
                    Validator.SetupRequest(textBox1);
                    // check this unit is supported by this program
                    if (!IsUnitTypeSupported(Validator.UnitType))
                    {
                        MessageBox.Show("Unsupported unit type, this SDK supports the BV series and the NV series (excluding the NV11)");
                        Application.Exit();
                        return(false);
                    }
                    // inhibits, this sets which channels can receive notes
                    Validator.SetInhibits(textBox1);
                    // enable, this allows the validator to receive and act on commands
                    Validator.EnableValidator(textBox1);

                    return(true);
                }
                while (reconnectionTimer.Enabled)
                {
                    Application.DoEvents();                               // wait for reconnectionTimer to tick
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void ConnectToNoteValidator(TextBox log = null)
        {
            // setup timer and attempts
            System.Windows.Forms.Timer reconnectionTimer = new System.Windows.Forms.Timer();
            reconnectionTimer.Tick    += new EventHandler(reconnectionTimer_Tick);
            reconnectionTimer.Interval = 1000;
            int attempts = 10;

            // Setup connection info
            Validator.CommandStructure.ComPort    = Global.ComPort;
            Validator.CommandStructure.SSPAddress = Global.Validator1SSPAddress;
            Validator.CommandStructure.Timeout    = 1000;
            Validator.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
                Validator.CommandStructure.EncryptionStatus = false;

                // if the key negotiation is successful then set the rest up
                if (Validator.OpenComPort(log) && Validator.NegotiateKeys(log) == true)
                {
                    Validator.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxValidatorProtocolVersion();
                    if (maxPVersion > 6)
                    {
                        Validator.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
                    Validator.SetupRequest(log);
                    // check unit is valid
                    if (!IsValidatorValid(Validator.UnitType))
                    {
                        string s = "Unsupported unit type detected on the Validator port, this SDK requires a BV or NV series ";
                        s += "validator on the Validator port (excluding NV11).";
                        MessageBox.Show(s);
                        Application.Exit();
                        return;
                    }
                    // inhibits, this sets which channels can receive notes
                    Validator.SetInhibits(log);
                    // set running to true so the validator begins getting polled
                    validatorRunning = true;
                    return;
                }
                while (reconnectionTimer.Enabled)
                {
                    if (CHelpers.Shutdown)
                    {
                        return;
                    }
                    Application.DoEvents();
                    Thread.Sleep(1);
                }
            }
            ;
        }