Use ModBus with Raspberry Pi

The best lib for ModBus over RS485: libmodbus (Link)

Installation:

Search already-done package for raspbian

sudo apt-cache search libmodbus

Install your favorite version. Dev if you want .h file:

sudo apt-get install libmodbus-dev

or standard for end-user

sudo apt-get install libmodbus5

Code Example

  //ModBusRequest Example
  #include <modbus.h>  

  modbus_t *mb;
  uint16_t tab_reg[32];

  mb = modbus_new_tcp("127.0.0.1", 1502);
  modbus_connect(mb);

  /* Read 5 registers from the address 0 */
  modbus_read_registers(mb, 0, 5, tab_reg);

  modbus_close(mb);
  modbus_free(mb);

Lascia un commento