How to Build a Simple Test Application for LPMS Devices
This page is outdated!
Please refer to our OpenZen library for the latesdt and greatest instruction on building a test application: https://lpresearch.bitbucket.io/openzen/latest/
Old content ------->
For the time being this tutorial works with Windows (7 or later) and the MS Visual Studio command line. Building via the Vidual Studio IDE and Linux build instructions will be added soon.
- Download example code from our GIT repository here: https://bitbucket.org/lpresearch/lpmsexamples
- In this tutorial we will work the code in LpmsExamples/LpmsSimpleExample/
Let's look at the files we are dealing with.
main.cpp: This file contains all the source code to do simple data acquisition using an LPMS device.
CMakeLists.txt: This is the source file for Makefile / project file generator CMake.
To build the test program the following prerequisites are necessary:
Install the lastest OpenMAT version. At the time of writing this is it: https://bitbucket.org/lpresearch/openmat/downloads/OpenMAT-1.3.5-Setup-Build20170518.exe
Install CMake from here: https://cmake.org/files/v3.8/cmake-3.8.0-rc1-win32-x86.msi
You need to have MS Visual Studio 2013 or later installed on your system. If you don't have it installed yet, a free version (Community Edition) can be downloaded from here: https://www.visualstudio.com/post-download-vs/?sku=community&clcid=0x409&telem=ga#
Include the path to the CMake executable (usually C:\Program Files (x86)\CMake\bin) to your Windows PATH system variable. More information on how to do that is here: http://windowsitpro.com/systems-management/how-can-i-add-new-folder-my-system-path
Include the path to your OpenMAT dynamic link libraries to your system path (e.g. C:\OpenMAT\OpenMAT-1.3.5\lib\x86)
Now, in the following I will explain how to build the application in my favorite way, that is via the command line. I will explain how to use the Visual Studio IDE later on:
Open the Visual Studio command line (e.g. VS2013 x86 Native Tools Command Prompt).
Change directory to the directory where you saved LpmsSimpleExample.
In an editor (Notepad++ recommended) open CMakeLists.txt and find the lines:
if (BUILD_ARCHITECTURE STREQUAL "32-bit") include_directories("C:/OpenMAT/OpenMAT-1.3.5/include") link_directories("C:/OpenMAT/OpenMAT-1.3.5/lib/x86") endif()
Edit these lines to reflect the location of your OpenMAT include and library files. In case of a default install of version 1.3.5 the directory in the example can be left unchanged.
Open main.cpp and find the following lines
// List of LPMS type identifiers // DEVICE_LPMS_B LPMS-B (Bluetooth) // DEVICE_LPMS_U LPMS-CU / LPMS-USBAL (USB) // DEVICE_LPMS_C LPMS-CU / LPMS-CANAL(CAN bus) // DEVICE_LPMS_BLE LPMS-BLE (Bluetooth low energy) // DEVICE_LPMS_RS232 LPMS-UARTAL (RS-232) // DEVICE_LPMS_B2 LPMS-B2 // DEVICE_LPMS_U2 LPMS-CU2/URS2/UTTL2/USBAL2 (USB) // DEVICE_LPMS_C2 LPMS-CU2/CANAL2 (CAN) // Connects to LPMS-B2 sensor with address 00:11:22:33:44:55 LpmsSensorI* lpms = manager->addSensor(DEVICE_LPMS_B2, "00:11:22:33:44:55");
To connect to a sensor we use the method addSensor. addSenor takes as an argument the sensor type (Bluetooth, USB etc.) and the device ID (e.g. the Bluetooth MAC address for LPMS-B2). Insert the sensor type and ID of your device here.
On the command line enter the following command: cmake -G"NMake Makefiles". This generates the Makefile for the following build process.
The result should be something like this:
C:\develop\lpmsexamples\LpmsSimpleExample>cmake -G"NMake Makefiles" -- The C compiler identification is MSVC 18.0.40629.0 -- The CXX compiler identification is MSVC 18.0.40629.0 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: C:/develop/lpmsexamples/LpmsSimpleExample
On the command line enter: nmake
Example output:
C:\develop\lpmsexamples\LpmsSimpleExample>nmake Microsoft (R) Program Maintenance Utility Version 12.00.21005.1 Copyright (C) Microsoft Corporation. All rights reserved. Scanning dependencies of target LpmsSimpleExample [ 50%] Building CXX object CMakeFiles/LpmsSimpleExample.dir/main.obj main.cpp [100%] Linking CXX executable LpmsSimpleExample.exe [100%] Built target LpmsSimpleExample
The application should build without error or warnings. Run the application by typing: LpmsSimpleExample