/// <summary> /// 寻找单据的处理类 /// </summary> /// <param name="sheet"></param> /// <returns></returns> //public IFlowHandler[] FindFlowHandler(FlowSheet sheet) //{ // //默认按照sheetname大写去找 // //如cgrk单,其处理类为CGRKHandler; // var handlerTypeName = $"{sheet.SheetName?.ToUpper()}Handler"; // var type = TypeFinder.Find(o => o.Name == handlerTypeName).FirstOrDefault(); // if (type == null) // { // throw new UserFriendlyException($"SheetHandler {handlerTypeName} not found"); // } // using(var handlerWrapper = IocManager.Instance.ResolveAsDisposable(type)) // { // return handlerWrapper.Object as IFlowSheetHandler; // } //} /// <summary> /// 根据表单标识寻找表单处理类 /// </summary> /// <param name="formKey"></param> /// <returns></returns> public IFlowHandler FindFlowHandler(string formKey) { IFlowHandler handler = null; //先去寻找自定义表单处理程序 var flowForm = FlowFormManager.GetAll().Where(o => o.FormKey == formKey).FirstOrDefault(); //如果表单已有处理程序 if (!string.IsNullOrWhiteSpace(flowForm.FormHandler)) { var type = ScriptRunner.CompileType(flowForm.FormHandler); handler = Activator.CreateInstance(type) as IFlowHandler; } else { //按照约定去程序集中寻找处理程序类 handler = FindFlowHandlerFromConvention(formKey); } if (handler == null) { throw new UserFriendlyException($"{formKey}FlowHandler not found"); } return(handler); }
/// <summary> /// Part of the IFlowHandler interface. Called when the PipeLineValue is raised. /// Updates all the values of the connected pipelines. /// </summary> public void AdjustPipelineValues() { if (OutcomePipeline == null) { return; } double upperFlow = 0; double lowerFlow = 0; if (this.UpperIncomePipeline != null) { upperFlow = this.UpperIncomePipeline.CurrentFlow; } if (this.LowerIncomePipeline != null) { lowerFlow = this.LowerIncomePipeline.CurrentFlow; } this.OutcomePipeline.ChangeCurrentFlow(upperFlow + lowerFlow); IFlowHandler outcomeElement = OutcomePipeline.EndComponent as IFlowHandler; if (outcomeElement != null && OutcomePipeline.EndComponent != this) { outcomeElement.AdjustPipelineValues(); } }
/// <summary> /// Part of the IFlowHandler interface. Called when the PipeLineValue is raised. /// Updates all the values of the connected pipelines. /// </summary> public void AdjustPipelineValues() { if (this.UpperOutcomePipeline != null) { double currentPercentage = ((double)UpperOutComePercentage) / 100; double newFlow = 0; if (IncomePipeline != null) { newFlow = IncomePipeline.CurrentFlow * currentPercentage; } this.UpperOutcomePipeline.ChangeCurrentFlow(newFlow); IFlowHandler flowHandler = UpperOutcomePipeline.EndComponent as IFlowHandler; if (flowHandler != null && UpperOutcomePipeline.EndComponent != this) { flowHandler.AdjustPipelineValues(); } } if (this.LowerOutcomePipeline != null) { double currentPercentage = ((double)LowerOutComePercentage) / 100; double newFlow = 0; if (IncomePipeline != null) { newFlow = IncomePipeline.CurrentFlow * currentPercentage; } this.LowerOutcomePipeline.ChangeCurrentFlow(newFlow); IFlowHandler flowHandler = LowerOutcomePipeline.EndComponent as IFlowHandler; if (flowHandler != null && LowerOutcomePipeline.EndComponent != this) { flowHandler.AdjustPipelineValues(); } } }
/// <summary> /// Changes the max flow of the pipeline if it is bigger than the current flow. /// </summary> /// <param name="newMaxFlow">The new value for the max flow.</param> public void ChangeMaxFlow(double newMaxFlow) { if (newMaxFlow >= CurrentFlow) { this.MaxFlow = newMaxFlow; } Pump p = StartComponent as Pump; if (p != null) { this.ChangeCurrentFlow(p.Flow); } IFlowHandler flowHandlerStart = StartComponent as IFlowHandler; if (flowHandlerStart != null) { flowHandlerStart.AdjustPipelineValues(); } IFlowHandler flowHandlerEnd = EndComponent as IFlowHandler; if (flowHandlerEnd != null) { flowHandlerEnd.AdjustPipelineValues(); } }
internal void Create(IDDK cmDDK, string deviceName) { m_DDK = cmDDK; m_Device = m_DDK.CreateDevice(deviceName, "Pump device"); IStringProperty typeProperty = m_Device.CreateProperty("DeviceType", "The DeviceType property tells us which component we are talking to.", m_DDK.CreateString(20)); typeProperty.Update("Pump"); // A data type for our pump flow ITypeDouble tFlow = m_DDK.CreateDouble(0, 10, 1); tFlow.Unit = "ml/min"; // Create our flow handler. The flow handler creates a Flow.Nominal, // a Flow.Value and 4 eluent component properties for us. m_FlowHandler = m_Device.CreateFlowHandler(tFlow, 4, 2); m_FlowHandler.FlowNominalProperty.OnSetProperty += OnSetFlow; // initialize the flow m_FlowHandler.FlowNominalProperty.Update(0); // initialize the components m_FlowHandler.ComponentProperties[0].Update(100.0); m_FlowHandler.ComponentProperties[1].Update(0); m_FlowHandler.ComponentProperties[2].Update(0); m_FlowHandler.ComponentProperties[3].Update(0); // A type for our pump pressure ITypeDouble tPressure = m_DDK.CreateDouble(0, 400, 1); tPressure.Unit = "bar"; // We create a struct for the pressure with Value, LowerLimit and UpperLimit m_PressureStruct = m_Device.CreateStruct("Pressure", "The pump pressure."); m_PressureValue = m_PressureStruct.CreateStandardProperty(StandardPropertyID.Value, tPressure); m_PressureLowerLimit = m_PressureStruct.CreateStandardProperty(StandardPropertyID.LowerLimit, tPressure); m_PressureLowerLimit.OnSetProperty += new SetPropertyEventHandler(OnSetPressureLowerLimit); m_PressureLowerLimit.Update(0.0); m_PressureUpperLimit = m_PressureStruct.CreateStandardProperty(StandardPropertyID.UpperLimit, tPressure); m_PressureUpperLimit.OnSetProperty += new SetPropertyEventHandler(OnSetPressureUpperLimit); m_PressureUpperLimit.Update(400.0); m_PressureStruct.DefaultGetProperty = m_PressureValue; m_Device.OnTransferPreflightToRun += new PreflightEventHandler(OnTransferPreflightToRun); }
public void StartSearching <T>(T screen) where T : ICommandHandler, IFlowHandler { commandHandler = screen; flowHandler = screen; if (client == null) { client = new NetManager(this, "SomeConnectionKey"); client.Start(); client.UpdateTime = 15; } }
/// <summary> /// Sets the flow of the pump if it does not exceed its capacity. /// </summary> /// <param name="max">The capacity of the pump.</param> /// <param name="current">The current flow of the pump.</param> public void SetFlow(double max, double current) { if (current <= max) { this.Flow = current; this.Capacity = max; if (OutcomePipeline != null) { this.OutcomePipeline.ChangeCurrentFlow(current); IFlowHandler flowHandler = OutcomePipeline.EndComponent as IFlowHandler; if (flowHandler != null) { flowHandler.AdjustPipelineValues(); } } } }
/// <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) { m_MyCmDDK = cmDDK; // 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 a flow ranging from 0.000 - 10.000 ITypeDouble tFlow = cmDDK.CreateDouble(0, 10, 3); tFlow.Unit = "ml/min"; // Create our flow handler. The flow handler creates a Flow.Nominal, // a Flow.Value and 2 eluent component properties for us. m_FlowHandler = m_MyCmDevice.CreateFlowHandler(tFlow, 2, 2); // initialize the flow m_FlowHandler.FlowNominalProperty.Update(0); // initialize the components m_FlowHandler.ComponentProperties[0].Update(100.0); m_FlowHandler.ComponentProperties[1].Update(0); // All properties support ramps m_FlowHandler.FlowNominalProperty.RampSyntax = true; m_FlowHandler.ComponentProperties[0].RampSyntax = true; m_FlowHandler.ComponentProperties[1].RampSyntax = true; // Attach various handlers m_FlowHandler.FlowNominalProperty.OnSetProperty += new SetPropertyEventHandler(m_RampedFlowProperty_OnSetProperty); m_FlowHandler.ComponentProperties[1].OnSetProperty += new SetPropertyEventHandler(m_RampedPercentageProperty_OnSetProperty); m_FlowHandler.FlowNominalProperty.OnSetRamp += new SetRampEventHandler(m_RampedFlowProperty_OnSetRamp); m_FlowHandler.ComponentProperties[1].OnSetRamp += new SetRampEventHandler(m_RampedPercentageProperty_OnSetRamp); m_FlowHandler.FlowNominalProperty.OnPreflightSetProperty += new SetPropertyEventHandler(m_RampedFlowProperty_OnPreflightSetProperty); m_FlowHandler.ComponentProperties[1].OnPreflightSetProperty += new SetPropertyEventHandler(m_RampedPercentageProperty_OnPreflightSetProperty); m_FlowHandler.FlowNominalProperty.OnPreflightSetRamp += new SetRampEventHandler(m_RampedFlowProperty_OnPreflightSetRamp); m_FlowHandler.ComponentProperties[1].OnPreflightSetRamp += new SetRampEventHandler(m_RampedPercentageProperty_OnPreflightSetRamp); m_MyCmDevice.OnSetTimeTable += new SetTimeTableEventHandler(m_MyCmDevice_OnSetTimeTable); m_MyCmDevice.OnPreflightSetTimeTable += new SetTimeTableEventHandler(m_MyCmDevice_OnPreflightSetTimeTable); // now create the properties and command for valve simulation ITypeInt valvePropType = cmDDK.CreateInt(1, 2); valvePropType.LegalValues = new[] { 1, 2 }; m_ValveState = m_MyCmDevice.CreateProperty("ValveState", "The state of the simulated valve, can be '1' or '2'.", valvePropType); m_ValveState.OnSetProperty += new SetPropertyEventHandler(m_ValveState_OnSetProperty); m_ValveState.OnPreflightSetProperty += new SetPropertyEventHandler(m_ValveState_OnPreflightSetProperty); m_ValveCommandTo1 = m_MyCmDevice.CreateCommand("SwitchValveTo1", "Switch the simulated valve to '1' state."); m_ValveCommandTo1.OnCommand += new CommandEventHandler(m_ValveCommandTo1_OnCommand); m_ValveCommandTo1.OnPreflightCommand += new CommandEventHandler(m_ValveCommandTo1_OnPreflightCommand); m_ValveCommandTo2 = m_MyCmDevice.CreateCommand("SwitchValveTo2", "Switch the simulated valve to '2' state."); m_ValveCommandTo2.OnCommand += new CommandEventHandler(m_ValveCommandTo2_OnCommand); m_ValveCommandTo2.OnPreflightCommand += new CommandEventHandler(m_ValveCommandTo2_OnPreflightCommand); m_ValveCommandWithPar = m_MyCmDevice.CreateCommand("SwitchValve", "Switch the simulated valve according to parameters."); m_ValveStateParameter = m_ValveCommandWithPar.AddParameter("NewState", "The new state of the simulated valve, can be '1' or '2'.", valvePropType); m_ValveStateParameter.Required = true; m_ValveLogParameter = m_ValveCommandWithPar.AddParameter("Message", "A message to be written when executing the command.", m_MyCmDDK.CreateString(64)); m_ValveLogParameter.Required = false; m_ValveCommandWithPar.OnCommand += new CommandEventHandler(m_ValveCommandWithPar_OnCommand); m_ValveCommandWithPar.OnPreflightCommand += new CommandEventHandler(m_ValveCommandWithPar_OnPreflightCommand); return(m_MyCmDevice); }
public Pump(IDriverEx driver, IDDK ddk, Config.Pump config, string id) : base(driver, ddk, typeof(Pump).Name, id, config.Name) { Log.TaskBegin(Id); try { m_Properties = new PumpProperties(m_DDK, m_Device); m_Properties.PressureLowerLimit.OnSetProperty += OnPropertyPressureLowerLimitSet; m_Properties.PressureUpperLimit.OnSetProperty += OnPropertyPressureUpperLimitSet; // Properties of the flow handler: // m_FlowHandler.FlowNominalProperty - Flow.Nominal // m_FlowHandler.FlowValueProperty - Flow.Value // m_FlowHandler.ComponentProperties[i] (4 eluent component) - %A.Equate, %B.Equate, %C.Equate, %D.Equate // %A.Valuue, %B.Valuue; %C.Valuue; %D.Valuue ITypeDouble flowType = m_DDK.CreateDouble(0, 10, 3); flowType.Unit = UnitConversionEx.PhysUnitName(UnitConversion.PhysUnitEnum.PhysUnit_MilliLiterPerMin); // ml/min m_FlowHandler = m_Device.CreateFlowHandler(flowType, 4, 2); m_FlowHandler.FlowNominalProperty.OnPreflightSetProperty += OnPropertyFlowNominalSetPreflight; m_FlowHandler.FlowNominalProperty.OnSetProperty += OnPropertyFlowNominalSet; m_FlowHandler.FlowNominalProperty.OnSetRamp += OnPropertyFlowNominalSetRamp; //m_FlowHandler.FlowNominalProperty.RampSyntax = true; // m_FlowHandler.FlowNominalProperty.IsRampSyntax is already True m_FlowHandler.FlowNominalProperty.Update(0); //m_FlowHandler.FlowValueProperty.RampSyntax = true; // m_FlowHandler.FlowValueProperty.IsRampSyntax is already True m_FlowHandler.FlowValueProperty.Update(0); m_EluentPercentA = 100; m_FlowHandler.ComponentProperties[0].Update(m_EluentPercentA); // Partial flow of this component, expressed in percent of the total flow. m_FlowHandler.EquateProperties[i].HelpText = "User-selectable designation of this solvent component." m_FlowHandler.ComponentProperties[1].Update(m_EluentPercentB); m_FlowHandler.ComponentProperties[2].Update(m_EluentPercentC); m_FlowHandler.ComponentProperties[3].Update(m_EluentPercentD); m_FlowHandler.EquateProperties[0].Update("Water"); m_FlowHandler.ComponentProperties[1].OnSetProperty += OnPropertyFlowHandler_ComponentProperty_2_Set; m_FlowHandler.ComponentProperties[2].OnSetProperty += OnPropertyFlowHandler_ComponentProperty_3_Set; m_FlowHandler.ComponentProperties[3].OnSetProperty += OnPropertyFlowHandler_ComponentProperty_4_Set; double pressureSignalMin = m_Properties.PressureLowerLimit.Value.GetValueOrDefault(); double pressureSignalMax = m_Properties.PressureUpperLimit.Value.GetValueOrDefault(); int pressureSignalDigits = 3; string pressureUnitName = m_Properties.PressureValue.DataType.Unit; UnitConversion.PhysUnitEnum pressureUnit = UnitConversionEx.PhysUnitFindName(pressureUnitName); m_ChannelPressure = new PumpChannelPressure(driver, ddk, m_Device, "Channel_Pressure_Id", "Channel_Pressure_Name", pressureSignalMin, pressureSignalMax, pressureSignalDigits, pressureUnit); m_Device.OnBatchPreflightBegin += OnDeviceBatchPreflightBegin; m_Device.OnBatchPreflightSample += OnDeviceBatchPreflightSample; m_Device.OnBatchPreflightEnd += OnDeviceBatchPreflightEnd; m_Device.OnPreflightBegin += OnDevicePreflightBegin; m_Device.OnPreflightLatch += OnDevicePreflightLatch; m_Device.OnPreflightSync += OnDevicePreflightSync; m_Device.OnPreflightBroadcast += OnDevicePreflightBroadcast; m_Device.OnPreflightEnd += OnDevicePreflightEnd; m_Device.OnTransferPreflightToRun += OnDeviceTransferPreflightToRun; m_Device.OnLatch += OnDeviceLatch; m_Device.OnSync += OnDeviceSync; // See these in the AutoSampler m_Device.OnSequenceStart += OnDeviceSequenceStart; m_Device.OnSequenceChange += OnDeviceSequenceChange; m_Device.OnSequenceEnd += OnDeviceSequenceEnd; m_Device.OnBroadcast += OnDeviceBroadcast; Log.TaskEnd(Id); } catch (Exception ex) { Log.TaskEnd(Id, ex); throw; } }
public void ChangeHandler <T>(T handler) where T : ICommandHandler, IFlowHandler { commandHandler = handler; flowHandler = handler; }