LaserInit

by Tim Lueth & Sebastian Heininger, SG-Lib Toolbox: SolidGeometry 5.6 - USB Interface
Introduced first in SolidGeometry 4.0, Creation date: 2017-07-06, Last change: 2025-08-19

Initializes the USB-Serial Port and Requests Data from the Leuze Scanner

Description

This is just an example how to use the Leuze Laser Scanner at the mac computer.

See Also: USBhelp

Example Illustration

 missing image of LaserInit

Syntax

LaserInit




Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm initializes a USB-Serial port to communicate with a Leuze laser scanner and requests data from it. Below is a detailed explanation of the algorithm and its parameters:

Input Parameters

Algorithm Steps

  1. Delete all existing serial port objects using instrfindall to ensure no conflicts with previous connections.
  2. Define the device name devnam as '/dev/tty.usbserial-DQ1MO622'. This is the path to the USB-Serial device on a Mac computer.
  3. Create a serial port object com1 with the following settings:
    • Baud rate: 57600
    • Terminator: '#'
    • Timeout: 1 second
  4. Attempt to open the serial port connection using fopen(com1). If unsuccessful, an error message is displayed indicating the device is not connected.
  5. Initialize variables:
    • da: Previous distance measurement, initialized to 0.
    • n: Number of measurements to take, set to 100.
    • m: Array to store distance measurements, initialized with NaN values.
    • t: Array to store time measurements, initialized with NaN values.
  6. Start a timer using tic and store the start time in A.
  7. Loop n times to collect data:
    • Send a command to the laser scanner using fprintf(com1, char(00)) to request a 4-digit measurement.
    • Read the response from the scanner using fscanf(com1) and convert the relevant part of the string to a number.
    • Adjust the measurement by dividing by 100 and subtracting 52 to get the final distance.
    • If the new distance d is different from the previous da, update da and print the new distance.
    • Record the elapsed time since the start of the loop in t(i).
    • If the distance d is less than 47, store it in m(i).
  8. Close the serial port connection using fclose(com1).
  9. Return the time and distance arrays [t m].
Algorithm explaination created using ChatGPT on 2025-08-19 00:03. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21