Skip to content

Commit

Permalink
Updated ReadMe
Browse files Browse the repository at this point in the history
  • Loading branch information
SRGDamia1 committed Sep 22, 2017
1 parent b682781 commit 5cc024b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SensorModbusMaster

This library is designed to use an Arduino as a modbus master to communicate with a sensor/slave via modbus RTU. It's specifically written with lots of "higher-level" functions to help out users who are largely unfamiliar with modbus.

Modbus is a serial communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). ([wikipedia](https://en.wikipedia.org/wiki/Modbus))
This library is designed to use an Arduino as a modbus master to communicate with a sensor/slave via [modbus RTU](https://en.wikipedia.org/wiki/Modbus). It's specifically written with lots of "higher-level" functions to help out users who are largely unfamiliar with the modbus protocol and want an easy way to get information from a modbus device.
_____

## Using the library
Expand Down Expand Up @@ -59,9 +57,22 @@ _____


## Notes on modbus maps
While modbus RTU specifications define the format of a data frame and a very simple data structure for a master and slave, there are no specification for what types of data a slave stores, where it is stored, or in what format it is stored. You **MUST** get this information from the manufacture/programmer of your modbus device. Typically this information is shared in what is called a modbus map. You will also need to know the baud rate and parity the device uses on the serial line. Without this information, you have little hope of being able to communicate properly with the device. You can use programs like [CAS modbus scanner](http://www.chipkin.com/cas-modbus-scanner/) to find a device if its address, baud rate, and parity are unknown, but it may take some time to make a connection. You can also use the "scanRegisters" utility in this library to get a view of all the registers, but if you don't have a pretty good idea of what you are looking for that will not be as helpful as you might hope.
While modbus RTU specifications define the format of a data frame and a very simple data structure for a master and slave, there are no specification for what types of data a slave stores, where it is stored, or in what format it is stored. You **MUST** get this information from the manufacture/programmer of your modbus device. Typically this information is shared in what is called a modbus map.

You need the following data from your modbus map:
- the baud rate the device communicaes at (modbus allows any baud rate)
- the parity the device uses on the serial line (modbus technically allows 8O1, 8E1, and 8N2, though some devices may use 8N1)
- the type of register or coils the data you are interested is stored in (ie, holding register, input register, coil, or discrete input)
- Note - This library does not currently support getting or setting values in coils.
- the register or coil number the data is stored in
- the format of data within the registers/coils (ie, float, integer, bitmask, ascii text)
- whether multi-register numeric data is stored as ["big-endian" or "little-endian"](https://en.wikipedia.org/wiki/Endianness) values (That is, is it high _word_ first or low _word_ first. There are no specifications for this.)
- whether single-register data is stored "big-endian" or "little-endian" (That is, is it high _byte_ first or low _byte_ first. Modbus specifies that it should be high byte first (big-endian), but devices vary.)
- Note - This library only supports data that is "fully" big or little endian. That is, data must be both high byte and high word first or both low byte and low word first.

Without this information, you have little hope of being able to communicate properly with the device. You can use programs like [CAS modbus scanner](http://www.chipkin.com/cas-modbus-scanner/) to find a device if its address, baud rate, and parity are unknown, but it may take some time to make a connection. You can also use the "scanRegisters" utility in this library to get a view of all the registers, but if you don't have a pretty good idea of what you are looking for that will not be as helpful as you might hope.
_____


## Notes on RS485
Again, while modbus RTU specifications define the format of a data frame transfered over a serial line, the type of serial signal is not defined. Many modbus sensors communicate over [RS-485](https://en.wikipedia.org/wiki/RS-485). To interface with them, you will need an RS485-to-TLL adapter. There are a number of RS485-to-TLL adapters available. When shopping for one, be mindful of the logic level of the TLL output by the adapter. The MAX485, one of the most popular adapters, has a 5V logic level in the TLL signal. This will _fry_ any board that can only use on 3.3V logic. You would need a voltage shifter in between the Mayfly and the MAX485 to make it work. You will also need an interface board to communicaet between an Arduino and any modbus sensor that communicates over RS232. Again, mind your voltages.
## TTL and RS485/RS322
Again, while modbus RTU specifications define the format of a data frame transfered over a serial line, the type of serial signal is not defined. Many modbus sensors communicate over [RS-485](https://en.wikipedia.org/wiki/RS-485). To interface with them, you will need an RS485-to-TLL adapter. There are a number of RS485-to-TLL adapters available. When shopping for one, be mindful of the logic level of the TLL output by the adapter. The MAX485, one of the most popular adapters, has a 5V logic level in the TLL signal. This will _fry_ any board that can only use on 3.3V logic. You would need a voltage shifter in between the Mayfly and the MAX485 to make it work. You will also need an interface board to communicate between an Arduino and any modbus sensor that communicates over [RS422](https://en.wikipedia.org/wiki/RS-422) or [RS232](https://en.wikipedia.org/wiki/RS-232). Again, mind your voltages.
2 changes: 1 addition & 1 deletion src/SensorModbusMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class modbusMaster
// Per modbus specifications, the stream must have:
// - 1 start bit
// - 8 data bits, least significant bit sent first
// - 1 stop bit if parity is used-2 bits if no parity
// - 1 stop bit if parity is used - 2 bits if no parity
// Note that neither SoftwareSerial, AltSoftSerial, nor NeoSoftwareSerial
// will support either even or odd parity!
bool begin(byte modbusSlaveID, Stream *stream, int enablePin = -1);
Expand Down

0 comments on commit 5cc024b

Please sign in to comment.