示例#1
0
        // The main program loop, this is to control the validator, it polls at
        // a value set in this class (pollTimer).
        void MainLoop()
        {
            btnRun.Enabled = false;
            Validator.CommandStructure.ComPort    = Global.ComPort;
            Validator.CommandStructure.SSPAddress = Global.SSPAddress;
            Validator.CommandStructure.Timeout    = 3000;

            // connect to the validator
            if (ConnectToValidator())
            {
                Running = true;
                textBox1.AppendText("\r\nPoll Loop\r\n*********************************\r\n");
                btnHalt.Enabled = true;
            }

            while (Running)
            {
                // if the poll fails, try to reconnect
                if (!Validator.DoPoll(textBox1))
                {
                    textBox1.AppendText("Poll failed, attempting to reconnect...\r\n");
                    Connected        = false;
                    ConnectionThread = new Thread(ConnectToValidatorThreaded);
                    ConnectionThread.Start();
                    while (!Connected)
                    {
                        if (ConnectionFail)
                        {
                            textBox1.AppendText("Failed to reconnect to validator\r\n");
                            return;
                        }
                        Application.DoEvents();
                    }
                    textBox1.AppendText("Reconnected successfully\r\n");
                }

                timer1.Enabled = true;
                // update form
                UpdateUI();
                // setup dynamic elements of win form once
                if (!FormSetup)
                {
                    SetupFormLayout();
                    FormSetup = true;
                }
                while (timer1.Enabled)
                {
                    Application.DoEvents();
                    Thread.Sleep(1); // Yield to free up CPU
                }
            }

            //close com port and threads
            Validator.SSPComms.CloseComPort();

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }
示例#2
0
        // 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;
        }