Mar 31, 2014 0 Comments in Learning, Misc, MODBUS by
modbusfs: the MODBUS filesystem

Modbusfs allow users to see all MODBUS clients connected with a MODBUS master as a filesystem tree, where directories are named as the client’s MODBUS address and files are the clients’ registers.

With modbusfs users can use their preferred programming languages even if they do not have any dedicated MODBUS support!

In fact users simply use file related system calls (i.e. open(), close(), read(), write(), etc.) to get access to the MODBUS clients’ register.

[Note: ths projects is still in beta version so refer to the “known bugs” section for further info! DO NOT USE in production environment!!!]

First of all you need a running Debian OS on your Cosino then you need the modbusfs project from our github site. But let’s install needed programs first!

# aptitude install libmodbus-dev libfuse-dev make gcc git-core

Package git-core is need to clone our code, in fact now you must clone the Cosino’s modbusfs project from GitHUB:

# git clone https://github.com/cosino/modbusfs.git

here what you should get after cloning:

# cd modbusfs/
# ls
Makefile README.md methods.c modbusfs.c modbusfs.h

To compile the tools just use:

# make
...
cc modbusfs.o methods.o -lfuse -lmodbus -o modbusfs

when finished you should have a new program named modbusfs. Usage is quite simple, just use command:

$ ./modbusfs rtu:/dev/ttyUSB0,115200,8E1 serial_0/
$ ls serial_0/
exports

The connection type argument is self explanatory. It asks for a RTU MODBUS connection throught device /dev/ttyUSB0 at 115200 baud transfer rate with 8 bits, even parity and 1 stop bit.

After the mount you have only the exports file which can be used to add new clients to the filesystem (that is new directories). So, for instance, if you have a client at address 10 you can add it by using:

$ echo 10 0755 > serial_0/exports

where 10 is the slave’s address and 0755 is the file access permissions. Here the result:

$ ls -l serial_0
total 0
drwxr-xr-x 2 giometti staff 0 Jan 1 1970 10/
--w------- 1 giometti staff 0 Jan 1 1970 exports

Now we have a new directory referring to the MODBUS slave at address 10! Let’s that a look at it:

$ ls -l serial_0/10
total 0
--w------- 1 giometti staff 0 Jan 1 1970 exports

This time the exports file can be used to add new files referring to the client’s register. For instance I can add a read-only register at address 8 by using:

$ echo 8 0444 > serial_0/10/exports
$ ls -l serial_0/10/
total 0
-r--r--r-- 1 giometti staff 4 Jan 1 1970 8
--w------- 1 giometti staff 0 Jan 1 1970 exports

Now you can easily read the client’s register by using standard file related system calls! For instance, using bash you can do:

$ cat serial_0/10/8 ; echo -e
0

[The echo command is just to add a newline at the end of cat’s output for better readability]

On the other way if you need writing on read-write register 13 you can do:

$ echo 13 0666 > serial_0/10/exports
$ cat serial_0/10/13 ; echo -e
afc8
$ echo afc9 > serial_0/10/13
$ cat serial_0/10/13 ; echo -e
afc9

For further info see the modbusfs project from our github site.

Facebooktwitterlinkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

68 − = 63