user904: I have Code for Mod bus Library as below. I have Gone through lots of forum. How to assign device ID, slave address, length using below library function:
#include <SimpleModbusSlave.h>
#define  LED 9  
enum 
{     

  ADC_VAL,     
  PWM_VAL,        
  HOLDING_REGS_SIZE // leave this one
};

unsigned int holdingRegs[HOLDING_REGS_SIZE]; 
void setup()
{
  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);    
  pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
  holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
  analogWrite(LED, holdingRegs[PWM_VAL]>>2); // constrain adc value from the arduino master to 255
}

I am getting Error has.
SimpleModbusSlaveArduino.cpp: In function 'void setup()':
SimpleModbusSlaveArduino:79: error: 'SERIAL_8N2' was not declared in this scope


I have  made changes in the lib as in forum. but I found no value read by my software.
Master sending below request on read mode. But not receiving anything.
12:31:02.953: Com8, Baud Rate: 9600, Data Bits: 8 Bits, Parity: None, Stop Bits: 1 Stop Bit
12:31:02.953: Echoback: On, RTS Control: On, Transmit Delay: 5 ms, Response Delay: 1000 ms
12:31:02.953: Read Holding Register(s), Repeat Loop
12:31:02.953: Device Address: 01h, Register: 0000h
12:31:02.953: |-> Read Register: 0000h
12:31:02.968: -> [01h] [0Dh] [00h] [00h] [00h] [01h] [CBh] [EDh]


CHANGES MADE IN AS IN FORUM MENTIONED

user643: In your first example the error is that SERIAL_8N2 is not declared. maybe you are using an old Arduino IDE? try latest 1.0.x or 1.5.x
in the second case TOTAL_REGS_SIZE is a pointer to int, while the function expect a char. Without code is hard to tell what is wrong and how, but in your first code it should be
modbus_configure(115200, 1, 2, HOLDING_REGS_SIZE);

also because you are not passing a reference to the array, you have to pass a pointer pointing the current element in the update function
modbus_update(holdingRegs[i]);
i++


user11: Not sure where you got the library from, but if it's from this github repo, you're using it wrong.
The function prototype for modbus_configure is:
void modbus_configure(long baud, byte _slaveID, byte _TxEnablePin, unsigned int _holdingRegsSize, unsigned char _lowLatency);

The example file shows how to use it correctly
modbus_configure(115200, 1, 2, TOTAL_REGS_SIZE);


904: <p>I have Code for Mod bus Library as below. I have Gone through lots of forum. How to assign device ID, slave address, length using below library function:</p>

<pre><code>#include &lt;SimpleModbusSlave.h&gt;
#define  LED 9  
enum 
{     

  ADC_VAL,     
  PWM_VAL,        
  HOLDING_REGS_SIZE // leave this one
};

unsigned int holdingRegs[HOLDING_REGS_SIZE]; 
void setup()
{
  modbus_configure(&amp;Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);    
  pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
  holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
  analogWrite(LED, holdingRegs[PWM_VAL]&gt;&gt;2); // constrain adc value from the arduino master to 255
}
</code></pre>

<p>I am getting Error has.</p>

<pre><code>SimpleModbusSlaveArduino.cpp: In function 'void setup()':
SimpleModbusSlaveArduino:79: error: 'SERIAL_8N2' was not declared in this scope
</code></pre>

<p><img src="https://i.stack.imgur.com/rzaUD.jpg" alt="Error message for IDE"></p>

<p>I have  made changes in the lib as in forum. but I found no value read by my software.</p>

<p>Master sending below request on read mode. But not receiving anything.</p>

<pre><code>12:31:02.953: Com8, Baud Rate: 9600, Data Bits: 8 Bits, Parity: None, Stop Bits: 1 Stop Bit
12:31:02.953: Echoback: On, RTS Control: On, Transmit Delay: 5 ms, Response Delay: 1000 ms
12:31:02.953: Read Holding Register(s), Repeat Loop
12:31:02.953: Device Address: 01h, Register: 0000h
12:31:02.953: |-&gt; Read Register: 0000h
12:31:02.968: -&gt; [01h] [0Dh] [00h] [00h] [00h] [01h] [CBh] [EDh]
</code></pre>

<p><img src="https://i.stack.imgur.com/rJSz8.jpg" alt="my softawre">
<a href="http://forum.arduino.cc/index.php?topic=176142.0" rel="nofollow noreferrer">CHANGES MADE IN AS IN FORUM MENTIONED</a></p>
 643: <p>In your first example the error is that SERIAL_8N2 is not declared. maybe you are using an old Arduino IDE? try latest 1.0.x or 1.5.x</p>

<p>in the second case TOTAL_REGS_SIZE is a pointer to int, while the function expect a char. Without code is hard to tell what is wrong and how, but in your first code it should be</p>

<pre><code>modbus_configure(115200, 1, 2, HOLDING_REGS_SIZE);
</code></pre>

<p>also because you are not passing a reference to the array, you have to pass a pointer pointing the current element in the update function</p>

<pre><code>modbus_update(holdingRegs[i]);
i++
</code></pre>
 11: <p>Not sure where you got the library from, but if it's from this <a href="https://github.com/thibs0/EWC2013-Greenhouse-demo/tree/master/Arduino/libraries/SimpleModbusSlave" rel="nofollow">github repo</a>, you're using it wrong.</p>

<p>The function prototype for <code>modbus_configure</code> is:</p>

<pre><code>void modbus_configure(long baud, byte _slaveID, byte _TxEnablePin, unsigned int _holdingRegsSize, unsigned char _lowLatency);
</code></pre>

<p>The <a href="https://github.com/thibs0/EWC2013-Greenhouse-demo/blob/master/Arduino/libraries/SimpleModbusSlave/examples/SimpleModbusSlaveExample/SimpleModbusSlaveExample.ino" rel="nofollow">example file</a> shows how to use it correctly</p>

<pre><code>modbus_configure(115200, 1, 2, TOTAL_REGS_SIZE);
</code></pre>
