Click or drag to resize

EnumToCommand

Converts an enum value into its corresponding instrument command.

template <typename T>
bool EnumToCommand(T enumVal, CString& strCommand) const;
Parameters
enumVal

[in] Enum value to be converted.

strCommand

[out] Command string associated with the specified enum value.

Return Value

Returns true if the conversion was successful, otherwise false.

Remarks

The Instrument Command Editor allows the developer to associate enum values with command strings that can be sent to an instruments. This function converts an enum value to its associated command string.

For example, a developer may have associated the enum value Acme4321TriggerSourceExternal with the command string "EXT". The EnumToCommand function can be used to help format a complete command string for setting, say, the trigger source.

It should be noted that directly calling EnumToCommand within a method or property implementation is rarely necessary. This is because the Printf function supports formatting enums as strings directly. (Indeed, the implementation of Printf calls EnumToCommand.)

Example

The following example demonstrates use of the EnumToCommand function.

C++
// CoAcme4321.cpp
HRESULT Acme4321::ConfigureTriggerSource()
{
  HRESULT hr = S_OK;

  // Write, but don't flush since we need to add on the enum string
  hr = io.WriteString(_T("TRIG:SOUR "), false);

  Acme4321TriggerSourceEnum eSource = Acme4321TriggerSourceExternal;
  CString strSource;
  if (EnumToCommand<Acme4321TriggerSourceEnum>(eSource, strSource))
  {
    // Sends "EXT", assuming that we configured in the Enum Command Editor
    hr = io.WriteString(strSource);
  }

  return hr;
}
See Also

Download a complete CHM version of this documentation here.