Академический Документы
Профессиональный Документы
Культура Документы
Overview
Output
Features
(http://playground.arduino.cc/Main/InterfacingWithHardware#Output)
The following Modbus functions
-
Input
(http://playground.arduino.cc/Main/InterfacingWithHardware#InputTOC)
User Interface
(http://playground.arduino.cc/Main/InterfacingWithHardware#ui)
- 0x02 - Read Discrete
-
Storage
Inputs
(http://playground.arduino.cc/Main/InterfacingWithHardware#Storage)
-
Communication
(http://playground.arduino.cc/Main/InterfacingWithHardware#Communication)
-
Power supplies
(http://playground.arduino.cc/Main/IntWithHW- 0x04
PwrSup)
-
General
(http://playground.arduino.cc/Main/InterfacingWithHardware#General)
- 0x10 - Write Multiple Registers
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
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
(http://playground.arduino.cc/Main/Participate#contribrules)
-
(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
ModbusMaster.o.
(http://playground.arduino.cc/Main/WikiSandbox)
Basic Editing
Support
(http://playground.arduino.cc/PmWiki/BasicEditing)
-
Documentation index
(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);
}
}
}
Share
NEWSLETTER
2016 Arduino
(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)