Problem with SerialCommandHandler

Support forum for MegunoLink
Post Reply
mr4681
Posts: 2
Joined: Thu Nov 20, 2014 6:01 pm

Thu Nov 20, 2014 6:08 pm

My project have a lot of command from Computer to Arduino Board So, I need to setup all command in arduino code. BUt I founded that Arduino can get only the first 10 commands. How can I fix this problem? ,,, As I shown below, First 10 commands are accepts. RYCompON, RYCOmpOFF, RYDryerON, RYDryerOFF are not available after load to arduino board. but when I rearrange and let's them stay on top, I will lost GetSPValue, GetIntValue, SetSPValue, SetIntValue.

SerialCommandHandler.AddCommand(F("SetSensor"), Cmd_SetSensor);
SerialCommandHandler.AddCommand(F("EnableSensor"), Cmd_EnableSensor);
SerialCommandHandler.AddCommand(F("DisableSensor"), Cmd_DisableSensor);
SerialCommandHandler.AddCommand(F("CountSensor"), Cmd_CountSensor);
SerialCommandHandler.AddCommand(F("ReadfromID"), Cmd_ReadfromID);
SerialCommandHandler.AddCommand(F("ProgramByID"), Cmd_ProgramByID);
SerialCommandHandler.AddCommand(F("GetSPValue"), Cmd_GetSetpointValue);
SerialCommandHandler.AddCommand(F("GetIntValue"), Cmd_GetIntervalValue);
SerialCommandHandler.AddCommand(F("SetSPValue"), Cmd_SetSetpointValue);
SerialCommandHandler.AddCommand(F("SetIntValue"), Cmd_SetIntervalValue);

SerialCommandHandler.AddCommand(F("RYCompON"), Cmd_RYCompON);
SerialCommandHandler.AddCommand(F("RYCompOFF"), Cmd_RYCompOFF);
SerialCommandHandler.AddCommand(F("RYDryerOFF"), Cmd_RYDryerOFF);
SerialCommandHandler.AddCommand(F("RYDryerON"), Cmd_RYDryerON);

At first, I guess the problem may come from memory, But after I try with the fresh code. Problem is still.
Please Help,..
SVP
raescuin
Posts: 9
Joined: Sun Nov 16, 2014 9:13 pm

Wed Dec 10, 2014 8:22 am

Is there any fix for this? I'm having the same problem.

Appreciate any responses,
Robert
admin
Site Admin
Posts: 16
Joined: Mon May 26, 2014 10:53 am

Mon Dec 22, 2014 7:38 am

Howdy,

There's an easy solution to this one. The CommandHandler is a template which takes two parameters: the maximum number of commands supported and the maximum length of a command message. You can see the definition here:
https://github.com/Megunolink/MLP/blob/ ... dHandler.h

Line 9 is the clue:
template <int MAX_COMMANDS = 10, int CP_SERIAL_BUFFER_SIZE = 30> class CommandHandler : public MLP::CommandDispatcherBase, public MLP::StreamParser

It defaults to 10 commands, with maximum buffer length of 30 characters.

To get 15 commands, and keep the same buffer size use this declaration:
CommandHandler<15> SerialCommandHandler;

This will increase the buffer size to 40 characters:
CommandHandler<15, 40> SerialCommandHandler;

The only constraints on the number of commands is the amount of free memory and how quickly you need to process them. Just note, that if you set the maximum commands to 15 but only add 5 commands, the Arduino will still allocate enough memory for 15.

Merry Christmas,
Paul.
raescuin
Posts: 9
Joined: Sun Nov 16, 2014 9:13 pm

Tue Dec 23, 2014 6:22 am

Thanks for the info Paul, that works.

Robert
Post Reply