WWW.DDROV.COM |
|
Last Update: 2013-03-17 Contact Info: ![]() Downloads: CmdModbusStuff |
Command Line Linux Modbus Commands I was just looking for a way to do modbus messaging from the command line. I ran into the libmodbus project but they had no pre-built tools to use without writing some code and compiling it. So I wrote some tools myself using their library. I don't do much Linux programming so this may be messy but it works for me. If you find it helpful then I'm glad to give something back to the Linux community. How I setup a Development Environment. You must start by loading the libmodbus libraries. I did this from a command line with the usual. ('./configure', 'make', as root 'make install'). Then once that is done I still had trouble running my code. I kept getting "error while loading shared libraries: libmodbus.so.5: cannot open shared object file: No such file or directory". Some looking around I found I needed to run 'ldconfig' as root. This must make the system recognize the newly installed libmodbus library. I used command line for editing first. To compile I had to use (cc `pkg-config --cflags --libs libmodbus` -o modbus_write_registers modbus_write_registers.c) for example. Then I moved on to Kdevelop. I had to learn to create a makefile that contained the compile commands for the code I wrote. Like this: cc `pkg-config --cflags --libs libmodbus` -o modbus_write_registers modbus_write_registers.c cc `pkg-config --cflags --libs libmodbus` -o modbus_read_registers modbus_read_registers.c cc `pkg-config --cflags --libs libmodbus` -o modbus_write_regserial modbus_write_regSerial.c I believe I then had to tell Kdevelop to use the make file but honestly can't remember. I think it may have been in project settings. If you have trouble just download my kdevelop project which should have the settings in it. I appreciate any feedback for this web site to make it easier for the next person. If you want to help, need help, or have comments or questions please contact me. My e-mail is to the left as a graphic. These tools have allowed me to do modbus testing using the command line. Control modbus I/O from my shell scripts etc. The Commands so far: modbus_read_registers ip port StartReg NumOfRegs example: modbus_read_registers 192.168.1.100 502 0 4 reply would be: val1 val2 val3 val4 separated by spaces modbus_write_registers ip port StartReg NumOfRegs Data1... modbus_write_registers 192.168.1.100 502 0 4 1 2 3 4 modbus_write_regserial |