示例#1
0
文件: Program.cs 项目: luputona/CS01
        static void Main(string[] args)
        {
            Computer computer = new Computer();
            Switch   sw       = new Switch();

            sw.PowerOn(computer);

            Moniter moniter = new Moniter();
            //sw.PowerOn(moniter);
        }
示例#2
0
 public void TurnOn(Moniter machine)     // 모니터 클래스를 받는다.
 {
     Console.WriteLine("Moniter Switch");
     machine.TurnOn();
 }
 private void Moniter_TextChanged(object sender, TextChangedEventArgs e)
 {
     Moniter.ScrollToEnd();
 }
        /// <summary>
        /// Timer test
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            if (Mode == 0)
            {
                //string indataarray = mySerialPort.ReadBufferSize();
                string indata = mySerialPort.ReadLine();

                //string indataarray = mySerialPort.ReadExisting();
                //string[] indatastrings = indataarray.Split('\n');

                for (int i = 0; i < 3; i++)
                {
                    DataFromGlover4times[i] = DataFromGlover4times[i + 1];
                }

                DataFromGlover4times[3] = indata;

                Moniter.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { Moniter.AppendText(indata); }));

                indata = indata.Replace("\r", "");

                ThreeDChange(indata);

                char KetQua = toLeter(DataFromGlover4times);

                textBoxLetter.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() => { textBoxLetter.Text = KetQua.ToString(); }));
            }
            else if (Mode == 1)
            {
                string indata = mySerialPort.ReadLine();

                Moniter.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() => { Moniter.AppendText(indata); }));

                indata = indata.Replace("\r", "");

                string[] indatabuffer = indata.Split('#');

                for (int i = 0; i < indatabuffer.Length; i++)
                {
                    dataMinimumValue[i] = Int32.Parse(indatabuffer[i]);
                }

                mySerialPort.Close();
                buttonOpen.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() => { buttonOpen.Content = "Open"; }));
            }
            else if (Mode == 2)
            {
                string indata = mySerialPort.ReadLine();

                Moniter.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() => { Moniter.AppendText(indata); }));

                indata = indata.Replace("\r", "");

                string[] indatabuffer = indata.Split('#');

                for (int i = 0; i < indatabuffer.Length; i++)
                {
                    dataMaximumValue[i] = Int32.Parse(indatabuffer[i]);
                }

                mySerialPort.Close();

                buttonOpen.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() => { buttonOpen.Content = "Open"; }));
            }
        }