Пример #1
0
        /// <summary>
        /// Start scan button press
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonStart_Click(object sender, EventArgs e)
        {
            // Parse mode
            if (!Enum.TryParse(comboMode.SelectedItem.ToString(), out ScanMode mode))
            {
                logger.LogError($"Invalid scan mode: {comboMode.SelectedItem.ToString()}");
                return;
            }

            // Decide port
            if (comboPort.SelectedIndex < 0)
            {
                logger.LogError($"No port selected");
                return;
            }
            lidar.PortName = (string)comboPort.SelectedItem;

            // Set timeout high enough to allow slow speed scanning
            lidar.ReceiveTimeout = 3000;

            // Flipped ?
            lidar.IsFlipped = comboIsFlipped.SelectedIndex == 1;

            // Try to parse angle offset
            if (float.TryParse(textAngleOffset.Text, out float angleOffset))
            {
                lidar.AngleOffset = angleOffset;
            }
            else
            {
                logger.LogWarning("Invalid angle offset, using zero.");
                lidar.AngleOffset = 0.0f;
            }

            // Try to open port
            if (lidar.Open())
            {
                // Allow stopping
                comboPort.Enabled   = false;
                comboMode.Enabled   = false;
                buttonStart.Enabled = false;
                buttonStop.Enabled  = true;

                // Start scan task
                cancellationSource = new CancellationTokenSource();
                lidarTask          = Task.Run(() => Scan(mode, cancellationSource.Token));
            }
        }
Пример #2
0
 public void lidarSerial()
 {
     //turn on Lidar
     l.Open();
 }