Command Parameters

Support forum for MegunoLink
Post Reply
leon
Posts: 9
Joined: Tue Nov 12, 2019 2:13 am

Sat Dec 26, 2020 3:02 am

Firstly, merry xmas.
I have several text boxs on the UI and I want to pass the values to Arduino using Serial Command.
The issue is that a person can type text within a text box that includes spaces. eg John Citizen
When data is passed to Arduino, it see this as two separate parameters.
For example !SaveProjectData John Citizen Male

. . . . .
void Cmd_SaveProjectData(CommandParameter &Parameters){
_sName = Parameters.NextParameter();
_sSex = Parameters.NextParameter();
. . . . .


In the code above, _sName would be assigned John and _sSex would be assigned Citizen

Referring to the documentation

Working with Command Parameters
Parameters are the optional part of a command which follow the command name. There is 1 space between the command and the first parameter; each parameter is separated by 1 space.


I would value either being able to specify a delimiter eg "|" in the Arduino code or being able to add an escape character wrap around the text from the UI.

If there is a work around, would appreciate some guidance.
Cheers,
Leon
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Sat Dec 26, 2020 3:46 am

I think if you put sex first then use .RemainingParameters() that will grab all remaining and that would include both names.

Cheers
Phil
leon
Posts: 9
Joined: Tue Nov 12, 2019 2:13 am

Sun Dec 27, 2020 4:57 am

Thanks for the quick reply Phil.
I am using .RemainingParameters() as suggested and formatting the message in the UI with key pair values separated by a delimiter.
The template for "CommandHandler" has been modified to increase the buffer size to allow for the longer message.
Will see how I go.
Cheers
Leon
Post Reply