libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

add a sniffing function for RTU serial line modbus

Open gitaeuber opened this issue 6 years ago • 12 comments

Hi everybody,

for the network modbus there is the wireshark tool for sniffing. But there is none for the serial line (RS485) for the (Linux) console afaik.

Please add some functions to sniff the protokoll on serial lines. Maybe some functions like: modbus_sniff(ctx) that could be called by modbus_sniff_and_parse(ctx)

Thanks a lot and best regards.

gitaeuber avatar Mar 10 '18 20:03 gitaeuber

Patches are welcome. Do you think you could contribute something?

pboettch avatar Mar 10 '18 22:03 pboettch

Patches are welcome. Do you think you could contribute something?

I don't think I'm able to contribute useful code. I'm not really a coder. Sorry.

gitaeuber avatar Mar 11 '18 13:03 gitaeuber

Is a patch for this even actually welcome? it seems way out of scope

karlp avatar Mar 11 '18 14:03 karlp

Why not adding debug and analyze code to the library, for example in a tools-dir? We could still debate on a patch once it's there. IMHO.

pboettch avatar Mar 11 '18 16:03 pboettch

Hi there!

This is a try to introduce a function for sniffing on a serial line. It isn't complete yet. The attached diff is a patch against #define LIBMODBUS_VERSION 3.1.4

What do you think about this?

I get compiling errors I can't resolve. Could you help me?

.libs/modbus-data.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:(.data.rel.local+0x0): first defined here
.libs/modbus-rtu.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:/tmp/libmodbus/src/modbus.c:45: first defined here
.libs/modbus-tcp.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:/tmp/libmodbus/src/modbus.c:45: first defined here
collect2: error: ld returned 1 exit status
Makefile:447: recipe for target 'libmodbus.la' failed
make[2]: *** [libmodbus.la] Error 1
Makefile:500: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
Makefile:386: recipe for target 'all' failed
make: *** [all] Error 2

Thanks and best regards Lars sniff_serial.diff.gz

PS: Is there an open mailinglist somewhere? I don't have a google account and don't want one.

gitaeuber avatar Mar 16 '18 08:03 gitaeuber

Please use Github's Pull-request feature for code-reviews. (Clone this repo onto your account, push to it and then "Create Pull Request")

pboettch avatar Mar 16 '18 08:03 pboettch

Hi,

I'm not sure if understood you correctly. Here is a pull request I managed to create against my own repo: https://github.com/gitaeuber/libmodbus/pull/1 I could not manage to create a pull request to the original libmodbus repo. And I don't like to do this either, because the patch doesn't compile.

Thanks

gitaeuber avatar Mar 16 '18 09:03 gitaeuber

Just mention in your PR that it doesn't work and that you just want a review. People are generally nice here because all useful contribution efforts are seen as a great thing.

pboettch avatar Mar 16 '18 10:03 pboettch

I managed to make a pull request. I had to fork the repo to my account first. Thanks

gitaeuber avatar Mar 16 '18 10:03 gitaeuber

That's what I wanted to say with clone to your account. Fork is the right word.

pboettch avatar Mar 16 '18 10:03 pboettch

Hello

I've got a use case where I need to monitor traffic between two endpoints without putting additional traffic on the bus Has this functionality been made available in the general library?

embcla avatar Jan 20 '21 16:01 embcla

QModMaster uses two custom callbacks to implement Bus Monitor functionality:

//***Not part of libmodbus - added for QModMaster***//
busMonitorRawRequestData(msg, msg_length);
//***Not part of libmodbus - added for QModMaster***//
busMonitorRawResponseData(msg, msg_length);

Do you think it makes sense to add registration of such callbacks? For example, something like this:

typedef void modbus_raw_monitor_handler(uint8_t* data, int len);

int modbus_add_raw_request_monitor(modbus_raw_monitor_handler* handler);
int modbus_add_raw_response_monitor(modbus_raw_monitor_handler* handler);

gresolio avatar Feb 22 '23 15:02 gresolio