示例#1
0
        /// <summary>
        /// Get all the possible values for a specific param
        /// </summary>
        public async Task <CamGetParamValuesMessage> GetParamValues(string param)
        {
            // Create the message
            UserGetParamValuesMessage GetValuesMsg = new UserGetParamValuesMessage(_token, param);

            // Get the codec
            UserGetParamValuesMessageCodec UserValuesCodec = new UserGetParamValuesMessageCodec();

            // Send the message
            if (await Send(await UserValuesCodec.Encode(GetValuesMsg)))
            {
                // If sent, get the response
                string MsgReceived = await _CameraSocket.Receive();

                // Get the codec
                CamGetParamValuesMessageCodec CamValuesCodec = new CamGetParamValuesMessageCodec();

                // Decode the string
                CamGetParamValuesMessage CamValuesMsg = await CamValuesCodec.Decode(MsgReceived);

                if (CamValuesMsg.rval != 0 || CamValuesMsg.msg_id != GetValuesMsg.msg_id)
                {
                    return(null);
                }
                return(CamValuesMsg);
            }
            // If there is a problem
            return(null);
        }
        /// <summary>
        /// Populate a combobox with the possible values
        /// </summary>
        public async void PopulateValues(ComboBox CBox)
        {
            if (CBox.Items.Count == 1)
            {
                string currentValue = CBox.SelectedItem.ToString();

                // To avoid ComboBox closing:
                // Deselect the current Item
                CBox.SelectedItem = null;

                //Get the Values
                CamGetParamValuesMessage Param = await Camera.GetParamValues(CBox.Name);

                // Get the Param and update its values with reflexion
                Models.Param parameter = (Models.Param)GetParamByName(CBox.Name);

                foreach (var item in Param.options)
                {
                    parameter.Values.Add(item);
                }

                // Remove the first one (so it isn't repeated)
                parameter.Values.RemoveAt(0);

                // Select the value again
                parameter.currentValue = currentValue;

                parameter.permission = Param.permission;

                // Now set the handler for SelectionChanged
                CBox.SelectionChanged += DropDownSelectionChanged;
            }
        }