예제 #1
0
파일: Form1.cs 프로젝트: kalkansa/stserver
        // The main program loop, this is to control the validator, it polls at
        // a value set in this class (pollTimer).
        public void MainLoop()
        {
            this.Enabled    = true;
            btnRun.Enabled  = false;
            btnHalt.Enabled = true;

            // Connect to the validators (non-threaded for initial connect)
            ConnectToSMARTPayout(textBox1);
            ConnectToHopper(textBox1);

            // Enable validators
            Payout.EnableValidator();
            Hopper.EnableValidator();

            // While app active
            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 && !hopperConnecting && !Hopper.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Hopper\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!payoutRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    hopperRunning = false;
                    // Create and start a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    tHopRec = new Thread(() => ReconnectHopper());
                    tHopRec.Start();
                }
                // Same as above but for the Payout
                if (payoutRunning && !payoutConnecting && !Payout.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Payout\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!hopperRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    payoutRunning = false;
                    // Create and start a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    tSPRec = new Thread(() => ReconnectPayout());
                    tSPRec.Start();
                }
                UpdateUI();
                timer1.Enabled = true;
                while (timer1.Enabled)
                {
                    Application.DoEvents();
                }
            }

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }
예제 #2
0
파일: Form1.cs 프로젝트: kalkansa/stserver
        // 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;
            Payout.CommandStructure.ComPort    = Global.ComPort;
            Payout.CommandStructure.SSPAddress = Global.SSPAddress;
            Payout.CommandStructure.Timeout    = 3000;

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

            while (Running)
            {
                // if the poll fails, try to reconnect
                if (Payout.DoPoll(textBox1) == false)
                {
                    textBox1.AppendText("Poll failed, attempting to reconnect...\r\n");
                    while (true)
                    {
                        Payout.SSPComms.CloseComPort();  // close com port

                        // attempt reconnect, pass over number of reconnection attempts
                        if (ConnectToValidator(reconnectionAttempts, 2) == true)
                        {
                            break; // if connection successful, break out and carry on
                        }
                        // if not successful, stop the execution of the poll loop
                        btnRun.Enabled  = true;
                        btnHalt.Enabled = false;
                        Payout.SSPComms.CloseComPort();  // close com port before return
                        return;
                    }
                    textBox1.AppendText("Reconnected\r\n");
                }

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

            //close com port
            Payout.SSPComms.CloseComPort();

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }