Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modbus_configure #23

Open
GoogleCodeExporter opened this issue Dec 23, 2015 · 6 comments
Open

modbus_configure #23

GoogleCodeExporter opened this issue Dec 23, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

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 [email protected] on 9 Dec 2013 at 11:40

@GoogleCodeExporter
Copy link
Contributor Author

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 [email protected] on 11 Dec 2013 at 12:42

  • Added labels: Type-Review
  • Removed labels: Type-Defect

Attachments:

@GoogleCodeExporter
Copy link
Contributor Author

Thanks, I ll test it.

Original comment by [email protected] on 12 Dec 2013 at 11:36

@GoogleCodeExporter
Copy link
Contributor Author

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 [email protected] on 12 Dec 2013 at 1:02

@GoogleCodeExporter
Copy link
Contributor Author

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 [email protected] on 18 Dec 2013 at 11:12

@GoogleCodeExporter
Copy link
Contributor Author

Hi.
Will check it tomorrow.
Thanks

Original comment by [email protected] on 20 Dec 2013 at 2:15

@GoogleCodeExporter
Copy link
Contributor Author

Yes it works perfectly!
Thanks mate. Well done!

Original comment by [email protected] on 22 Dec 2013 at 12:49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant