Modbus Software, Driver and Libraries
 Login 
Member of Modbus Organization

Have a Question?

We accept VISA, MasterCard, PayPal

30-day Money-Back Guarantee

This Application Note describes how to recompile the FieldTalk Modbus Master C++ Library / Windows Edition with Visual Studio 2005.

Note The product is delivered with a precompiled static library which is ready to be used. Recompilation is only required if your project requires custom settings or modifications.
Prerequisites
  • Visual Studio 2005 Standard or Professional

  • The Windows Edition of the FieldTalk package must be installed and unzipped on your development computer.

Compilation using Visual Studio IDE

The FieldTalk package contains a folder structure similar to this:

My Projects
   fieldtalk
      doc
      include
      src                     <1>
      lib
         win
            win32
            release           <2>
      samples
      Visual C++ 6.0
      Visual Studio 2003
      Visual Studio 2005      <3>
  1. Directory containing the makefile

  2. Directory containing the library file libmbusmaster.lib

  3. Directory containing the Visual Studio 2005 project files to compile the library

Open Visual Studio and load the mbusmaster_win.sln solution file from the Visual Studio 2005 directory of the FieldTalk package.

Select Rebuild Solution from the Build menu.

Rebuild Solution Menu Entry

The compilation starts and the Output window will show a log similar to this:

1>------ Rebuild All started: Project: libmbusmaster, Configuration: Release Win
1>Deleting intermediate and output files for project 'libmbusmaster', configurat
1>Compiling...
1>MbusTcpMasterProtocol.cpp
1>MbusSerialMasterProtocol.cpp
1>MbusRtuOverTcpMasterProtocol.cpp
1>MbusRtuMasterProtocol.cpp
1>MbusMasterFunctions.cpp
1>MbusMasterCexports.cpp
1>MbusAsciiMasterProtocol.cpp
1>hmtimer.cpp
1>hmserio.cpp
1>Generating Code...
1>Compiling...
1>hmhex.c
1>hmcrc16.c
1>BusProtocolErrors.c
1>Generating Code...
1>Creating library...
1>Build log was saved at "file://c:\proconx\fieldtalk\obj\win\Win32\Release\Buil
1>libmbusmaster - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

The rebuilt library libmbusmaster.lib has been placed in the directory lib\win\win32\release, the library include files can be found in the directory include.

Changing the compiler settings

Typically some of the following compiler settings may be adjusted depending on your project needs. The following list shows the most common adjustments.

  • The libraries' character set must match your project's character set. Unless you are targeting Windows 98, you should use Unicode as shown below:

    General Property Page
  • It is recommended to use the same runtime library settings for FieldTalk as you use for your main project. Adjust as shown below:

    General Property Page
  • For backward compatibility with Visual C++ 6.0 the library is compiled with the floating point option /QIFIST set. This setting should be removed with Visual Studio 2005, as it is now deprecated. To remove, open the C/C++ Command Line property page and remove the /QIFIST entry as shown below.

    Command Line Property Page

Compilation using nmake

Open a Visual Studio Command Prompt window from the start menu as shown below.

Visual Studio 2005 Command Prompt

Change into the src subdirectory of your FieldTalk installation directory:

cd c:\proconx\fieldtalk\src

Run nmake from the Visual Studio 2005 Command Prompt window:

nmake

The compilation starts and the output will show a log similar to this:

C:\proconx\fieldtalk\src>nmake
Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

        md ..\obj\win\win32\release
        cl -W4  -I..\src -Fo..\obj\win\win32\release\ -c  ..\src\hmlib\common\hm
crc16.c ..\src\hmlib\common\hmhex.c ..\src\BusProtocolErrors.c  ..\src\hmlib\win
32\hmtimer.cpp ..\src\hmlib\win32\hmserio.cpp ..\src\MbusMasterFunctions.cpp ..\
src\MbusTcpMasterProtocol.cpp ..\src\MbusSerialMasterProtocol.cpp ..\src\MbusAsc
iiMasterProtocol.cpp ..\src\MbusRtuMasterProtocol.cpp ..\src\MbusRtuOverTcpMaste
rProtocol.cpp ..\src\MbusMasterCexports.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hmcrc16.c
hmhex.c
BusProtocolErrors.c
Generating Code...
Compiling...
hmtimer.cpp
hmserio.cpp
MbusMasterFunctions.cpp
MbusTcpMasterProtocol.cpp
MbusSerialMasterProtocol.cpp
MbusAsciiMasterProtocol.cpp
MbusRtuMasterProtocol.cpp
MbusRtuOverTcpMasterProtocol.cpp
MbusMasterCexports.cpp
Generating Code...
        md ..\include
