Create Project
Launch Visual Studio, select [New]-[Project] from [File] menu.
From the [Templates] of [New Project] dialog box, select [MFC Application] of [Visual C++],
and specify the name and location of the project to be created.
Click the [OK] button to the next dialog.
[MFC Application Wizard] dialog is displayed.
Select [Application Type], change it to be [Dialog based].
Click the [Finish] button and the project is created.
* Item names and commands may differ depending on the version of Visual Studio.
Include Header File
In order to use libmodbus functions in Visual C++, the following files are required.
Include the header files in the source code.
Specify the include at the beginning of the C++ file that will use the functions.
- For ModbusTCP
#include "modbus.h"
#include "modbus-tcp.h"
- For ModbusRTU
#include "modbus.h"
#include "modbus-rtu.h"
Add each file from [Project]-[Add Existing Item].
Include Library File
For Visual C++, in addition to the header file, the library file is also required to include.
Add modbus.lib from [Project]-[Add Existing Item].