Вы находитесь на странице: 1из 3

Search the Arduino Playground

Manuals and Curriculum


(http://playground.arduino.cc/Main/ManualsAndCurriculum)
ModbusMaster Library for Arduino
Arduino StackExchange
Author: Doc Walker
(http://arduino.stackexchange.com)
Contact: 4-20ma at wvfans dot net
Board Setup and Conguration
(http://playground.arduino.cc/Main/ArduinoCoreHardware)
Development Tools
(http://playground.arduino.cc/Main/DevelopmentTools)
This is an Arduino library for communicating with Modbus slaves over RS232/485 (via RTU protocol).
Arduino on other Chips
Updated to support Arduino 1.0.
(http://playground.arduino.cc/Main/ArduinoOnOtherAtmelChips)
Interfacing With Hardware
(http://playground.arduino.cc/Main/InterfacingWithHardware)

Overview

Output

Features

(http://playground.arduino.cc/Main/InterfacingWithHardware#Output)
The following Modbus functions
-

have been implemented:

Input
(http://playground.arduino.cc/Main/InterfacingWithHardware#InputTOC)

User Interface

0x01 - Read Coils

(http://playground.arduino.cc/Main/InterfacingWithHardware#ui)
- 0x02 - Read Discrete
-

Storage

Inputs

0x05 - Write Single Coil

0x0F - Write Multiple Coils

(http://playground.arduino.cc/Main/InterfacingWithHardware#Storage)
-

Communication

(http://playground.arduino.cc/Main/InterfacingWithHardware#Communication)
-

Power supplies

0x03 - Read Holding Registers

(http://playground.arduino.cc/Main/IntWithHW- 0x04
PwrSup)
-

General

- Read Input Registers

0x06 - Write Single Register

(http://playground.arduino.cc/Main/InterfacingWithHardware#General)
- 0x10 - Write Multiple Registers

Interfacing with Software


- 0x16 - Mask Write Register
(http://playground.arduino.cc/Main/InterfacingWithSoftware)
User Code Library
- 0x17 - Read Write Multiple Registers
(http://playground.arduino.cc/Main/GeneralCodeLibrary)
-

Snippets and Sketches

Uploading Sketches

(http://playground.arduino.cc/Main/SketchList)
-

Libraries

Arduinos prior to the Mega have one serial port which must be connected to USB (FTDI) for uploading
and to the RS232/485 device/network for running sketches. You will need to disconnect pin 0
(RX) while uploading sketches. After a successful upload, you can reconnect pin 0.

sketches
(http://playground.arduino.cc/Main/LibraryList)
-

Tutorials

(http://playground.arduino.cc/Main/TutorialList)

Hardware

Suggestions & Bugs


(https://github.com/arduino/arduino/issues)
Electronics Technique
This library has been tested with an Arduino Duemilanove
(http://playground.arduino.cc/Main/ElectroInfoResources)
(http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove), PHOENIX CONTACT nanoLine
Sources for Electronic Parts
(http://www.phoenixcontact.com/automation/34197.htm) controller, connected via RS485 using a
(http://playground.arduino.cc/Main/Resources)
Related Hardware and Initiatives
Maxim MAX488EPA (http://www.maxim-ic.com/quick_view2.cfm/qv_pk/1111) transceiver.
(http://playground.arduino.cc/Main/SimilarBoards)
Arduino People/Groups & Sites
(http://playground.arduino.cc/Main/People)
Exhibition
(http://playground.arduino.cc/Projects/ArduinoUsers)
The latest version can be downloaded from Github (https://github.com/4-20ma/ModbusMaster).
Project Ideas
(http://playground.arduino.cc/Projects/Ideas)
Languages
Arduino 17 (or later)
(http://playground.arduino.cc/Main/Languages)

Installation

Determine the location of your sketchbook by selecting File > Preferences from within the Arduino IDE.

Participate
(http://playground.arduino.cc/Main/Participate)
If you don't already have a libraries folder within your sketchbook, create one and unzip the archive
-

Formatting guidelines

there. See this (http://arduino.cc/blog/?p=313) for more information.

(http://playground.arduino.cc/Main/Participate#contribrules)
-

All recent changes

Arduino 16 (or earlier)

(http://playground.arduino.cc/Site/AllRecentChanges)

PmWiki

Download the zip le, extract and copy the ModbusMaster folder to

(http://playground.arduino.cc/PmWiki/PmWiki)
-

WikiSandBox training

ARDUINO_HOME/hardware/libraries. If you are upgrading from a previous version, be sure to delete

ModbusMaster.o.
(http://playground.arduino.cc/Main/WikiSandbox)
Basic Editing

Support

(http://playground.arduino.cc/PmWiki/BasicEditing)
-

Documentation index

Please report any bugs on the Issue Tracker (https://github.com/4-20ma/ModbusMaster/issues).

(http://www.pmwiki.org/wiki/PmWiki/DocumentationIndex)

Questions/Feedback
I can be contacted at 4-20ma at wvfans dot net.

Example
The library contains a few sketches that demonstrate use of the ModbusMaster library. You can nd
these in the examples (https://github.com/4-20ma/ModbusMaster/tree/master/examples) folder.
/*
Basic.pde - example using ModbusMaster library
This file is part of ModbusMaster.
ModbusMaster is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ModbusMaster is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ModbusMaster. If not, see <http://www.gnu.org/licenses/>.
Written by Doc Walker (Rx)
Copyright 2009-2012 Doc Walker <4-20ma at wvfans dot net>
*/
#include <ModbusMaster.h>
// instantiate ModbusMaster object as slave ID 2
// defaults to serial port 0 since no port was specified
ModbusMaster node(2);

void setup()
{
// initialize Modbus communication baud rate
node.begin(19200);
}

void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
// set word 0 of TX to least-significant word of counter (bits 15..0)
node.TX(0, lowWord(i));
// set word 1 of TX to most-significant word of counter (bits 31..16)
node.TX(1, highWord(i));
// slave 1: write TX to (2) 16-bit registers starting at register 0
result = node.WriteMultipleRegisters(0, 2);
// slave 1: read (6) 16-bit registers starting at register 2 to RX
result = node.ReadHoldingRegisters(2, 6);
// do something with data if read is successful
if (result == node.ku8MBSuccess)
{
for (j = 0; j < 6; j++)
{
data[j] = node.RX(j);
}
}
}

Project inspired by Arduino Modbus Master (http://sites.google.com/site/jpmzometa/arduinombrt/arduino-modbus-master).

Share

NEWSLETTER

Enter your email to sign up

2016 Arduino

Copyright Notice (https://arduino.cc/en/Main/CopyrightNotice)

(https://twitter.com/arduino)

Contact us (https://arduino.cc/en/Main/ContactUs)

(http://www.facebook.com/ocial.arduino)

(http://www.ickr.com/photos/arduino_cc)

(http://youtube.com/arduinoteam)

(https://plus.google.com/+Arduino)

Вам также может понравиться