Ejemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (SPLidar.IsOpen)
     {
         SPLidar.Close();
         button1.Enabled = true;
         button2.Enabled = false;
     }
 }
Ejemplo n.º 2
0
        private void InitForm()
        {
            /*set Serial port name*/
            foreach (string s in SerialPort.GetPortNames())
            {
                comboBox1.Items.Add(s);
            }
            /*if item in comboBox is more than 1,show it*/
            if (comboBox1.Items.Count > 0)
            {
                comboBox1.SelectedIndex = 0;
                SPLidar.PortName        = comboBox1.SelectedItem.ToString();
                Console.WriteLine("Serial Port is " + SPLidar.PortName);
            }

            comboBox2.Items.AddRange(new object[] { 4800, 9600, 19200, 38400, 115200, 460800 });
            comboBox2.SelectedIndex = 4;
            /*initialize lidarSpeed */
            lidarSpeed = 0;
            if (lidarSpeed > 1024)
            {
                lidarSpeed = 1024;
            }
            trackBar1.Value = lidarSpeed;
            textBox1.Text   = lidarSpeed.ToString();


            InitSPLidar();

            /*open port, stop scan, start rotating*/

            foreach (string s in SerialPort.GetPortNames())
            {
                SPLidar.PortName = s;
                SPLidar.Open();
                if (SPLidar.IsOpen)
                {
                    stopScan();
                    updateSpeed();
                    stopScan();
                    SPLidar.Close();
                }
            }

            /*close form1*/
            Console.WriteLine("close this form automotive");

            //this.Close();
        }