コード例 #1
0
        //*********************************************************
        public void Thread1()
        {
            // try
            {
                // while (request)
                {
                    serialPort.ReadExisting();
                    byte[] data = new byte[8];
                    data[0] = 75;
                    data[1] = 75;
                    data[2] = 75;
                    serialPort.Write(data, 0, 3);

                    byte[] d = new byte[10];

                    label1.Text = "";
                    if (serialPort.ReadChar() == 65)
                    {
                        if (serialPort.ReadChar() == 65)
                        {
                            for (int i = 0; i <= 3; i++)
                            {
                                d[i] = Convert.ToByte(serialPort.ReadChar());
                            }

                            P_L.Invoke(new Action(() => P_L.Text = d[0].ToString()));
                            P_H.Invoke(new Action(() => P_H.Text = d[1].ToString()));

                            T_L.Invoke(new Action(() => T_L.Text = d[2].ToString()));
                            T_H.Invoke(new Action(() => T_H.Text = d[3].ToString()));

                            double Pan_Position = (((d[1] * 100) + d[0]));
                            double Til_Position = (((d[3] * 100) + d[2]));

                            Pan.Invoke(new Action(() => Pan.Text = Pan_Position.ToString()));
                            Til.Invoke(new Action(() => Til.Text = Til_Position.ToString()));

                            // listBox1.Invoke(new Action(() => listBox1.Items.Add(Pan_Position.ToString())));

                            // listBox1.Invoke(new Action(() => listBox1.Items.Add("------------------")));

                            //   listBox1.Invoke(new Action(() => T_L.Text = d[2].ToString()));
                            //   listBox1.Invoke(new Action(() => T_H.Text = d[3].ToString()));
                            //
                        }
                    }
                    System.Threading.Thread.Sleep(100);
                }
            }
            // catch
            {
            }
        }