private void BtnQueueManagerControl_Click(object sender, RoutedEventArgs e)
        {
            LoadGoalLists();

            QueueJobManager.Start(Connection);

            ThreadPool.QueueUserWorkItem(new WaitCallback(QueueLoop));

            GrdJMMain.IsEnabled = true;

            //SychronousCommands sychronousCommands = new SychronousCommands(TxtConnectionString.Text);
            //List<string> goals;

            //if(sychronousCommands.Connect())
            //    goals = sychronousCommands.GetGoals();
            //else
            //{
            //    return;
            //}
            //sychronousCommands.Close();

            //if(Connection.Connect())
            //{
            //    btnConnect.Background = Brushes.Green;

            //    Connection.DataReceived += Connection_DataReceived;

            //    QueueJobManager = new QueueJobManager(Connection);

            //    QueueJobManager.Start();

            //    for(int i = 0; i < 4; i++)
            //    {
            //        ((ComboBox)stkGoalType.Children[i]).Items.Add("pickup");
            //        ((ComboBox)stkGoalType.Children[i]).Items.Add("dropoff");
            //    }
            //    foreach(ComboBox cmb in stkGoalName.Children)
            //    {
            //        cmb.ItemsSource = goals;
            //    }

            //    ThreadPool.QueueUserWorkItem(new WaitCallback(QueueLoop));
            //}
            //else
            //{
            //    btnConnect.Background = Brushes.Red;
            //}
        }
        private void BtnSendMulti_Click(object sender, RoutedEventArgs e)
        {
            List <QueueManagerJobSegment> goals = new List <QueueManagerJobSegment>();

            int i = 0;

            foreach (ComboBox cmb in GoalsComboBoxes)
            {
                if (i++ == 0)
                {
                    goals.Add(new QueueManagerJobSegment(null, ((string)cmb.SelectedItem).ToLower(), QueueManagerJobSegment.Types.pickup));
                    continue;
                }
                if (cmb.SelectedIndex >= 0)
                {
                    QueueManagerJobSegment.Types type = (cmb.SelectedIndex == 0) ? QueueManagerJobSegment.Types.pickup : QueueManagerJobSegment.Types.dropoff;
                    goals.Add(new QueueManagerJobSegment(null, ((string)cmb.SelectedItem).ToLower(), type));
                }
            }

            QueueJobManager.QueueMulti(goals);
        }
        private void ConnectionCleanup()
        {
            if (Connection != null)
            {
                Connection.ConnectState   -= Connection_ConnectState;
                Connection.QueueJobUpdate -= Connection_QueueUpdate;
            }

            if (EmRobots_Manager != null)
            {
                EmRobots_Manager.InSync -= EmRobots_Manager_InSync;
                EmRobots_Manager.Stop();
                EmRobots_Manager = null;
            }
            this.Queue(false, new Action(() => EmRobots_InSync?.Invoke(this, false)));

            if (EmIO_Manager != null)
            {
                EmIO_Manager.InSync -= EmIO_Manager_InSync;
                EmIO_Manager.Stop();

                EmIO_Manager = null;
            }
            this.Queue(false, new Action(() => EmIO_InSync?.Invoke(this, false)));

            if (EmQueue_Manager != null)
            {
                EmQueue_Manager.InSync -= EmQueue_Manager_InSync;
                EmQueue_Manager.Stop();

                EmQueue_Manager = null;
            }
            this.Queue(false, new Action(() => EmQueue_InSync?.Invoke(this, false)));

            Connection?.Close();
            Connection?.Dispose();
            Connection = null;
        }
 private void BtnCancelJob_Click(object sender, RoutedEventArgs e)
 {
     QueueJobManager.CancelJob(((Button)sender).Tag.ToString());
 }
        private void Connection_ConnectState(object sender, bool state)
        {
            if (state)
            {
                Connection.QueueJobUpdate += Connection_QueueUpdate;

                Dictionary <string, ExtIOSet> IOList = new Dictionary <string, ExtIOSet>()
                {
                    { "1", new ExtIOSet("1", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "2", new ExtIOSet("2", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "3", new ExtIOSet("3", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "4", new ExtIOSet("4", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "5", new ExtIOSet("5", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "6", new ExtIOSet("6", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "7", new ExtIOSet("7", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "8", new ExtIOSet("8", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "9", new ExtIOSet("9", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "10", new ExtIOSet("10", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "11", new ExtIOSet("11", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "12", new ExtIOSet("12", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "13", new ExtIOSet("13", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "14", new ExtIOSet("14", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "15", new ExtIOSet("15", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "16", new ExtIOSet("16", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "17", new ExtIOSet("17", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "18", new ExtIOSet("18", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "19", new ExtIOSet("19", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) },
                    { "20", new ExtIOSet("20", new List <byte> {
                            0
                        }, new List <byte> {
                            0
                        }) }
                };

                EmIO_Manager         = new ExternalIOManager(Connection, IOList);
                EmIO_Manager.InSync += EmIO_Manager_InSync;
                EmIO_Manager.Start();

                EmRobots_Manager         = new QueueRobotManager(Connection);
                EmRobots_Manager.InSync += EmRobots_Manager_InSync;
                EmRobots_Manager.Start();

                EmQueue_Manager         = new QueueJobManager(Connection);
                EmQueue_Manager.InSync += EmQueue_Manager_InSync;
                EmQueue_Manager.Start();
            }
            else
            {
                ConnectionCleanup();
                this.Queue(true, new Action(() => Em_Restart()));
            }
        }