Пример #1
0
        public void ReadPort()
        {
            SerialHandler serialHander = new SerialHandler();

            serialHander.remoteCallEvent     += agvSerialRemoteCall;
            serialHander.carStateReportEvent += agvCarStateReport;
            while (true)
            {
                if (this.newCanvas.Scheduler.SP.IsOpen)
                {
                    if (this.newCanvas.Scheduler.SP.BytesToRead == 0)
                    {
                        Thread.Sleep(10);
                        continue;
                    }
                    try
                    {
                        byte b = (byte)this.newCanvas.Scheduler.SP.ReadByte();
                        //writeLine( Convert.ToString(b,16) );
                        Console.WriteLine("================");
                        Console.Write((char)b);
                        serialHander.handleOneByte(b);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else
                {
                    break;
                }
            }
        }
Пример #2
0
        /*
         * public void agvSerialRemoteCall(object sender, SerialEventArgs e)
         * {
         ++callNum;
         *  if (callNum == 1)
         *  {
         *      Invoke(new niming(button8.PerformClick));//初始化
         *  }
         *  Invoke(new niming(button1.PerformClick));//AGV1
         *  try
         *  {
         *      switch (e.Message)
         *      {
         *          case "toT1":
         *              Invoke(new niming(Station1.PerformClick));
         *              Invoke(new niming(button9.PerformClick));
         *              break;
         *          case "toT2":
         *              Invoke(new niming(Station2.PerformClick));
         *              Invoke(new niming(button9.PerformClick));
         *              break;
         *          case "reF2":
         *              //aTimer1.Elapsed -= new ElapsedEventHandler(OnTimedEvent1);
         *              startPositon = "F2";
         *              Invoke(new niming(SetLocation1));
         *              Invoke(new niming(SetStartStation1));
         *              Invoke(new niming(StartStation.PerformClick));
         *              Invoke(new niming(button9.PerformClick));
         *              break;
         *          case "reT1":
         *              startPositon = "T1";
         *              Invoke(new niming(SetLocation1));
         *              Invoke(new niming(SetStartStation1));
         *              Invoke(new niming(StartStation.PerformClick));
         *              Invoke(new niming(button9.PerformClick));
         *              break;
         *
         *      }
         *  }
         *  catch (Exception x)
         *  {
         *      Console.WriteLine(x.Message);
         *  }
         * }
         */
        public void ReadPort()
        {
            SerialHandler serialHander = new SerialHandler();

            //serialHander.serialEvent += agvSerialRemoteCall;
            while (true)
            {
                if (serialPort1.IsOpen)
                {
                    if (serialPort1.BytesToRead == 0)
                    {
                        Thread.Sleep(100);
                    }
                    try
                    {
                        byte b = (byte)serialPort1.ReadByte();
                        serialHander.handleOneByte(b);
                        //String SerialIn = System.Text.Encoding.ASCII.GetString(readBuffer, 0, count);
                        //if (count != 0)
                        //{
                        //MessageBox.Show(SerialIn);
                        //}
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                /*else
                 * {
                 *  TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 50);
                 *  Thread.Sleep(waitTime);
                 * }*/
            }
        }