フィルターのクリア

How to pass a value to an enumeration member?

6 ビュー (過去 30 日間)
Raha
Raha 2023 年 3 月 14 日
回答済み: Shubham 2023 年 5 月 5 日
I am trying to change the default trigger setting on a Thorlabs brushless DC controller.
I can read the current setting, but I have troubke changing to change the value to a new setting that matches the application.
Is there a place where I can learn more how to assign values to a member of an enumeration.
Thanks
==============
K>> triggerSetting.Trigger2Mode
ans =
TrigOUT_GPO
K>> triggerSetting.Trigger2Mode = 'TrigOUT_InMotion'
Error setting property 'Trigger2Mode' of class 'KCubeTriggerConfigSettings':
Value must be 'Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings+TriggerPortMode'.
  2 件のコメント
chrisw23
chrisw23 2023 年 3 月 15 日
first steps
asm = NET.addAssembly("<...>");
enTrigPortModes = asm.AssemblyHandle.GetType("<...TriggerPortMode>")
trigPortModeNames = string(enTrigPortModes.GetEnumNames); % get enum values as strings
% loop through the enumerator or convert string to enum object
trigPortMode = System.Enum.Parse(enTrigPortMode,trigPortModeNames(n)); % from name to object to be assigned
Raha
Raha 2023 年 3 月 15 日
Thanks for the suggestion. It seems that the GetType does not work in this case--I am able to read the type using class, but when tried to typecast using the response about type from class(), get this message:
No method 'GetType' with matching signature found for class 'Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings'.
===================================
K>> triggerSetting.GetType("Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings+TriggerPortMode")
No method 'GetType' with matching signature found for class 'Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings'.
K>> device.MotorDeviceSettings.TriggerConfigSettings.GetType("Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings+TriggerPortMode")
No method 'GetType' with matching signature found for class 'Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings'.
K>> class(device.MotorDeviceSettings.TriggerConfigSettings)
ans =
'Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings'

サインインしてコメントする。

回答 (1 件)

Shubham
Shubham 2023 年 5 月 5 日
Hi Raha,
To assign a value to a member of an enumeration, you need to use the dot notation. Here's an example of how to set the Trigger2Mode property to TrigOUT_InMotion:
triggerSetting.Trigger2Mode = Thorlabs.MotionControl.GenericMotorCLI.Settings.KCubeTriggerConfigSettings.TriggerPortMode.TrigOUT_InMotion;
Make sure to use the full enumeration path, including the namespace and the enumeration name, to avoid errors.

カテゴリ

Help Center および File ExchangeString についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by