Giter Club home page Giter Club logo

modbusrtu-1's Introduction

About

The ModbusRTU library is a simple to use library that allows an arduino to act as a Modbus slave. It attempts to obscure all unnecessary parts of the protocol to provide a clean interface.

The library pre-allocates all necessary memory upon instantiation, which improves the performance of the library and allows for simpler diagnostics.

Support

Slave ID's are supported, it is therefore possible to have multiple slaves on the same bus.

Entities

  • Discrete Inputs
  • Coils
  • Input Registers
  • Holding Registers

Function Codes

  • 1 - Read Coils
  • 2 - Read Discrete Inputs
  • 3 - Read Multiple Holding Registers
  • 4 - Read Input Registers
  • 5 - Write Single Coil
  • 6 - Write Single Holding Register
  • 15 - Write Multiple Coils
  • 16 - Write Multuple Holding Registers

Exception Functionality

  • Exception Response Codes
    • 1 - Illegal Function
    • 2 - Illegal Data Address
    • 3 - Illegal Data Value

Documentation

Whole libary is enclosed in a namespace called ModbusRTU.

ModbusRTUSlave Class

The class is a template class with one parameter called registerCount. The parameter specifies the size of the register array or maximum register count.

Members

   void begin(unsigned long baud, HardwareSerial *pHardwareSerial = &Serial, unsigned char slaveId = 1)

The begin function sets up variables and configures the hardware serial class.

  • Parameters
    • baud: The baud rate the serial interface should run at.
    • pHardwareSerial: Pointer to a HardwareSerial instance. Defaults to &Serial.
    • slaveId: Slave ID to be used by this slave. Defaults to 1.
   void update()

The function checks for incoming frames from master, attempts to parse the frame upon receiving, thereafter returns the result to the master. The parsing includes reading/writing to the modbus entites. If parsing a frame fails, the slave will attempt to send an exception.

   long addCoil(bool *coil, unsigned short _register)

The function adds a coil to the register array.

  • Parameters
    • coil: Pointer to a read/write boolean value.
    • _register: The register number to be assigned to the coil.
  • Return value
    • Returns the register number upon success.
    • Returns -1 upon failure.
   long addDiscreteInput(const bool *discreteInput, unsigned short _register)

The function adds a discrete input to the register array.

  • Parameters
    • discreteInput: Pointer to a read-only boolean value.
    • _register: The register number to be assigned to the discrete input.
  • Return value
    • Returns the register number upon success.
    • Returns -1 upon failure.
   long addInputRegister(const short *inputRegister, unsigned short _register)

The function adds an input register to the register array.

  • Parameters
    • inputRegister: Pointer to a read-only 16-bit value.
    • _register: The register number to be assigned to the input register.
  • Return value
    • Returns the register number upon success.
    • Returns -1 upon failure.
   long addHoldingRegister(short *holdingRegister, unsigned short _register)

The function adds an input register to the register array.

  • Parameters
    • holdingRegister: Pointer to a read/write 16-bit value.
    • _register: The register number to be assigned to the holding register.
  • Return value
    • Returns the register number upon success.
    • Returns -1 upon failure.

modbusrtu-1's People

Contributors

cewbdex avatar norgor avatar per1234 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.