Using GetValue with the MLPUI Message Processor
Posted: Wed Jun 17, 2020 1:05 pm
Goal: read the UI NumericUpDown values to initialise the variables in Arduino Code
The NumericUpDown buttons allow an initial value to be set. The Properties:Communications allow a serial command to be sent, that sets a variable value on the Arduino. When the mouse is used to change the UI value, this value is then updated on the Arduino.
After power on, the code is uploaded to the Arduino, this would require all the UI values to be mouse clicked to initialise the variables to the UI. Otherwise, they would all have to be hard coded (where I am pre MegUnoLink)). Since the initial values can be saved to a project or even to file, it should be possible to have a method to update the Arduino variables from the UI at power-on.
I've not found a simple solution, but I suspect there is one! I've tried 3 approaches, still not quite there so I've picked up the white flag and admitted defeat.
First, the neat solution should be to use the Message Processor to 'GET' the value. The problem is the response. For example: {UI:SetUp|set|origin.Value=18}. The value I want is 18. Reading the documentation, this is the correct serial response, but the next step to grab the response and pull out the value requested is missing. Having a red serial response is very nice, but it doesn't complete the request to GET the value into the variable. That's what the command is all about, isn't it? This must be possible.
A modification of this was to add the Message Library and set-up the same serial command used by the NumericUpDown Communications:OnValueChange. The black command confirmation appeared, for example, {UI|CMD|GetOrigin}. The name 'GetOrigin ' is linked to the command '!Setorigin [origin.DoubleValue]\r\n'. This is the same command that works when the mouse changes the UI value. However, no change is seen to the value of the variable 'origin' when printed to the monitor.
The final approach was really banging a nail into the UI and setting up a Button with multiple commands, one for each NumericUpDown button. Once the default length had been increased to accommodate the total length sent to the Command Handler, this allows a single mouse click to set-up the default values for several variables. This works, but it's not really a solution as it relies on people like me remembering to do it! Better to find a clean solution.
Reference flow…...
(1)https://www.megunolink.com/documentatio ... r-library/:
This library lets you:
Set the value of a control on the interface panel
**Get the value of a control on the interface panel**
Invoke a message from the MessageLibrary component attached to the MLPUIMessageProcessor
(2)<https://www.megunolink.com/documentatio ... /#GetValue>
GetValue(ControlName, PropertyName)
Returns the value of a serial message property for the named control. The format used for the message return is described in the Message Processor Reference.
(3)https://www.megunolink.com/documentatio ... processor/
Response
When a GET command is received by a message processor, it returns the information requested using the MegunoLink Pro message format. The general format of the message returned is:
{UI:ChannelName|set|ControlName.Property=CurrentValue}
(4)<MISSING info> how to get the CurrentValue from this message?
Your feedback would be appreciated,
Nick.
The NumericUpDown buttons allow an initial value to be set. The Properties:Communications allow a serial command to be sent, that sets a variable value on the Arduino. When the mouse is used to change the UI value, this value is then updated on the Arduino.
After power on, the code is uploaded to the Arduino, this would require all the UI values to be mouse clicked to initialise the variables to the UI. Otherwise, they would all have to be hard coded (where I am pre MegUnoLink)). Since the initial values can be saved to a project or even to file, it should be possible to have a method to update the Arduino variables from the UI at power-on.
I've not found a simple solution, but I suspect there is one! I've tried 3 approaches, still not quite there so I've picked up the white flag and admitted defeat.
First, the neat solution should be to use the Message Processor to 'GET' the value. The problem is the response. For example: {UI:SetUp|set|origin.Value=18}. The value I want is 18. Reading the documentation, this is the correct serial response, but the next step to grab the response and pull out the value requested is missing. Having a red serial response is very nice, but it doesn't complete the request to GET the value into the variable. That's what the command is all about, isn't it? This must be possible.
A modification of this was to add the Message Library and set-up the same serial command used by the NumericUpDown Communications:OnValueChange. The black command confirmation appeared, for example, {UI|CMD|GetOrigin}. The name 'GetOrigin ' is linked to the command '!Setorigin [origin.DoubleValue]\r\n'. This is the same command that works when the mouse changes the UI value. However, no change is seen to the value of the variable 'origin' when printed to the monitor.
The final approach was really banging a nail into the UI and setting up a Button with multiple commands, one for each NumericUpDown button. Once the default length had been increased to accommodate the total length sent to the Command Handler, this allows a single mouse click to set-up the default values for several variables. This works, but it's not really a solution as it relies on people like me remembering to do it! Better to find a clean solution.
Reference flow…...
(1)https://www.megunolink.com/documentatio ... r-library/:
This library lets you:
Set the value of a control on the interface panel
**Get the value of a control on the interface panel**
Invoke a message from the MessageLibrary component attached to the MLPUIMessageProcessor
(2)<https://www.megunolink.com/documentatio ... /#GetValue>
GetValue(ControlName, PropertyName)
Returns the value of a serial message property for the named control. The format used for the message return is described in the Message Processor Reference.
(3)https://www.megunolink.com/documentatio ... processor/
Response
When a GET command is received by a message processor, it returns the information requested using the MegunoLink Pro message format. The general format of the message returned is:
{UI:ChannelName|set|ControlName.Property=CurrentValue}
(4)<MISSING info> how to get the CurrentValue from this message?
Your feedback would be appreciated,
Nick.