Libmodbus Visual Studio Build & Test

posted Oct 20, 2014, 8:05 AM by Javad Taghia   [ updated Oct 20, 2014, 8:05 AM ]
After building as explained in the previous post. We have modbus.lib and modbus.dll. 
Now it's time to test. 
There is a directory named test in the file attached to the previous post. In that there is a README and explained the functionality of the programs. However it's not executable right away on Windows by VStudio. 
Here I cover how to setup VS to run the examples. I do it for random server and random client example. 
They use local ip and port 139 which is not assigned presumebly. You can check it via command line: netstat -a if you don't see the port 139 next to 127.0.0.1 then you are okay to use the attached project which are in VS2012. 
Okay now it's time to setup. 
1. Now you have a scr folder that has win32 in it and in win32 you got modbus.lib and modbus.dll. Put modbus.dll in the folder of your new project where the debug/release is called and the final exe file is going to place there. 
2. You need to add modbus.lib to the Input of the Linker from the properties of your new project. 
3. You need to add the path in VC directories for the lib to the src/win32 
4. you need to set the path in VC directories for the header files to src.
5. if you get some errors about linking and external issues add this line:
#pragma comment(lib, "Ws2_32.lib")
6. if you get error about close port add this lines:
#if defined(_WIN32)
#define close closesocket
#endif

Okay now it should be okay to build and run your projects. I have added a solution containing both server and client. And project containing the builder of the lib and dll to this post.

Download it from GoogleDrive: https://drive.google.com/file/d/0BxxliwIPgBT3ZUZ3MXJGN1o2LUU/view?usp=sharing

ċ
MyModBusPro.zip
(12076k)
Javad Taghia,
Oct 21, 2014, 1:12 AM
Comments