• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Automation
  • MUXOperator
  • 5.0.0

MUXOperator Class

(Automation::MUXOperator)

The MUXOperator is a multiplexer that selects one source by Index from a selection of many sources. More...

Header: #include <MUXOperator>
Inherits: CDPOperator<T>
  • List of all members, including inherited members

Public Functions

MUXOperator(const CDPPropertyBase &in)

Reimplemented Public Functions

virtual void Configure(XMLPrimitive *operatorXML) override
virtual unsigned int Process() override
  • 18 public functions inherited from CDPOperator
  • 17 public functions inherited from CDPOperatorBase
  • 49 public functions inherited from CDPBaseObject
  • 27 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Protected Functions

T GetIndexedInputValue(unsigned int index) const
  • 1 protected function inherited from CDP::StudioAPI::CDPNode

Additional Inherited Members

  • 1 public variable inherited from CDPOperatorBase
  • 1 static public member inherited from CDPBaseObject
  • 8 protected variables inherited from CDPOperator
  • 5 protected variables inherited from CDPOperatorBase
  • 10 protected variables inherited from CDPBaseObject

Detailed Description

The MUXOperator is a multiplexer that selects one source by Index from a selection of many sources.

The default input will always be source 0. Additional sources can be added as Arguments into the MUXOperator. The source selection is done by setting the MUXOperator Index to the desired 0-based source number to use. Index can be routed from another value.

Example

To select between a signal value and the values 10,20 and 30; add a Signal<double>, go into it and add two additional Arguments. Go into the first Argument and set Value to 10, then go into the second Argument and set Value to 20, and finally go into the third argument and set Value to 30.

How to Run the Example

To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information.

Click into the signal containing the MUXOperator, change the Index between 0 and 3, and validate that the signal value changes according to the selected source index.

Note: If the index is larger than the allowed range (number of arguments), then the Index will be limited (to number of arguments).

Arguments

NameDescription
OutThe default output value.
InterpolationTimeSpecifies the time to interpolate from the last selected input value to the newly selected input value. Defaults to zero which means no interpolation will be done (i.e. immediate switchover will be used). Time can be configured either in seconds or in the operator processing cycles (depending on the Unit property of the InterpolationTime argument).
Index0-based index to select which of the arguments to use. Index 0 is the default input value; any other Index value chooses the input argument corresponding to the Index. If the index is larger than the allowed range (number of arguments), then the Index will be limited (to the number of arguments).
In0Default input argument corresponding to Index 0
In1Input argument corresponding to Index 1

When operator is used inside a signal its default input is automatically tied to signal's InternalValue or previous operator's output. Its default output is automatically tied to next operator's input or to signal's Value. See also CDP Operator Usage In CDP Signals.

Actual Processing Code of the MUXOperator

unsigned int MUXOperator<T>::Process()
{
  if (!m_index)
    return STATUS_ERROR;

  auto index = static_cast<unsigned int>(*m_index);
  T selectedValue = GetIndexedInputValue(index);

  if constexpr (!std::is_same<T, std::string>::value && !std::is_same<T, bool>::value)
  {
    if (m_interpolationTime && m_lastKnownIndex.has_value() && m_lastKnownIndex != index)
    {
      if (m_interpolationTime->GetUnit() == "cycles")
        m_interpolationCyclesLeft = (unsigned int)*m_interpolationTime;
      else
        m_interpolationCyclesLeft = (double)*m_interpolationTime / CDPOperatorBase::GetOperatorPeriod();
      m_interpolationState = GetIndexedInputValue(m_lastKnownIndex.value());
    }
    if (m_interpolationCyclesLeft > 0)
    {
      const double interpolationStep = (double)(selectedValue - m_interpolationState) / m_interpolationCyclesLeft;
      m_interpolationState += interpolationStep;
      m_output = m_interpolationState; // round down from precise interpolation to the precision possible with operator type T
      --m_interpolationCyclesLeft;
    }
    else
      m_output = selectedValue;
    m_lastKnownIndex = index;
  }
  else
    m_output = selectedValue;

  return STATUS_OK;
}

See also Argument.

Member Function Documentation

MUXOperator::MUXOperator(const CDPPropertyBase &in)

Default constructs an instance of MUXOperator.

[override virtual] void MUXOperator::Configure(XMLPrimitive *operatorXML)

Reimplemented from CDPBaseObject::Configure().

[protected] T MUXOperator::GetIndexedInputValue(unsigned int index) const

[override virtual] unsigned int MUXOperator::Process()

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top