libmodbus Windows下的编译使用

2024-03-12 13:04

本文主要是介绍libmodbus Windows下的编译使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.下载libmodbus

官方下载地址如下,可以使用git下载或者直接下载zip包
libmodbus下载地址、

2.编译运行

下载到本地文件目录是这样子的
在这里插入图片描述
windows下编译需要进入到src/win32下点击configure.js,生成对应的config.h等文件
大部分人是这步出现问题,报错

C: local\libmodbus-3.1.4 libmodbus-master src win32 configurejs
50
文件未找到
错误:
800A0035
代码源Microsoft JScript 运行时错误

这里就要修改configure.js脚本文件。原因是脚本里识别相对路径出现问题,导致找不到对应的文件,这里把里面的相对路径全部改成绝对路径。我把改好的脚本文件放到下面,里面路径要改成你们的。使用文本编辑器编辑脚本文件,做修改如下:

/* Configure script for modbus.dll, specific for Windows with Scripting Host.** Inspired by configure.js from libxml2** oldfaber  < oldfaber _at_ gmail _dot_ com >**//* The source directory, relative to the one where this file resides. */
//var srcDir = "..";
var srcDir = "G:\\Kits\\libmodbus-master\\libmodbus-master\\src";
/* Base name of what we are building. */
var baseName = "modbus";
/* Configure file template and output file */
var configFile = "G:\\Kits\\libmodbus-master\\libmodbus-master\\configure.ac";
//var configFile = srcDir + "\\..\\configure.ac";
/* Input and output files for the modbus-version.h include */
var newfile;
/* Version strings for the binary distribution. Will be filled later in the code. */
var verMajor;
var verMinor;
var verMicro;
/* modbus features. */
var dryRun = false;
/* Win32 build options. NOT used yet */
var compiler = "msvc";
/* Local stuff */
var error = 0;
/* Filename */
var newFile;/* Displays the details about how to use this script. */
function usage() {var txt;txt = "Usage:\n";txt += "  cscript " + WScript.ScriptName + " <options>\n";txt += "  cscript " + WScript.ScriptName + " help\n\n";txt +="Options can be specified in the form <option>=<value>, where the value is\n";txt += "either 'yes' or 'no', if not stated otherwise.\n\n";txt +="\nModbus library configure options, default value given in parentheses:\n\n";txt +="  dry-run:  Run configure without creating files (" +(dryRun ? "yes" : "no") +")\n";txt += "\nWin32 build options, default value given in parentheses:\n\n";txt += "  compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";WScript.Echo(txt);
}/* read the version from the configuration file */
function readVersion() {var fso, cf, ln, s;fso = new ActiveXObject("Scripting.FileSystemObject");cf = fso.OpenTextFile(configFile, 1);while (cf.AtEndOfStream !== true) {ln = cf.ReadLine();s = new String(ln);if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {verMajor = s.substr(s.indexOf(",") + 3, 1);} else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {verMinor = s.substr(s.indexOf(",") + 3, 1);} else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {verMicro = s.substr(s.indexOf(",") + 3, 1);}}cf.Close();
}/* create the versioned file */
function createVersionedFile(newfile, unversioned) {var fso, ofi, of, ln, s;fso = new ActiveXObject("Scripting.FileSystemObject");ofi = fso.OpenTextFile(unversioned, 1);if (!dryRun) {of = fso.CreateTextFile(newfile, true);}while (ofi.AtEndOfStream !== true) {ln = ofi.ReadLine();s = new String(ln);if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));} else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));} else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));} else if (!dryRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/,verMajor + "." + verMinor + "." + verMicro));} else {if (!dryRun) {of.WriteLine(ln);}}}ofi.Close();if (!dryRun) {of.Close();}
}/** main(),* Execution begins here.*/// Parse the command-line arguments.
for (i = 0; i < WScript.Arguments.length && error === 0; i++) {var arg, opt;arg = WScript.Arguments(i);opt = arg.substring(0, arg.indexOf("="));if (opt.length > 0) {if (opt == "dry-run") {var str = arg.substring(opt.length + 1, arg.length);if (opt == 1 || opt == "yes") {dryRun = true;}} else if (opt == "compiler") {compiler = arg.substring(opt.length + 1, arg.length);} else {error = 1;}} else if (i === 0) {if (arg == "help") {usage();WScript.Quit(0);}} else {error = 1;}
}// If we fail here, it is because the user supplied an unrecognised argument.
if (error !== 0) {usage();WScript.Quit(error);
}// Read the the version.
readVersion();
if (error !== 0) {WScript.Echo("Version discovery failed, aborting.");WScript.Quit(error);
}newfile = srcDir + "\\modbus-version.h";
createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
if (error !== 0) {WScript.Echo("Creation of " + newfile + " failed, aborting.");WScript.Quit(error);
}
WScript.Echo(newfile + " created.");newfile = "G:\\Kits\\libmodbus-master\\libmodbus-master\\src\\win32\\modbus.dll.manifest";
createVersionedFile(newfile, "G:\\Kits\\libmodbus-master\\libmodbus-master\\src\\win32\\modbus.dll.manifest.in");
if (error !== 0) {WScript.Echo("Creation of " + newfile + " failed, aborting.");WScript.Quit(error);
}
WScript.Echo(newfile + " created.");newfile = "G:\\Kits\\libmodbus-master\\libmodbus-master\\src\\win32\\config.h";
createVersionedFile(newfile, "G:\\Kits\\libmodbus-master\\libmodbus-master\\src\\win32\\config.h.win32");
if (error !== 0) {WScript.Echo("Creation of " + newfile + " failed, aborting.");WScript.Quit(error);
}
WScript.Echo(newfile + " created.");WScript.Echo("\nLibmodbus configuration completed\n");

然后右击修改后的脚本文件,使用它打开
在这里插入图片描述

会出现弹窗创建了对应的文件
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
这就代表编译成功了。
然后将对应生成的.h文件汇总。最后通过vs studio2019编译对应的库文件就可以了。具体可以参考
libmodbus在Windows平台下安装与编译与测试

这篇关于libmodbus Windows下的编译使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/801341

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

git使用的说明总结

Git使用说明 下载安装(下载地址) macOS: Git - Downloading macOS Windows: Git - Downloading Windows Linux/Unix: Git (git-scm.com) 创建新仓库 本地创建新仓库:创建新文件夹,进入文件夹目录,执行指令 git init ,用以创建新的git 克隆仓库 执行指令用以创建一个本地仓库的

【北交大信息所AI-Max2】使用方法

BJTU信息所集群AI_MAX2使用方法 使用的前提是预约到相应的算力卡,拥有登录权限的账号密码,一般为导师组共用一个。 有浏览器、ssh工具就可以。 1.新建集群Terminal 浏览器登陆10.126.62.75 (如果是1集群把75改成66) 交互式开发 执行器选Terminal 密码随便设一个(需记住) 工作空间:私有数据、全部文件 加速器选GeForce_RTX_2080_Ti

【Linux 从基础到进阶】Ansible自动化运维工具使用

Ansible自动化运维工具使用 Ansible 是一款开源的自动化运维工具,采用无代理架构(agentless),基于 SSH 连接进行管理,具有简单易用、灵活强大、可扩展性高等特点。它广泛用于服务器管理、应用部署、配置管理等任务。本文将介绍 Ansible 的安装、基本使用方法及一些实际运维场景中的应用,旨在帮助运维人员快速上手并熟练运用 Ansible。 1. Ansible的核心概念