/// <summary> /// This illustrates variations on the ITypeDouble that can be used for creating properties /// </summary> internal void CreateMoreProperties(IDDK cmDDK) { ITypeDouble type1 = cmDDK.CreateDouble(-1, 1, 0); // Range: [-1...1] // - any number -1 <= x <= 1 can be assigned, will be rounded to 0 decimals // - user input is allowed with 0 decimals only (-1|0|1) // - numbers outside this range (-1|0|1) cause validation errors in panel edit controls or during Instrument Method syntax checking // - panel edit control's spin box will spin -1,0,1 // - F8 box's/Instrument Method Editor's drop list will contain -1,0,1 IDoubleProperty type1Property = m_MyCmDevice.CreateProperty("Type1Property", "", type1); type1Property.Update(-1); //set default value type1Property.OnSetProperty += new SetPropertyEventHandler(type1Property_OnSetProperty); ITypeDouble type2 = cmDDK.CreateDouble(-1, 1, 2); type2.Unit = "bar"; // Range: [-1.00..1.00 bar] // - any number -1 <= x <= 1 can be assigned, will be rounded to 2 decimals // - user input is allowed with up to 2 decimals // - numbers outside this range cause validation errors in panel edit controls or during Instrument Method syntax checking // - unit "bar" is shown in Commands overview (F8), // and can be appended to text shown in panel edit controls and panel string displays // - unit [bar] can be added to assignments in Instrument Method scripts, // system can also convert from other units if it makes sense, // e.g. Type2Property = 1 [psi] is equal to Type2Property = 0.0689475729 [bar] // - panel edit control's spin box will spin in 0.01 incrementals // - F8 box's/Instrument Method Editor's drop list will be empty as it would be too long (a maximum of 12 items can be shown) IDoubleProperty type2Property = m_MyCmDevice.CreateProperty("Type2Property", "", type2); type2Property.Update(0.0); //set default value type2Property.OnSetProperty += new SetPropertyEventHandler(type2Property_OnSetProperty); ITypeDouble type3 = cmDDK.CreateDouble(0, 20, 1); type3.AddNamedValue("Null", 0); type3.AddNamedValue("OnePointFive", 1.5); type3.AddNamedValue("Ten", 10); type3.AddNamedValue("Thirty", 30); // Range: [Null..20.0] - when a property is displayed or logged, a named value is used instead of a pure number if a named value is available. // - any number 0 <= x <= 20 can be assigned, will be rounded to 1 decimal // - 30 can also be assigned, even if it is outside the min/max range, because it has been added as named value // - user input is allowed with up to 1 decimal // - instead of Type3Property = 0, one can write Type3Property = Null // - instead of Type3Property = 1.5, one can write Type3Property = OnePointFive // - instead of Type3Property = 10, one can write Type3Property = Ten // - instead of Type3Property = 30, one can write Type3Property = Thirty // - panel edit control's spin box will spin in 0.1 incrementals: Null, 0.1, 0.2, ..., 1.4, OnePointFive, 1.6, .... 20.0, Thirty // - F8 box's/Instrument Method Editor's drop list contains the four named values IDoubleProperty type3Property = m_MyCmDevice.CreateProperty("Type3Property", "", type3); type3Property.Update(4);//set default value type3Property.OnSetProperty += new SetPropertyEventHandler(type3Property_OnSetProperty); ITypeDouble type4 = cmDDK.CreateDouble(0, 20, 1); type4.AddNamedValue("Null", 0); type4.AddNamedValue("Ten", 10); type4.AddNamedValue("Twenty", 20); type4.NamedValuesOnly = true; // Range: [Null..Twenty] - when a property is displayed or logged, a named value is used instead of a pure number if a named value is available. // - numbers 0.0, 10.0 and 20.0 can be assigned only, because of the 'NamedValuesOnly' flag. // - instead of Type3Property = 0, one can write Type3Property = Null // - instead of Type3Property = 10, one can write Type3Property = Ten // - instead of Type3Property = 20, one can write Type3Property = Twenty // - panel edit control's spin box will spin Null, Ten, Twenty only. Other values will cause validation errors // - F8 box's/Instrument Method Editor's drop list contains the three named values, other values will cause validation errors IDoubleProperty type4Property = m_MyCmDevice.CreateProperty("Type4Property", "", type4); type4Property.Update(0);//set default value type4Property.OnSetProperty += new SetPropertyEventHandler(type4Property_OnSetProperty); ITypeDouble type5 = cmDDK.CreateDouble(0, 20, 1); Double[] legalValues = { 1.1, 2.2, 3.3 }; type5.LegalValues = legalValues; // Range: [0.0..20.0] // - any (!) number 0 <= x <= 20 can be assigned, will be rounded to 1 decimal // - user input is allowed with up to 1 decimal // - panel edit control's spin box will spin to 1.1, 2.2 and 3.3 (due to LegalValues) // - F8 box's/Instrument Method Editor's drop list contains the three legal values IDoubleProperty type5Property = m_MyCmDevice.CreateProperty("Type5Property", "", type5); type5Property.Update(2.2);//set default value type5Property.OnSetProperty += new SetPropertyEventHandler(type5Property_OnSetProperty); ITypeDouble type6 = cmDDK.CreateDouble(0, 20, 1); type6.LegalValues = legalValues; type6.AddNamedValue("Null", 0); type6.AddNamedValue("OnePointFive", 1.5); type6.AddNamedValue("Ten", 10); type6.AddNamedValue("Twenty", 20); // Range: [Null..20.0] // - any (!) number 0 <= x <= 20 can be assigned, will be rounded to 1 decimal // - user input is allowed with up to 1 decimal // - panel edit control's spin box will spin to all legal and named values // - F8 box's/Instrument Method Editor's drop list contains the seven legal and named values IDoubleProperty type6Property = m_MyCmDevice.CreateProperty("Type6Property", "", type6); type6Property.Update(10);//set default value type6Property.OnSetProperty += new SetPropertyEventHandler(type6Property_OnSetProperty); ITypeInt badBooleanType = cmDDK.CreateInt(0, 1); IIntProperty badBoolean1 = m_MyCmDevice.CreateProperty("BadBoolean", "This is a Boolean type without enumerations. Please define appropriate enumerations in the driver!", badBooleanType); badBoolean1.OnSetProperty += new SetPropertyEventHandler(badBoolean_OnSetProperty); m_MyProperBoolean = m_MyCmDevice.CreateBooleanProperty("ProperBoolean", "This is how to do it", "False_No_Zero_NotReady", "True_Yes_One_Ready"); m_MyProperBoolean.OnSetProperty += new SetPropertyEventHandler(properBoolean_OnSetProperty); ITypeInt explicitBooleanType = cmDDK.CreateInt(0, 1); explicitBooleanType.AddNamedValue("False_No_Zero_NotReady", 0); explicitBooleanType.AddNamedValue("True_Yes_One_Ready", 1); explicitBooleanType.NamedValuesOnly = true; IIntProperty explicitBoolean = m_MyCmDevice.CreateProperty("ExplicitBoolean", "Also ok, but way more explicit code", explicitBooleanType); explicitBoolean.OnSetProperty += new SetPropertyEventHandler(explicitBoolean_OnSetProperty); }
/// Create our Chromeleon symbols internal IPDAChannel OnCreate(IDDK cmDDK, IDevice master, string name) { // Create a data type for the wavelength range ITypeDouble tWavelength = cmDDK.CreateDouble(200.0, 600.0, 1); tWavelength.Unit = "nm"; // Create a data type for the reference wavelength range ITypeDouble tRefWavelength = cmDDK.CreateDouble(200.0, 600.0, 1); tRefWavelength.Unit = "nm"; tRefWavelength.AddNamedValue("Off", 0.0); // Create a data type for the reference bandwidth ITypeDouble tReferenceBandwidth = cmDDK.CreateDouble(0.0, 20.0, 1); tReferenceBandwidth.Unit = "nm"; // Create a data type for the bunch width ITypeDouble tBunchWidth = cmDDK.CreateDouble(0.0, 10.0, 1); tBunchWidth.Unit = "nm"; // Create the channel symbol m_MyCmDevice = cmDDK.CreatePDAChannel(name, "This is a channel that can generate a spectrum.", tWavelength, tRefWavelength, tReferenceBandwidth, tBunchWidth, 400, PDAWriteMode.AbsorbanceDirect); // We will be a subdevice of the master device m_MyCmDevice.SetOwner(master); // Attach our handlers to the AcquisitionOffCommand and AcquisitionOnCommand of the channel m_MyCmDevice.AcquisitionOffCommand.OnCommand += new CommandEventHandler(OnAcqOff); m_MyCmDevice.AcquisitionOnCommand.OnCommand += new CommandEventHandler(OnAcqOn); m_MyCmDevice.OnDataFinished += new DataFinishedEventHandler(m_MyCmDevice_OnDataFinished); // Usually, TimeStepFactor and TimeStepFactor are read-only properties and the driver updates them. // In this driver we allow to change these values manually for illustration purposes. m_MyCmDevice.TimeStepFactorProperty.DataType.Minimum = 1; m_MyCmDevice.TimeStepFactorProperty.DataType.Maximum = 10000; m_MyCmDevice.TimeStepFactorProperty.OnSetProperty += new SetPropertyEventHandler(TimeStepFactorProperty_OnSetProperty); m_MyCmDevice.TimeStepDivisorProperty.DataType.Minimum = 1; m_MyCmDevice.TimeStepDivisorProperty.DataType.Maximum = 10000; m_MyCmDevice.TimeStepDivisorProperty.OnSetProperty += new SetPropertyEventHandler(TimeStepDivisorProperty_OnSetProperty); ITypeDouble tRateType = cmDDK.CreateDouble(0.1, 1000.0, 1); tRateType.Unit = "Hz"; m_RateProperty = m_MyCmDevice.CreateProperty("FixedRate", "The data collection rate in Hz.", tRateType); m_RateProperty.OnSetProperty += new SetPropertyEventHandler(m_RateProperty_OnSetProperty); ITypeInt tDataIndexType = cmDDK.CreateInt(0, int.MaxValue); m_SpectraIndexProperty = m_MyCmDevice.CreateProperty("TotalSpectra", "Total number of spectra.", tDataIndexType); ICommand noMoreDataCommand = m_MyCmDevice.CreateCommand("NoMoreData", "Send IChannel.NoMoreData to stop data acquisition immediately."); noMoreDataCommand.OnCommand += new CommandEventHandler(noMoreDataCommand_OnCommand); ITypeDouble tChannelTimeType = cmDDK.CreateDouble(0, 1000, 3); tChannelTimeType.Unit = "min"; m_ChannelTimeProperty = m_MyCmDevice.CreateProperty("ChannelTime", "Internal time of the channel.", tChannelTimeType); return(m_MyCmDevice); }
/// <summary> /// Create our Dionex.Chromeleon.Symbols.IDevice and our Properties and Commands /// </summary> /// <param name="cmDDK">The DDK instance</param> /// <param name="name">The name for our device</param> /// <returns>our IDevice object</returns> internal IDevice Create(IDDK cmDDK, string name) { // Create the Dionex.Chromeleon.Symbols.IDevice m_MyCmDevice = cmDDK.CreateDevice(name, "This is an example device."); // create a few example properties // A Data type for seconds ranging from 0 - 59 ITypeInt tSeconds = cmDDK.CreateInt(0, 59); tSeconds.Unit = "s"; // Create the "Clock" property m_ClockProperty = m_MyCmDevice.CreateProperty("Clock", "This is a second counter", tSeconds); // Attach the OnSetClockProperty handler to the "Clock" property m_ClockProperty.OnSetProperty += new SetPropertyEventHandler(OnSetClockProperty); // we will use a timer to update the clock property each second // Attach the OnTimedEvent handler to the timer. m_clockTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // A Data type with two values 0 and 1 ITypeInt tEnable = cmDDK.CreateInt(0, 1); tEnable.AddNamedValue("false", 0); tEnable.AddNamedValue("true", 1); // Create the "EnableClock" property m_EnableClockProperty = m_MyCmDevice.CreateProperty("EnableClock", "Enable / disable the clock", tEnable); // Attach the OnEnableClock handler to the "EnableClock" property m_EnableClockProperty.OnSetProperty += new SetPropertyEventHandler(OnEnableClock); // A Data type for a percentage ranging from 0.0 - 100.0 ITypeDouble tPercent = cmDDK.CreateDouble(0, 100, 2); tPercent.Unit = "%"; // Create the "Percentage" property m_PercentageProperty = m_MyCmDevice.CreateProperty("Percentage", "This is a percentage property", tPercent); // Attach the OnSetProperty handler to the "Percentage" property m_PercentageProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for a time constant ranging from 1.0 - 10.0 ITypeDouble tTimeConstant = cmDDK.CreateDouble(1.0, 10.0, 1); tTimeConstant.AddNamedValue("Off", 0.0); tTimeConstant.Unit = "s"; // Create the "Percentage" property m_FilterTimeConstantProperty = m_MyCmDevice.CreateProperty("FilterTimeConstant", "This is a numeric property with one special named value.", tTimeConstant); // Attach the OnSetProperty handler to the "FilterTimeConstant" property m_FilterTimeConstantProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for the measurement range property ITypeDouble tMeasurementRange = cmDDK.CreateDouble(0.01, 100.0, 2); tMeasurementRange.LegalValues = new double[] { 0.01, 0.1, 1.0, 10.0, 100.0 }; tMeasurementRange.EnforceLegalValues = true; tMeasurementRange.Unit = "V"; // Create the "Percentage" property m_MeasurementRangeProperty = m_MyCmDevice.CreateProperty("MeasurementRange", "This is a numeric property with 5 legal (valid) values.", tMeasurementRange); // Attach the OnSetProperty handler to the "FilterTimeConstant" property m_MeasurementRangeProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for a string with 20 characters at most ITypeString tString = cmDDK.CreateString(20); // Create the "AnyText" property m_AnyTextProperty = m_MyCmDevice.CreateProperty("AnyText", "This is a string property", tString); // Attach the OnSetProperty handler to the "AnyText" property m_AnyTextProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // Create the "ToggleEnableClock" example command m_Command = m_MyCmDevice.CreateCommand("ToggleEnableClock", "This is a simple command that toggles the EnableClock property."); // Attach the OnToggleEnableClock handler to the "ToggleEnableClock" command m_Command.OnCommand += new CommandEventHandler(OnToggleEnableClock); // Create the "SetEnableClock" command which uses a parameter. m_SetEnableClockCommand = m_MyCmDevice.CreateCommand("SetEnableClock", "This is a command with one required parameter. Set true or false to enable/disable the clock."); // Add the "Enable" parameter to the "SetEnableClock" command IParameter parameter = m_SetEnableClockCommand.AddParameter("Enable", "Set true or false to enable/disable the clock", tEnable); // This is a required parameter. parameter.Required = true; // Attach the OnSetEnableClock handler to the "SetEnableClock" command m_SetEnableClockCommand.OnCommand += new CommandEventHandler(OnSetEnableClock); // Create the "SetPercentage" command which uses a parameter. m_SetPercentageCommand = m_MyCmDevice.CreateCommand("SetPercentage", "This is a command with one required parameter to set the \"Percentage\" property."); // Add the "Value" parameter to the "SetPercentage" command parameter = m_SetPercentageCommand.AddParameter("Value", "Set to 0.00 - 100.00", tPercent); // This is a required parameter. parameter.Required = true; // Attach the OnSetPercentage handler to the "SetPercentage" command m_SetPercentageCommand.OnCommand += new CommandEventHandler(OnSetPercentage); // Create the "CommandWith4Parameters" command which uses 4 optional parameters. m_CommandWith4Parameters = m_MyCmDevice.CreateCommand("CommandWith4Parameters", "This is a command with four optional parameters."); // Add the parameters to the "CommandWith4Parameters" command m_CommandWith4Parameters.AddParameter("Param1", "Set true or false", tEnable); m_CommandWith4Parameters.AddParameter("Param2", "Set to 0.00 - 100.00", tPercent); m_CommandWith4Parameters.AddParameter("Param3", "Set true or false", tEnable); m_CommandWith4Parameters.AddParameter("Param4", "A string with 20 characters", tString); // Attach the OnCommandWith4Parameters handler to the "CommandWith4Parameters" command m_CommandWith4Parameters.OnCommand += new CommandEventHandler(OnCommandWith4Parameters); return(m_MyCmDevice); }