Example #1
0
 private void SerialRead_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (mySerialPort.IsOpen)
     {
         try
         {
             byte[] buffer = new byte[2];
             //if ((e.KeyChar == '\r') || (e.KeyChar == '\n'))
             //{
             //    buffer[0] = Convert.ToByte('\r');
             //    buffer[1] = Convert.ToByte('\n');
             //    mySerialPort.Write(buffer, 0, 2);
             //    Console.WriteLine("WriteBuffer" + buffer[0] + ", " + buffer[1]);
             //}
             //else
             {
                 buffer[0] = Convert.ToByte(e.KeyChar);
                 mySerialPort.Write(buffer, 0, 1);
                 Console.WriteLine("WriteBuffer" + buffer[0]);
             }
             //SerialRead.SelectionStart = SerialRead.TextLength;//光标在最后
             SerialRead.ScrollToCaret();
         }
         catch (Exception)
         {
             MessageBox.Show(this, "发送出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #2
0
        public void SerialDataSent(object source, EventArgs args)
        {
            SerialRead tempObj = (SerialRead)source;
            //double[] X = new double[tempObj.Message.Length];
            //double[] Y = new double[tempObj.Message.Length];


            //for (int i = 2; i < (tempObj.Message.Length - 2); i++)
            //{
            //    string[] temp = tempObj.Message[i].ToString().Split(',');
            //    if (temp.Length == 3)
            //    {
            //        bool isNumeric = double.TryParse(temp[0], out double n) && double.TryParse(temp[1], out double n2);
            //        if (isNumeric)
            //        {
            //            double d = Convert.ToDouble(temp[0]);
            //            double a = Convert.ToDouble(temp[1]);
            //            X[i] = d * Math.Cos(a * Math.PI / 180);
            //            Y[i] = d * Math.Sin(a * Math.PI / 180);
            //        }
            //    }
            //}
            //if (chart1.InvokeRequired)
            //{
            //    Delegate del = new UpdatePlotDelegate(UpdatePlot);
            //    this.Invoke(del, X, Y);
            //}
            //else
            //{
            //    chart1.Series["LIDAR Data"].Points.AddXY(X, Y);
            //}
        }
Example #3
0
 private void SerialReadChange(char recv)
 {
     if (SerialRead.InvokeRequired)
     {
         SDataRcvEntHnd s = new SDataRcvEntHnd(SerialReadChange);
         SerialRead.Invoke(s, new object[] { recv });
     }
     else
     {
         SerialRead.Text += recv;
         //SerialRead.AppendText((string)recv);
         //SerialRead.Text += "\r\n";
         SerialRead.SelectionStart = SerialRead.TextLength;//光标在最后
         SerialRead.ScrollToCaret();
     }
 }
Example #4
0
 void start()
 {
     Yubi   = GameObject.Find("Serial");
     script = Yubi.GetComponent <SerialRead> ();
 }
Example #5
0
 void Start()
 {
     serial_script = GameObject.Find("SerialMaster").GetComponent("SerialRead") as SerialRead;
 }