Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpLibrary writers › MODBUS library problem.

Page Index Toggle Pages: 1
MODBUS library problem. (Read 16985 times)
01/25/11 at 01:02:55

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
I'm trying to use the arduino MODBUS slave lib from here:
http://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave
Along with the rtu slave pde example from here:
http://sites.google.com/site/jpmzometa/arduino-mbrt/examples

When I try and compile I get several errors, such as 'Serial' was not declared in ModbusSlave.cpp and several others.

Could anyone help with the modifications to the MODBUS lib's to suit wiring?

Thanks Zap.
 

IP Logged
 
Reply #1 - 01/25/11 at 01:21:16

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi I tried and note that modbus_rtu_slave.pde doesn't need to include the library, in fact the code doesn't include it.
Just compile the modbus_rtu_slave.pde file and it will work fine. Do you have another example that uses the library?
 
IP Logged
 
Reply #2 - 01/25/11 at 02:14:04

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 
Thanks , that is correct if you use the non lib version of the MODBUS slave.
However if you try the lib version in the examples (also below) I get thoses errors.

#include <ModbusSlave.h>

/* First step MBS: create an instance */
ModbusSlave mbs;

/* slave registers */
enum {       
        MB_CTRL,        /* Led control on, off or blink */
        MB_TIME,        /* blink time in milliseconds */
        MB_CNT,        /* count the number of blinks */
        MB_REGS            /* total number of registers on slave */
};

int regs[MB_REGS];
int ledPin = 13;
unsigned long wdog = 0;         /* watchdog */
unsigned long tprev = 0;         /* previous time*/

void setup()
{
       
/* the Modbus slave configuration parameters */
const unsigned char SLAVE = 1;
const long BAUD = 115200;
const char PARITY = 'e';
const char TXENPIN = 0;

       /* Second step MBS: configure */
      mbs.configure(SLAVE,BAUD,PARITY,TXENPIN);

        pinMode(ledPin, OUTPUT);
       
}

void loop()
{
        /* Third and las step MBS: update in loop*/
        if(mbs.update(regs, MB_REGS))
                wdog = millis();

        if ((millis() - wdog) > 5000)  {      /* no comms in 5 sec */
                regs[MB_CTRL] = 0;      /* turn off led */
        }       

        /* the values in regs are set by the modbus master */
        switch(regs[MB_CTRL]) {
        case 0:
                digitalWrite(ledPin, LOW);
                break;
        case 1:
                digitalWrite(ledPin, HIGH);
                break;       
        default: /* blink */
                if (millis() - tprev > regs[MB_TIME]) {
                        if (LOW == digitalRead(ledPin)) {
                                digitalWrite(ledPin, HIGH);
                                /* this is how you change your holding registers
                                  so the master can read values from the slave */
                                regs[MB_CNT]++;
                        } else {
                                digitalWrite(ledPin, LOW);
                        }
                        tprev = millis();
                }
        }

}


Thanks Zap.
 

IP Logged
 
Reply #3 - 01/25/11 at 16:08:36

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Could you point me to an example that uses the library? those are not included with the library. Thx.
 
IP Logged
 
Reply #4 - 01/28/11 at 04:43:46

Zap   Offline
YaBB Newbies
Tnks Zap
Ausi

Posts: 22
*
 

I don't know of any, other than the one supplied.

Zap
 

IP Logged
 
Reply #5 - 01/28/11 at 05:51:26

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
got it, this is a quick fix for 0027, it won't happen on 0028 that will be released soon. On the library there is a file called ModBusSlave.h, open it and edit and add the include line shown after the WProgram.h line:


Code (C++):
/****************************************************************************
 * BEGIN MODBUS RTU SLAVE FUNCTIONS
 ****************************************************************************/
#include "WProgram.h"
#include "HardwareSerial.h"
 



That's it, try to compile your sketch after that.
let me know.
 
IP Logged
 
Page Index Toggle Pages: 1