Readout Software for Baumer UNDK 09 Ultrasonic Distance Sensor with RS232


Overview

Baumer UNDK 09 Ultrasonic Distance Sensor

We want to use a ultrasonic distance sensor to scan over a surface of wet soil to measure it's warping.

We found the UNDK 09 Baumer to fit well for our needs.

The UNDK 09 is available with an RS232 serial interface to read out the measured values and to set some configuration values.

The UNDK 09 has a distance range of 3mm to 150mm.

To be able to communicate with the sensor, a program serial_comm_w32_unix.pl is written, which features the setting of the configuration and the readout and recording to a file of the stream of measurement values.

serial_comm_w32_unix.pl is written to be portable, i.e. it works under both Windows and Linux or probably other Unix like operating system (if supported by Device::SerialPort perl module).
This page is mainly a description on how to make the script run under Windows.

Index


Baumer UNDK 09 Ultrasonic Distance Sensor with RS232

UNDK 09T9114/KS35AD1 ia an ultrasonic distance measuring sensor with RS232 serial interface. It uses a sonic frequency of 380kHz.
It is encapsulated in a plastic housing (PA12) reaching a protection class of IP67.

It can measure the distance to a surface in the range of 3 to 150mm with a resolution and a repeatablity up to 0.1mm.

For power supply it uses 15 - 30VDC at 35mA.
Operating temperature range is 0 - 60°C.

The serial communication parameters are 115200 bits/s (baud rate), 8 data bits, no parity, 1 stop bit.

top

Install Strawberry Perl and additional modules

The software implementing communication with the ultrasonic distance sensor is written in perl. To be able to run it, perl must be installed. For Windows Strawberry Perl is recommended and tested. Active State Perl did not work together with Win32::SerialPort module needed for serial communication handling.

Download and install Strawberry Perl 32bit version. Win32::SerialPort module does not work with 64bit version of Strawberry Perl at time of this writing (2014-11-18).

The perl script written to communicate with the UNDK 09 Ultrasonic Distance Sensor uses two additional modules not included with Strawberry Perl.
The first is Win32::SerialPort which implements serial port handling on Windows and
second is DateTime::Format::Strptime needed to create properly formatted time stamps in the log file.

Both modules may be installed from cpan with the commands listed below.

As a user with administrative rights run:

cpan Win32::SerialPort

The installation of Win32::SerialPort per default runs some tests with COM1, and fails if there is no COM1 available in the system (see here).
To overcome this, you may connect a USB serial adapter and assign COM1 to it.

cpan DateTime::Format::Strptime
top

Useful Tools

To be able to work reasonbly on command line under Windows, it is recommended to install some tools:

The Console program included with Windows is very limited in functionality and not really usable to interact with the system based on command line. ConEmu is a much more usable console program for Windows.

The Windows command interpreter cmd.exe is a very bad command line shell. You may install Clink which adds the powerful command line editing known from the well-known Unix shell Bash.

As the serial_comm_w32_unix.pl perl script is developed in a cvs repository, TortoiseCVS is recommended to be installed to be able to easily stay up date with the script development progress.

top

serial_comm_w32_unix.pl Perl Script

For running the script, a command shell should be started. If ConEmu is installed as recommended, start it by using the Windows Start Menu or other appropriate means.
On our setup there is a shortcut to ConEmu on the desktop which starts the command interpreter in the correct folder.

In ConEmu window make shure you are in the right folder where the script resides (\Users\physio\Documents\cvs\snippets\perl\SerialPort in our case) or cd to it if not.

cd \Users\physio\Documents\cvs\snippets\perl\SerialPort

Run the script by calling it by it's filename, a typical call would look like:

serial_comm_w32_unix.pl -D COM1 -X abs -S highest -A 32 -T on -M -l distances.csv -a 

See below for explanations on the options meaning.
The usage instruction as shown below may be shown by calling the script with the option --help (or short -h).

Communicates via RS232 with a Baumer UNDK 09 Ultrasonic distance measuring sensor.
Per default the sensor is configured for absolute measure mode,
with ASCII format, at highest sensitivity (3..150mm range),
with 32 fold averaging and temperature compensation off.

usage: serial_comm_w32_unix.pl [options]
  Options:
    -h --help:      print this help information.
       --version:   print program version information.
    -v --verbose:   be verbose by printing progressing to stdout.
    -d --debug:     print debugging information to stdout.
    -D --serial-device <device file>
                    use <device file> as serial port device (default /dev/ttyUSB0).
    -l --logfile <logfile name>                                                                                                                     
                    Record measured values to log file <logfile name>.                                                                              
    -a --append     Append to logfile specified by --logfile <logfile name>                                                                         
                      instead of failure exit if file exists.                                                                                       
    -C --get-conf   Query and print sensor configuration.                                                                                           
    -Y --factory-defaults                                                                                                                           
                    Set sensor configuration to factory defaults.                                                                                   
    -X --measure-mode [absolute|relative]                                                                                                           
                    Selects absolute (in 0.1mm) or relative (0..4095)                                                                               
                      measuring node.                                                                                                               
    -S --sensitivity [highest|high|low|lowest]                                                                                                      
                    Set sensor sensitivity.                                                                                                         
    -T --temp-comp [on|off]                                                                                                                         
                    Set temperature compensation on or off.                                                                                         
    -A --averaging <count>                                                                                                                          
                    Set number of measurements to be averaged.                                                                                      
                      (allowed values are 0, 2, 4, 8, 16, 32, 64)
    -M --measure    Run single measurement.
    -F --periodic-format [ascii|binary]
                    Selects ascii or compact binary format for continuous
                      periodic measure mode.
    -P --periodic-measure
                    Run periodic contiuous measure.
    -R --reset      Stops continous measure mode.
    -B --baud <bit rate>
                    use <bit rate> as tx and rx rates (default 115200).
    -b --databits <databits>
                    data bit count is <databits> (default 8).
    -p --parity <parity>
                    <parity> can be set to "none", "odd" or "even" (default none).
    -s --stopbits <stopbits>
                    stop bit count is <stopbits>(default 1).

The perl script may be aborted by pressing Ctrl-C.

Be aware of the fact, that when you set the sensor to periodic continous measure mode it stays in this mode until it receives a reset command (option --reset) or until power cycled.
This means that the sensor doesn't react properly to any command except reset as long as it is in periodic continous measure mode.

Version 1.12 of serial_comm_w32_unix.pl perl script may be downloaded here.

top

Links

top
line
This site maintained by:
lukas.zimmermann@unibas.ch
My public PGP key
last updated: 2014-11-18 Valid CSS! Valid XHTML 1.0 Strict