amermaroun / simple-modbus

Automatically exported from code.google.com/p/simple-modbus
0 stars 0 forks source link

modbus_configure #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.
I m just wondering if that is possible to define modbus_configure parameters in 
some other loop other then void setup().
I m planing to provide a menu for setup parameters thru LCD screen. Would that 
be possible?
Cheers

Original issue reported on code.google.com by fisher...@gmail.com on 9 Dec 2013 at 11:40

GoogleCodeExporter commented 9 years ago
This is not a defect but a review.

I have attached the altered library and header file. I have tested it on the 
Deumilanove.

Original comment by bester.j...@gmail.com on 11 Dec 2013 at 12:42

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I ll test it.

Original comment by fisher...@gmail.com on 12 Dec 2013 at 11:36

GoogleCodeExporter commented 9 years ago
Hi again,
No its not working that way I expected. Or may be I missed smthng.
I m using this code (simplified just to make i shorter). And expect modbus ID 
to be either 3 or 4 depend on which button I press but its not working this 
way. It looks like modbus is not initiated properly. Could you direct me what I 
did wrong?

#include <SimpleModbusSlave.h>
enum //Modbus declare
{     
  giHR_01,
  giHR_02,
  HOLDING_REGS_SIZE // leave this one
};
unsigned int holdingRegs[HOLDING_REGS_SIZE];
void setup()
{  
}
void loop()
{ 
 switch (key)               // depending on which button was pushed, we configure modbus
 {
  case btnRIGHT: {
     lcd.print("RIGHT ");
     modbus_configure(&Serial, 9600, SERIAL_8N1, 4, 0, HOLDING_REGS_SIZE, holdingRegs);
     break;
     }
   case btnLEFT: {
     lcd.print("LEFT   ");
     modbus_configure(&Serial, 9600, SERIAL_8N1, 3, 0, HOLDING_REGS_SIZE, holdingRegs);
     break;
     }
     break;
 }
 modbus_update();
}

Original comment by fisher...@gmail.com on 12 Dec 2013 at 1:02

GoogleCodeExporter commented 9 years ago
I tested the code below and it works flawlessly:

#include <SimpleModbusSlave.h>
enum //Modbus declare
{     
  giHR_01,
  giHR_02,
  HOLDING_REGS_SIZE // leave this one
};
unsigned int holdingRegs[HOLDING_REGS_SIZE];
void setup()
{  
  modbus_configure(&Serial, 9600, SERIAL_8N1, 1, 2, HOLDING_REGS_SIZE, holdingRegs); // this has to be called at least once in setup
}
void loop()
{ 
 switch (key)               // depending on which button was pushed, we configure modbus
 {
  case btnRIGHT: {
     lcd.print("RIGHT ");
     modbus_config_comms(9600, SERIAL_8N1, 4);
     break;
     }
   case btnLEFT: {
     lcd.print("LEFT   ");
     modbus_config_comms(9600, SERIAL_8N1, 3);
     break;
     }
     break;
 }
 modbus_update();
}

Original comment by bester.j...@gmail.com on 18 Dec 2013 at 11:12

GoogleCodeExporter commented 9 years ago
Hi.
Will check it tomorrow.
Thanks

Original comment by fisher...@gmail.com on 20 Dec 2013 at 2:15

GoogleCodeExporter commented 9 years ago
Yes it works perfectly!
Thanks mate. Well done!

Original comment by fisher...@gmail.com on 22 Dec 2013 at 12:49