Exemplo n.º 1
0
        void UpdateEncoderList()
        {
            _event.WaitOne();
            _event.Reset();
            foreach (ListViewItem lvi in listView1.Items)
            {
                if (_done)
                    break;
                StreamingEncoder encoder = (StreamingEncoder)lvi.Tag;
                OysterEncoderController.Control oec =
                    new OysterEncoderController.Control(encoder.ControlAddress, encoder.ControlPort);

                lvi.SubItems[3].Text = "Connecting";
                Application.DoEvents();
                if (oec.Open())
                {
                    if (oec.IsRecording)
                    {
                        lvi.SubItems[2].Text = "Yes";
                        lvi.BackColor = Color.Cornsilk;
                        Application.DoEvents();
                    }
                    else
                    {
                        lvi.SubItems[2].Text = "No";
                        lvi.BackColor = Color.White;
                        Application.DoEvents();
                    }
                    oec.Close();
                    lvi.SubItems[3].Text = "Ready...";
                    lvi.Font = new Font(lvi.Font, FontStyle.Regular);
                    Application.DoEvents();
                }
                else
                {
                    IPAddress ipAddress;
                    if (encoder.ControlAddress.Split(new char[] {'.'}).Length != 3)
                    {
                        IPHostEntry hostEntry = Dns.GetHostByName(encoder.ControlAddress);
                        ipAddress = hostEntry.AddressList[0];
                    }
                    else
                    {
                        byte[] addressBytes = ASCIIEncoding.ASCII.GetBytes(encoder.ControlAddress);
                        ipAddress = new IPAddress(addressBytes);
                    }
                    Icmp ping = new Icmp(ipAddress);
                    if (ping.Ping() > TimeSpan.FromMilliseconds(5000.0))
                    {
                        lvi.SubItems[2].Text = "???";
                        lvi.SubItems[3].Text = "Possibly disabled. Needs to be power cycled.";
                        lvi.ForeColor = Color.LightGray;
                        lvi.Font = new Font(lvi.Font, FontStyle.Bold);
                        Application.DoEvents();
                    }
                    else
                    {
                        lvi.Font = new Font(lvi.Font, FontStyle.Regular);
                        lvi.SubItems[2].Text = "Yes";
                        lvi.SubItems[3].Text = "Encoder refused connection. Usually means it is recording...";
                        lvi.BackColor = Color.Cornsilk;
                        Application.DoEvents();
                    }
                }
                oec = null;
                Application.DoEvents();
            }
            _event.Set();
            Application.DoEvents();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (listView1.CheckedItems.Count > 0 && MessageBox.Show(this,"Are you sure you want to restart the selected encoders?","Restart requested...",MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                button1.Enabled = false;
                button2.Enabled = false;
                Cursor savedCursor = this.Cursor;
                this.Cursor = Cursors.WaitCursor;
                _event.WaitOne();
                _event.Reset();
                foreach (ListViewItem lvi in listView1.CheckedItems)
                {
                    if (_done)
                        break;
                    StreamingEncoder encoder = (StreamingEncoder)lvi.Tag;
                    OysterEncoderController.Control oec =
                        new OysterEncoderController.Control(encoder.ControlAddress, encoder.ControlPort);
                    bool success = false;

                    lvi.SubItems[3].Text = "Attempting to Restart...";
                    lvi.SubItems[2].Text = "No";
                    Application.DoEvents();
                    if (oec.Open())
                    {
                        if (oec.IsRecording)
                        {
                            lvi.SubItems[2].Text = "Yes";
                            lvi.SubItems[3].Text = "Recording will NOT be saved!";
                        }
                        Application.DoEvents();

                        CarverLab.Oyster.Encoder.Connection cn =
                            oec.Connection;
                        lvi.SubItems[3].Text = "Connected, sending command...";
                        Application.DoEvents();
                        Command retcmd = cn.SendCommandWaitForResponse(new Command("RBT","0"));
                        if (retcmd == null)
                        {
                            lvi.SubItems[3].Text = "Received an invalid response: <null>";
                        }
                        else
                        {
                            if (retcmd.Params.Length > 0)
                            {
                                if (retcmd.Params[0].Equals("OK"))
                                {
                                    lvi.SubItems[3].Text = "Sent restart command successfully.";
                                    success = true;
                                }
                                Application.DoEvents();
                            }
                            if (!success)
                            {
                                lvi.SubItems[3].Text = "Received an invalid response: " + retcmd.RawData;
                                Application.DoEvents();
                            }
                        }
                        oec.Close();
                    }
                    else
                    {
                        lvi.SubItems[3].Text = "Could not connect...";
                    }
                    Application.DoEvents();
                }
                this.Cursor = savedCursor;
                _event.Set();
                button1.Enabled = true;
                button2.Enabled = true;
            }
            Application.DoEvents();
        }