Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f33e9e
Add Makefiles
evgeny-boger Apr 28, 2014
9ec28ec
Add debian control directory
evgeny-boger Apr 28, 2014
4a03277
Fix ReadDiscreteInput.
ivan4th Jul 24, 2014
a737b80
Added set-rd-address.sh.
ivan4th Aug 5, 2014
33be25a
Added .gitignore.
ivan4th Aug 6, 2014
028536b
change changelog author to get signed package
evgeny-boger Sep 20, 2014
726dbdf
fix error in baud rate handling
evgeny-boger Jul 9, 2015
9764ac3
add source dependency
evgeny-boger Jul 9, 2015
9e23824
fix timeout handling
evgeny-boger Jul 22, 2015
d04647b
Revert "Added set-rd-address.sh."
evgeny-boger Dec 21, 2016
bc170ce
exit with EXIT_FAILURE in case Modbus request is failed
evgeny-boger Dec 21, 2016
0e8a52c
disable annoying "timeout is set" information message
evgeny-boger Dec 21, 2016
72a955a
added check if value to write is passed && port is string
Jan 27, 2019
8c89ff0
updated changelog
Jan 27, 2019
b71e381
Merge pull request #1 from contactless/feature/check_passed_value
evgeny-boger Mar 20, 2019
0488d86
add Jenkinsfile + bullseye build (#3)
webconn Aug 16, 2022
a327424
Fix response timeout option handled incorrectly (#4)
sikmir Dec 1, 2022
48e4964
fix IP address parse in arguments (#6)
webconn Jan 18, 2023
b9e0369
Build package for amd64 platform (#7)
sikmir Apr 3, 2023
5c9389f
Add arm64 build (#8)
sikmir Nov 16, 2023
3791fd0
Add homepage to deb package info (#9)
sikmir Jan 22, 2024
d997036
Win32 support (#10)
sikmir Nov 21, 2024
b1a8c74
Fix lintian (#11)
sikmir Apr 4, 2025
961579d
Fix build with gcc15 (#12)
sikmir Jun 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
debian/files
debian/modbus-utils*
modbus_client/modbus_client
modbus_server/modbus_server
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
buildDebSbuild defaultTargets: 'bullseye-armhf bullseye-host',
repos: ['release', 'devTools']
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
prefix=/usr

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CC=gcc
else
CC=$(DEB_HOST_GNU_TYPE)-gcc
endif

CC_FLAGS=-I../common -I/usr/include/modbus -L../common -lmodbus

all: client server

client:
$(MAKE) -C modbus_client

server:
$(MAKE) -C modbus_server

install: $(BIN_NAME)
$(MAKE) -C modbus_client install
$(MAKE) -C modbus_server install


clean:
$(MAKE) -C modbus_client clean
$(MAKE) -C modbus_server clean

.PHONY: install clean all
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ Both apps are linked with libmodbus library. After repository is pulled do the f
compilation
===========

#assumes you are in a root of the repository
#go to libmodbus dir and compile it
cd ./libmodbus
./configure
./make
#as a result *.so libraries are in export ./src/.libs/ directory

#get back to the root
cd ..
gcc ./modbus_client/modbus_client.c -I./common -I./libmodbus/src/ -L./libmodbus/src/.libs/ -lmodbus -o mbClient
gcc ./modbus_server/modbus_server.c -I./common -I./libmodbus/src/ -L./libmodbus/src/.libs/ -lmodbus -o mbServer
```sh
make
```

running
=======
Expand Down
2 changes: 1 addition & 1 deletion common/mbu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int setRtuParam(void *backend, char c, char *value) {
switch (c) {
case 'b': {
rtuParams->baud = getInt(value, &ok);
if (0 != ok) {
if (0 == ok) {
printf("Baudrate is invalid %s", value);
ok = 0;
}
Expand Down
71 changes: 71 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
modbus-utils (1.2.8) stable; urgency=medium

* Build deb package for amd64 platform, no functional changes

-- Nikolay Korotkiy <[email protected]> Mon, 03 Apr 2022 15:35:00 +0400

modbus-utils (1.2.7) stable; urgency=medium

* fix IP address parse in arguments

-- Nikita Maslov <[email protected]> Thu, 12 Jan 2023 21:03:16 +0600

modbus-utils (1.2.6) stable; urgency=medium

* Fix response timeout option handled incorrectly

-- Nikolay Korotkiy <[email protected]> Wed, 30 Nov 2022 19:51:00 +0400

modbus-utils (1.2.5) stable; urgency=medium

* rebuild of 1.2.4 for Debian bullseye (without source change)
* Makefile: make pkg-config work with multi-arch (for sbuild support)

-- Nikita Maslov <[email protected]> Fri, 29 Jul 2022 18:34:14 +0300

modbus-utils (1.2.4) stable; urgency=medium

* added check if any value is passed to write function
* improved parsing args for port

-- Vladimir Romanov <[email protected]> Sun, 27 Jan 2018 18:33:12 +0300

modbus-utils (1.2.3) stable; urgency=medium

* disable annoying "timeout is set" information message

-- Evgeny Boger <[email protected]> Wed, 21 Dec 2016 14:24:32 +0300

modbus-utils (1.2.2) stable; urgency=medium

* exit with EXIT_FAILURE in case Modbus request is failed

-- Evgeny Boger <[email protected]> Wed, 21 Dec 2016 13:16:41 +0300

modbus-utils (1.2.1) stable; urgency=medium

* fix timeout handling

-- Evgeny Boger <[email protected]> Wed, 22 Jul 2015 22:53:15 +0300

modbus-utils (1.2) stable; urgency=medium

* fix baud rate handling

-- Evgeny Boger <[email protected]> Thu, 09 Jul 2015 19:55:45 +0300

modbus-utils (1.1) wheezy; urgency=low

* Add set-rd-address.sh script
* Fix ReadDiscreteInput function
(was) Ivan Shvedunov <[email protected]> Wed, 06 Aug 2014 10:15:01 +0400

-- Evgeny Boger <[email protected]> Wed, 06 Aug 2014 10:15:01 +0400

modbus-utils (1.0) wheezy; urgency=low

* Initial debianization using https://github.com/Krzysztow/modbus-utils

-- Evgeny Boger <[email protected]> Tue, 29 Apr 2014 01:59:04 +0400


1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
11 changes: 11 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: modbus-utils
Maintainer: Evgeny Boger <[email protected]>
Section: misc
Priority: optional
Standards-Version: 3.9.2
Build-Depends: debhelper (>= 9), pkg-config, libmodbus-dev

Package: modbus-utils
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libmodbus5
Description: Modbus client and server command line tools based on libmodbus
Empty file added debian/copyright
Empty file.
2 changes: 2 additions & 0 deletions debian/modbus-utils.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/bin
usr/share/man/man1
3 changes: 3 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/make -f
%:
dh $@
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
1 change: 0 additions & 1 deletion libmodbus
Submodule libmodbus deleted from b09ff2
24 changes: 24 additions & 0 deletions modbus_client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
prefix=/usr
BIN_NAME=modbus_client

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CC=gcc
else
CC=$(DEB_HOST_GNU_TYPE)-gcc
endif

CC_FLAGS=-I../common `PKG_CONFIG_PATH=/usr/lib/$(DEB_HOST_GNU_TYPE)/pkgconfig pkg-config --libs --cflags libmodbus`

$(BIN_NAME): modbus_client.c
$(CC) modbus_client.c $(CC_FLAGS) -o $(BIN_NAME)


install: $(BIN_NAME)
install -Dm0755 $(BIN_NAME) -t $(DESTDIR)$(prefix)/bin

clean:
-@rm $(BIN_NAME)
.PHONY: install clean all



50 changes: 34 additions & 16 deletions modbus_client/modbus_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ int main(int argc, char **argv)
int c;
int ok;

int gotData = 0; //Data_to_write existance flag
int raw_data = 0; //While parsing not keyword args
int debug = 0;
BackendParams *backend = 0;
int slaveAddr = 1;
Expand Down Expand Up @@ -153,7 +155,6 @@ int main(int argc, char **argv)
printUsage(argv[0]);
exit(EXIT_FAILURE);
}
printf("Timeout set to %d\r\n", timeout_ms);
}
break;

Expand Down Expand Up @@ -194,14 +195,11 @@ int main(int argc, char **argv)
if (1 == startReferenceAt0) {
startAddr--;
}

//choose write data type
switch (fType) {
case(ReadCoils):
wDataType = Data8Array;
break;
case(ReadDiscreteInput):
wDataType = DataInt;
wDataType = Data8Array;
break;
case(ReadHoldingRegisters):
case(ReadInputRegisters):
Expand Down Expand Up @@ -256,8 +254,11 @@ int main(int argc, char **argv)
if (1 == debug && 1 == isWriteFunction)
printf("Data to write: ");
if (optind < argc) {

while (optind < argc) {
if (0 == hasDevice) {
raw_data = getInt(argv[optind], &ok);
if (0 == hasDevice && (ok == 0 || //Portname couldn't consist of only numbers
NULL != strchr(argv[optind], '.'))) { // but IP address fits in sscanf()
if (0 != backend) {
if (Rtu == backend->type) {
RtuBackend *rtuP = (RtuBackend*)backend;
Expand All @@ -271,21 +272,24 @@ int main(int argc, char **argv)
}
}
}
else {//setting write data buffer
else {//Got int as data => setting write data buffer
switch (wDataType) {
case (DataInt):
data.dataInt = getInt(argv[optind], 0);
data.dataInt = raw_data;
gotData = 1;
if (debug)
printf("0x%x", data.dataInt);
break;
case (Data8Array): {
data.data8[wDataIdx] = getInt(argv[optind], 0);
data.data8[wDataIdx] = raw_data;
gotData = 1;
if (debug)
printf("0x%02x ", data.data8[wDataIdx]);
}
break;
case (Data16Array): {
data.data16[wDataIdx] = getInt(argv[optind], 0);
data.data16[wDataIdx] = raw_data;
gotData = 1;
if (debug)
printf("0x%04x ", data.data16[wDataIdx]);
}
Expand All @@ -296,14 +300,28 @@ int main(int argc, char **argv)
optind++;
}
}
if (1 == debug && 1 == isWriteFunction)
printf("\n");

if (isWriteFunction == 1){
if (gotData == 0) {
printf("\nSeems you are using a write function\nDon't forget to specify the value!\n");
exit(EXIT_FAILURE);}
if (debug == 1)
printf("\n");
}

//create modbus context, and preapare it
modbus_t *ctx = backend->createCtxt(backend);
modbus_set_debug(ctx, debug);
modbus_set_slave(ctx, slaveAddr);

struct timeval response_timeout;
response_timeout.tv_sec = timeout_ms / 1000;
response_timeout.tv_usec = (timeout_ms % 1000) * 1000;
#if LIBMODBUS_VERSION_CHECK(3, 1, 2)
modbus_set_response_timeout(ctx, response_timeout.tv_sec, response_timeout.tv_usec);
#else
modbus_set_response_timeout(ctx, &response_timeout);
#endif
//issue the request
int ret = -1;
if (modbus_connect(ctx) == -1) {
Expand All @@ -317,8 +335,7 @@ int main(int argc, char **argv)
ret = modbus_read_bits(ctx, startAddr, readWriteNo, data.data8);
break;
case(ReadDiscreteInput):
printf("ReadDiscreteInput: not implemented yet!\n");
wDataType = DataInt;
ret = modbus_read_input_bits(ctx, startAddr, readWriteNo, data.data8);
break;
case(ReadHoldingRegisters):
ret = modbus_read_registers(ctx, startAddr, readWriteNo, data.data16);
Expand All @@ -344,8 +361,9 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
}
uint8_t success = (ret == readWriteNo);

if (ret == readWriteNo) {//success
if (success) {
if (isWriteFunction)
printf("SUCCESS: written %d elements!\n", readWriteNo);
else {
Expand Down Expand Up @@ -387,5 +405,5 @@ int main(int argc, char **argv)
break;
}

exit(EXIT_SUCCESS);
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
}
24 changes: 24 additions & 0 deletions modbus_server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
prefix=/usr
BIN_NAME=modbus_server

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CC=gcc
else
CC=$(DEB_HOST_GNU_TYPE)-gcc
endif

CC_FLAGS=-I../common `PKG_CONFIG_PATH=/usr/lib/$(DEB_HOST_GNU_TYPE)/pkgconfig pkg-config --libs --cflags libmodbus`

$(BIN_NAME):
$(CC) modbus_server.c $(CC_FLAGS) -o $(BIN_NAME)


install: $(BIN_NAME)
install -Dm0755 $(BIN_NAME) -t $(DESTDIR)$(prefix)/bin

clean:
-@rm $(BIN_NAME)
.PHONY: install clean all