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
- There are no explicit input parameters for this function. It operates based on predefined settings within the code.
Algorithm Steps
- Delete all existing serial port objects using
instrfindall
to ensure no conflicts with previous connections.
- Define the device name
devnam
as '/dev/tty.usbserial-DQ1MO622'
. This is the path to the USB-Serial device on a Mac computer.
- Create a serial port object
com1
with the following settings:
- Baud rate: 57600
- Terminator: '#'
- Timeout: 1 second
- Attempt to open the serial port connection using
fopen(com1)
. If unsuccessful, an error message is displayed indicating the device is not connected.
- 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.
- Start a timer using
tic
and store the start time in A
.
- 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)
.
- Close the serial port connection using
fclose(com1)
.
- 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