![]() | EnumToCommand |
Converts an enum value into its corresponding instrument command.
template <typename T> bool EnumToCommand(T enumVal, CString& strCommand) const;
[in] Enum value to be converted.
[out] Command string associated with the specified enum value.
Returns true if the conversion was successful, otherwise false.
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.)
The following example demonstrates use of the EnumToCommand function.
// 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; }