Advertisement
Guest User

arduino modbus

a guest
May 30th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. /**
  2.  *  Modbus slave example 1:
  3.  *  The purpose of this example is to link a data array
  4.  *  from the Arduino to an external device.
  5.  *
  6.  *  Recommended Modbus Master: QModbus
  7.  *  http://qmodbus.sourceforge.net/
  8.  */
  9.  
  10. #include <ModbusRtu.h>
  11.  
  12. // data array for modbus network sharing
  13. uint16_t au16data[16] = {
  14.   3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };
  15.  
  16. /**
  17.  *  Modbus object declaration
  18.  *  u8id : node id = 0 for master, = 1..247 for slave
  19.  *  u8serno : serial port (use 0 for Serial)
  20.  *  u8txenpin : 0 for RS-232 and USB-FTDI
  21.  *               or any pin number > 1 for RS-485
  22.  */
  23. Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI
  24.  
  25. void setup() {
  26.   slave.begin( 115200 ); // baud-rate at 115200
  27. }
  28.  
  29. void loop() {
  30.   slave.poll( au16data, 16 );
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement