4-20ma / modbusmaster Goto Github PK
View Code? Open in Web Editor NEWEnlighten your Arduino to be a Modbus master
Home Page: http://4-20ma.io/ModbusMaster/
License: Apache License 2.0
Enlighten your Arduino to be a Modbus master
Home Page: http://4-20ma.io/ModbusMaster/
License: Apache License 2.0
If this library works with ESP8266? I get this during compilation: This library only supports boards with an AVR or SAM processor. Please open an issue at https://github.com/4-20ma/ModbusMaster/issues and indicate which processor/platform you're using.
Hi,
I have used the library for my Arduino Mega2560 with Arduino IDE 1.0.5 r2.
It is working fine.
Couple of days before, I installed Arduino IDE 1.5.5 Beta. I compiled my project & upload to my Mega2560.
The library is not working. It can not get communicated to slave !! I tried simple serial program & it working fine. But this library is not working.
I was confused.
Then later on I decide to use Arduino IDE 1.0.5 r2. Now the library works fine.
So, I think, the library is not supported in Arduino 1.5.5 Beta.
This is For Your Information Only.
Thanks.
Dixit
0.11.0
any
any
any
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
CONTRIBUTING.md
Use HardwareSerial* MBSerial = &Serial
instead of HardwareSerial *MBSerial = &Serial;
.
This might also be true for the other Modbus Functions, however I am currently only using writeMultipleRegisters.
With version 0.10.3 (and also 0.10.2 & 0.9.1), using the milli() function, the time it takes to perform a node.setTransmitBuffer, followed by a node.writeMultipleRegisters is around 209 milliseconds. If I use exactly the same sketch with version 0.11.0 the difference is almost exactly 10 times slower at 2006 milliseconds.
Here is my code to check this:
void loop() {
static uint32_t i = 0;
static long previousMillis = 0;
unsigned long currentMillis = 0;
uint8_t result;
// put your main code here, to run repeatedly:
previousMillis = millis();
node.setTransmitBuffer(0, lowWord(i++));
result = node.writeMultipleRegisters(3960, 1);
currentMillis = millis();
Serial.println(currentMillis - previousMillis);
//delay(1000);
}
Per stroustrup.com style guide, replace Hungarian notation with more conventional notation.
On arduino yun i use the IDE 1.5.6-r2 ... but i get a problem with the library Error conversion from 'Serial_' to non scalar type ....
When the library will be ready for the new IDE ?
Hy,
is it possible to set the serial mode to SERIAL_8E1 with a baud rate of 9600 ?
I use it with arduino 1.6.9 with an ESP8266 v12 Module.
thank's a lot
Per Arduino style guide:
When using serial communication, allow the user to specify any Stream object, rather than hard-coding "Serial". This will make your library compatible all serial ports on Mega and the Due, and can also use alternate interfaces like SoftwareSerial. The Stream object can be passed to your library's constructor or to a begin() function (as a reference, not a pointer). See Firmata 2.3 or XBee 0.4 for examples of each approach.
Refer to http://www.arduino.cc/en/Reference/APIStyleGuide.
Changes:
Test with real hardware and signal tracer
I'm using your library for connection my Arduino Lenoardo ETH with another device via Modbus RTU.
Everything was going well before I come to my last function. This function have to write Float to 2 registers on the device.
I'm doing it with that function:
void WriteMultRegFloat(int adress,float Temp,int StartReg) { node.setTransmitBuffer(0x0,highWord(Temp)); node.setTransmitBuffer(0x1,lowWord(Temp)); node.writeMultipleRegisters(StartReg,2); node.clearTransmitBuffer(); }
And it crashes bootloader of my Arduino and I have to rewrite it with help of another Arduino via ICSP.
As a project user
I want to know what information is required to submit an issue
So that my issue may be resolved quickly
If I try to use Serial1, Serial2 or Serial3 on an Arduino Mega 2560 for the modbus master interface (e.g with:
ModbusMaster node(Serial1, 4);
the code does not work. Although 'MBSerial' is correctly set to 'Serial1', no output appears on TX1 and the code hangs on MBSerial.flush().
Changing all occurrences of MBSerial to Serial1 in the library works as a workaround for me.
(tested with Arduino IDE 1.5.5-r2)
Change:
This release will support Arduino >= 1.5.
Refer to https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification.
Make the following changes after source code changes have been merged.
COPYING
(GPLv3)LICENSE
(Apache-2.0)I used this code to read holding register with baud rate setup is 115200. it didn't work. If i set 57600 baud rate it work very good. I don't know this error from my Mega 2560 or modbus master code???
I wrote a test code to print "Hello world" with 115200 baud rate, It worked good????? please help me to check this problem??thanks.
Changes introduced with #29 are not yet reflected in the README.md
file. Update README to match included example sketches.
Reorder Installation section of README so it comes after Features and before Hardware. Rename Uploading Sketches section to Caveats.
As a project maintainer
I want documentation to be readily understood
So that users may quickly apply my library
Hi buddy (4-20mA),
I just found that your github ModbusMaster library perfectly match my needs. Namely, I have an ElNet LT Energy&Powermeter (http://www.getelnet.com/wordpress/2009/10/15/elnet-lt/) that supports Modbus RTU communication an has built-in Functions 03, 04, 06, and 16.
I'm also planning to use max485 ESA transceiver and Arduino Uno board.
Now, I would like to know is it possible to use your library with Arduino Uno board? I saw that you made testings by using Duemilanove board that is similar to Uno bot not the same.
Also, I'm confused how to connect max485 pins:
Thank you very much for your time and effort to help me.
Sincerely,
Bojan.
// code below.
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-2013 Doc Walker <4-20ma at wvfans dot net>
*/
// 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 buffer to least-significant word of counter (bits 15..0)
node.setTransmitBuffer(0, lowWord(i));
// set word 1 of TX buffer to most-significant word of counter (bits 31..16)
node.setTransmitBuffer(1, highWord(i));
// slave: write TX buffer to (2) 16-bit registers starting at register 0
result = node.writeMultipleRegisters(0, 2);
// slave: read (6) 16-bit registers starting at register 2 to RX buffer
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.getResponseBuffer(j);
}
}
}
// code end.
facing problem, message as under.
Arduino: 1.5.6-r2 (Windows 8), Board: "Arduino Due (Programming Port)"
Basic.pde:25: fatal error: ModbusMaster.h: No such file or directory
compilation terminated.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
0.11.0
any
any
any
As a maintainer
I want to apply a structured approach to assigning issue labels
So that they are consistent over time
As a contributor or project user
I want to know how/why labels are assigned
So that I understand...
issue status and how it's assigned,
issue priority and how it's assigned, and
issue type and how it's assigned
I found that having a uint8_t is not enough of delay when trying to connect to an air compressor using your library. It seems that due to the nature of the design requests for certain registers requires long delays and a uint8_t is not enough. I bumped up ku8MBResponseTimeout to a uint16_t at 2000 millisecond delay time and everything began to work perfectly.
I have a potential fix that uses a uint16_t instead and it includes an overload constructor
ModbusMaster(uint8_t u8SerialPort, uint8_t u8MBSlave, uint16_t u16ResponseTimeout)
This should give the library greater flexibility of having a longer timeout that is easier to configure. I will test it out in the next few days and let you know. In the meantime, are there any reasons why uint8 was chosen, I'm not a Modbus expert so I'm not sure if there is a standard.
result = node.readHoldingRegisters(3913, 2);
if (result == node.ku8MBSuccess)
{
for (j = 0; j < 2; j++)
{
data[j] = node.getResponseBuffer(j);
}
}
parameter 2, shows that 2 16 bit values are read.
How to convert it back to float?
2.0.1
1.8.1
DUE
Windows 10 x64
Communiction with a CAR ecu that talks modbus. It's working, the problem is that I get malformed requests sometimes
This is my code:
void readModbusRegister()
{
ecu.readHoldingRegisters(4097, 6); //read 6 registers beginning from offest 4097
if (result == ecu.ku8MBSuccess) //if transmission is good, decode Data
{
decodeModbusRegister();
}
}
void decodeModbusRegister() //read word registers and write into data array
{
for (j = 0; j < 6; j++)
{
data[j] = ecu.getResponseBuffer(j);
}
printValues(); //after decoding, print data
}
Request is sent for 6 registers.
Its working but sometimes the request packets are malformed:
01 03 10 01 00 06 90 C8 <--- Good request
01 03 10 01 00 06 90 C8 <--- Good request
01 03 10 01 00 06 90 C8 <--- Good request
00 00 00 00 00 00 00 00 01 03 10 01 00 06 90 C8 <--- malformed request
[Version of the project where you are encountering the issue]
[Version of Arduino IDE in your environment]
[Hardware information, including board and processor]
[Operating system distribution and release version]
[What you are trying to achieve and you can't?]
[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this project or any resources it includes?]
[What are you expecting to happen as the consequence of above reproduction steps?]
[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]
As a [role]
I want [feature]
So that [benefit]
Scenario 1: Title
Given [context]
And [some more context]...
When [event]
Then [outcome]
And [another outcome]...
0.11.0
1.6
all
any
As a project owner
I want all changes to compile without error
So that end users have a working library
Scenario 1: Build is successful
Given a user submits a pull request
When it compiles without error on the automated ci tool
Then it is flagged as passing the build test
Scenario 1: Build fails
Given a user submits a pull request
When the build fails on the automated ci tool
Then it is flagged as failing the build test
As a project user
I want to know what information is required to submit a pull request
So that my request may be accepted quickly
Hello, I have a problem.
When I wanted to compile the example program the compiler returns an error:
ModbusMaster.cpp:36: error: conversion from ‘Serial_’ to non-scalar type ‘HardwareSerial’ requested
arduino-1.0.5/libraries/ModbusMaster/ModbusMaster.cpp: In member function ‘void ModbusMaster::begin(uint16_t)’:
arduino-1.0.5/libraries/ModbusMaster/ModbusMaster.cpp:139: error: no match for ‘operator=’ in ‘MBSerial = Serial’
arduino-1.0.5/hardware/arduino/cores/arduino/HardwareSerial.h:33: note: candidates are: HardwareSerial& HardwareSerial::operator=(const HardwareSerial&)
How to solve it?
First off, great library and thanks for making it, overall I've been very happy with it and it has worked perfectly for my project.
However, these few lines were causing some odd behavior in my system that it took me a while to track down.
ModbusMaster.cpp lines 150-153:
#if __MODBUSMASTER_DEBUG__
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
#endif
The way I constructed my application is part of the reason it took a while, but generally I don't expect a library to change the state of pins in a hidden way. I recommend setting MODBUSMASTER_DEBUG to 0 by default, since if you intend to use the debugging features you will have no issue in enabling them, but most users will probably not be aware of this functionality and are more likely to be using digital pins 4 and 5.
If nothing else, it would be good to make the fact that this is enabled by default very obvious and mention it in the main README.
Thanks again for the library.
1.0.0
any
any
any
As a project owner
I want my library to compile cleanly for multiple boards
So that it may be used on a wide variety of hardware
Scenario 1: all boards
Given board is one of uno | due | huzzah | genuino101 | teensy31
When `make` or `make all` is executed
Then target compiles cleanly
Scenario 2: specific board
Given board is one of uno | due | huzzah | genuino101 | teensy31
When `make <board>` is executed
Then target compiles cleanly
Scenario 3: travis-ci
Given board is one of uno | due | huzzah | genuino101 | teensy31
When `make build` is executed with PLATFORMIO_BOARD=<board>
Then targets compile cleanly
So I hope that somebody has gone though the same issue as me;
I'm trying to obtain the content of a holding register through the serial port. I can see the content but it's not understandable. What I'm getting It's not ASCII or any other variable type.
resut = node.readHoldingRegisters(25, 6);
0.11.0
1.6
any
any
Add cross-references to ModbusMaster.cpp
:
Add example to ModbusMaster.h
:
@example examples/RS485_HalfDuplex/RS485_HalfDuplex.ino
Arduino: 1.6.1 (Windows 8.1), Board: "Arduino Uno"
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:223:0,
from C:\Users\Ilyas\Documents\Arduino\libraries\ModbusMaster-master\ModbusMaster.h:53,
from C:\Users\Ilyas\Documents\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp:32:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h: In member function 'HardwareSerial& HardwareSerial::operator=(const HardwareSerial&)':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ubrrh', can't use default assignment operator
class HardwareSerial : public Stream
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ubrrl', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsra', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsrb', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsrc', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_udr', can't use default assignment operator
C:\Users\Ilyas\Documents\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp: In member function 'void ModbusMaster::begin(uint16_t)':
C:\Users\Ilyas\Documents\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp:139:16: note: synthesized method 'HardwareSerial& HardwareSerial::operator=(const HardwareSerial&)' first required here
MBSerial = Serial;
^
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Any plans on supporting Arduino 101 Curie chip in the future?
Thanks
Hi, thanks for super library.
I have problem with using different serial other then serial 0. On UNO si code fast and without problems. On DUE works slowly (but works). Serial1(2,3) on DUE didn't work at all. It sends nothing. I tried:
ModbusMaster node(Serial1,1);
ModbusMaster node(1,1);
Comunication not working.
I using library version 0.11.0, arduino IDE 1.6.8
Only corrections I made, is adding lines for TX enable and
MBSerial->begin(u16BaudRate, SERIAL_8E1)
Code works on UNO without any problems.
0.11.0
1.6
any
any
As a project owner
I want to contributors to have clear expectations related to interaction with other contributors
So that we foster an open and welcoming environment
Hi, this is a really mice library!
After some work I got it working within the ESP8266 wifi module together with a max3232 chip. This is less than USD 5 to get a RTU Modbus hardware by wifi!
The only problem is that the esp compiler gets confused with your ModbusMaster::send function. The fix is very simple, just adjust the cast:
void ModbusMaster::send(uint8_t data)
{
send((word)data);
}
We also discussed this issue here:
esp8266/Arduino#360
All the best.
Replace C utility macros with inline functions
The Modbus protocol uses a cyclic redundancy check (CRC) to verify data packets. The current ModbusMaster library uses the AVR-specific implementation found in <util/crc16.h>. Figure out a way to include this code for ARM SAM3 microprocessors (e.g. Arduino Due).
In file included from sketch_mar16a.ino:1:
/Users/doc/Documents/Automation/Arduino/libraries/ModbusMaster/ModbusMaster.h:83: fatal error: util/crc16.h: No such file or directory
compilation terminated.
0.11.0
any
any
any
As a project owner
I want project users to know how to get help
So that they may get their issues resolved efficiently
hello I have a program that only runs on IDE 1.0.6 and wish to add the Modbus instruction but the latter does not work with IDE 1.0.6, which I do? ..
CHANGELOG
is more consistent with contemporary projects.
HISTORY.md
to CHANGELOG.md
Rakefile
rake task accordingly.github/PULL_REQUEST_TEMPLATE.md
checklistAdd GitHub standard Ruby files to .gitignore
Update util/crc16.h
and util/word.h
to use consistent Doxygen comments.
I am fairly new to Arduinos and am looking for an easy to use Modbus RTU master. With your ModbusMaster how is the Tx enable for the RS485 driver controlled? I can't see anywhere in your library where this can be set up. I expected the ModbusMaster.begin to allow the TxEn signal to be allocated to any Arduino digital out pin. All I can see for .begin are parameters for choosing the Arduino serial port and the Modbus Id for the slave.
Use .md
instead of .markdown
or .mkd
.
rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf
pdflatex refman
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./refman.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
make: *** [refman.pdf] Error 1
The ModbusMaster library currently uses an object of type HardwareSerial to abstract the serial port object. Figure out how to work around the following compiler error:
sketch_mar16a:3: error: cannot allocate an object of abstract type 'HardwareSerial'
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:27: note: because the following virtual functions are pure within 'HardwareSerial':
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:35: note: virtual size_t HardwareSerial::write(uint8_t)
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:31: note: virtual int HardwareSerial::available()
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:33: note: virtual int HardwareSerial::read()
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:32: note: virtual int HardwareSerial::peek()
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:34: note: virtual void HardwareSerial::flush()
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:37: note: virtual HardwareSerial::operator bool()
sketch_mar16a:3: error: cannot declare variable 'abc' to be of abstract type 'HardwareSerial'
/Applications/Arduino 1.5.2.app/Contents/Resources/Java/hardware/arduino/sam/cores/arduino/HardwareSerial.h:27: note: since type 'HardwareSerial' has pure virtual functions
I have a unit where I need to read multiple registers from it. The registers I need are not next to each other and I need to make multiple read requests from the unit. If I try to do more than 1 read, when I get the values using the getResponseBuffer() function, the results are wrong. They seem to be the results from the last read and not the current one. Any help with this would be appreciated.
Use either:
#if defined(ARDUINO_ARCH_AVR)
// AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)
// SAM-specific code
#else
// generic, non-platform specific code
#endif
or:
#if defined(ARDUINO_ARCH_AVR)
// AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)
// SAM-specific code
#else
#error “This library only supports boards with an AVR or SAM processor.”
#endif
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.