Exemple #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(int attempts)
        {
            // setup timer
            System.Windows.Forms.Timer reconnectionTimer = new System.Windows.Forms.Timer();
            reconnectionTimer.Tick    += new EventHandler(reconnectionTimer_Tick);
            reconnectionTimer.Interval = 3000; // ms

            // run for number of attempts specified
            for (int i = 0; i < attempts; i++)
            {
                // close com port in case it was open
                NV11.SSPComms.CloseComPort();

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

                // if the key negotiation is successful then set the rest up
                if (NV11.NegotiateKeys(textBox1) == true)
                {
                    NV11.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxProtocolVersion();
                    if (maxPVersion >= 6)
                    {
                        NV11.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
                    NV11.SetupRequest(textBox1);
                    // inhibits, this sets which channels can receive notes
                    NV11.SetInhibits(textBox1);
                    // enable, this allows the validator to operate
                    NV11.EnableValidator(textBox1);
                    // value reporting, set whether the validator reports channel or coin value in
                    // subsequent requests
                    NV11.SetValueReportingType(false, textBox1);
                    // check for notes already in the float on startup
                    NV11.CheckForStoredNotes(textBox1);
                    //
                    return(true);
                }
                // reset timer
                reconnectionTimer.Enabled = true;
                while (reconnectionTimer.Enabled)
                {
                    Application.DoEvents();
                }
            }
            return(false);
        }
Exemple #2
0
        public void ConnectToNV11(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
            NV11.CommandStructure.ComPort    = Global.ComPort;
            NV11.CommandStructure.SSPAddress = Global.Validator1SSPAddress;
            NV11.CommandStructure.BaudRate   = 9600;
            NV11.CommandStructure.Timeout    = 1000;
            NV11.CommandStructure.RetryLevel = 3;

            // Run for number of attempts specified
            for (int i = 0; i < attempts; i++)
            {
                if (log != null)
                {
                    log.AppendText("Trying connection to NV11\r\n");
                }

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

                // if the key negotiation is successful then set the rest up
                if (NV11.OpenPort() && NV11.NegotiateKeys(log))
                {
                    NV11.CommandStructure.EncryptionStatus = true; // now encrypting
                    // find the max protocol version this validator supports
                    byte maxPVersion = FindMaxNV11ProtocolVersion();
                    if (maxPVersion >= 6)
                    {
                        NV11.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
                    NV11.SetupRequest(log);
                    // inhibits, this sets which channels can receive notes
                    NV11.SetInhibits(log);
                    // enable payout to begin with
                    NV11.EnablePayout(log);
                    // check for any stored notes
                    NV11.CheckForStoredNotes(log);
                    // report by the 4 byte value of the note, not the channel
                    NV11.SetValueReportingType(false, log);
                    // set running to true so the NV11 begins getting polled
                    NV11Running = true;
                    return;
                }
                // reset timer
                reconnectionTimer.Enabled = true;
                while (reconnectionTimer.Enabled)
                {
                    if (CHelpers.Shutdown)
                    {
                        return;
                    }
                    Application.DoEvents();
                }
            }
        }