A subdirectory or file ..\include already exists.
        attrib -r ..\include\*.*
        copy hmlib\common\hmserio.hpp ..\include
        1 file(s) copied.
        copy hmlib\common\hmtimer.hpp ..\include
        1 file(s) copied.
        copy hmlib\common\hmplatf.h ..\include
        1 file(s) copied.
        copy hmlib\common\hmtcpip.h ..\include
        1 file(s) copied.
        copy BusProtocolErrors.h ..\include
        1 file(s) copied.
        copy MbusMasterCexports.h ..\include
        1 file(s) copied.
        copy MbusMasterFunctions.hpp ..\include
        1 file(s) copied.
        copy MbusSerialMasterProtocol.hpp ..\include
        1 file(s) copied.
        copy MbusRtuMasterProtocol.hpp ..\include
        1 file(s) copied.
        copy MbusAsciiMasterProtocol.hpp ..\include
        1 file(s) copied.
        copy MbusTcpMasterProtocol.hpp ..\include
        1 file(s) copied.
        copy MbusRtuOverTcpMasterProtocol.hpp ..\include
        1 file(s) copied.
        del ..\lib\win\win32\release\libmbusmaster.lib
        md ..\lib\win\win32\release
A subdirectory or file ..\lib\win\win32\release already exists.
        lib.exe -out:..\lib\win\win32\release\libmbusmaster.lib  ..\obj\win\win3
2\release\hmcrc16.obj ..\obj\win\win32\release\hmhex.obj ..\obj\win\win32\releas
e\hmtimer.obj ..\obj\win\win32\release\hmserio.obj ..\obj\win\win32\release\BusP
rotocolErrors.obj ..\obj\win\win32\release\MbusMasterFunctions.obj ..\obj\win\wi
n32\release\MbusTcpMasterProtocol.obj ..\obj\win\win32\release\MbusSerialMasterP
rotocol.obj ..\obj\win\win32\release\MbusAsciiMasterProtocol.obj ..\obj\win\win3
2\release\MbusRtuMasterProtocol.obj ..\obj\win\win32\release\MbusRtuOverTcpMaste
rProtocol.obj ..\obj\win\win32\release\MbusMasterCexports.obj
Microsoft (R) Library Manager Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.


Library successfully compiled.

The rebuilt library libmbusmaster.lib has been placed in the directory lib\win\win32\release, the library include files can be found in the directory include.

Trouble shooting the Modbus communication using trace

The library has a tracing feature which logs all communication events and raw data to standard output. To use this trace feature, the library needs to be recompiled with the TRACELOG definition defined.

TRACELOG: Open port: COM1
TRACELOG: Parameters: 9600, 8, 1, 0
TRACELOG: Configuration: 1000, 0, 0
TRACELOG: Frame silence: 5
TRACELOG: Read multiple registers 1 100
TRACELOG: Send(6): 01 03 00 63 00 0A   <1>
TRACELOG: Recv(5): 01 83 01 80 F0      <2>
  1. Raw data sent on the serial port

  2. Raw data received on the serial port

In Visual Studio, trace can be enabled by defining the TRACELOG preprocessor definition from the C/C++ Preprocessor property pages as shown below:

Enabling trace log

Using nmake, TRACELOG can be defined by passing a tracelog parameter (all lower caps) to the makefile as follows:

nmake tracelog=1

Copyright © 2007-2008 proconX Pty Ltd. All rights reserved.

No part of this material may be reproduced or transmitted in any form or by any means or used to make any derivative work without express written consent from the copyright holders.

proconX and FieldTalk are trademarks of proconX Pty Ltd. All other product and brand names mentioned in this document may be trademarks or registered trademarks of their respective owners.

Disclaimer

proconX Pty Ltd makes no warranty for the use of its products, other than those expressly contained in the Company's standard warranty which is detailed in the Terms and Conditions located on the Company's Website. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of proconX are granted by the Company in connection with the sale of proconX products, expressly or by implication. proconX products are not authorized for use as critical components in life support devices or systems.

Support & product feedback

We provide an electronic support and feedback system for our FieldTalk products. It can be accessed through the following web link:

Your feedback and comments are always welcome. It helps improving this product.

Contact

For further information about this document please contact us at:

proconX Pty Ltd PO Box 791 Sumner QLD 4074 Australia Website: http://www.proconx.com