NMGRL_prepare_script

An example of a script used to load a gas sample into the Mass Spectrometer [|SocorroPrepBench-Prepare.cs] code format="csharp" // RegisterAssembly: DefinitionsCore.dll // RegisterAssembly: BasicHardware.dll // RegisterAssembly: PluginManager.dll // RegisterAssembly: HardwareClient.dll // RegisterAssembly: BasicHardware.dll // RegisterAssembly: plugin\HardwareScript.if.dll using System.Collections.Generic; using Thermo.Imhotep.BasicHardware; using Thermo.Imhotep.Definitions.Core; using Thermo.Imhotep.HardwareClientNS; //- public class InletSystemPrepare {   //-    #region Constants public const int Open = 1; public const int Close = 0; public const int On = 1; public const int Off = 0;

#endregion Constants //-   #region Constructors / Finalizer #endregion Constructors / Finalizer //-   #region Events #endregion Events //-   #region Public Properties static int SampleType = -1; #endregion Public Properties

//-   #region Public Methods ///-   ///     /// This method is used to determine the estimated duration which the task will execute. ///    /// The sample line index for which to get the estimated duration. /// The sample line information. /// The estimated duration which the task will execute. ///-   public static TimeSpan GetDuration(int sampleLineIndex, Dictionary sampleLineInfo) {       return TimeSpan.FromMinutes(12.0); }   ///-    ///     /// Get the last set information which needs to be displayed by the acquisition status. ///    /// The information status. ///-   public static string GetInformation {       return m_information; }   ///-    ///     /// This method is called when the script needs to abort it's current operation. ///    ///-    public static void Abort {       m_abort = true; }   ///-    ///     /// The execute method, responsible to check the sample line information. ///    /// The sample line index. /// The sample line information. /// true, when the sample line can be executed; otherwise, false ///-   public static bool Execute(int sampleLineIndex, Dictionary sampleLineInfo) {       bool result = true;

Logger.Log(LogLevel.Info, string.Format("Script: Sample line index {0} has the following columns and values:", sampleLineIndex));

foreach (KeyValuePair kvp in sampleLineInfo) {           Logger.Log(LogLevel.Info, string.Format("{0} -> {1}", kvp.Key, kvp.Value)); }       Logger.Log(LogLevel.Info, "Script: Sample line report done!");

object SmpTypeKey;

if (sampleLineInfo.TryGetValue("SocorroPrepBench.SampleInlet", out SmpTypeKey) == true) {           Logger.Log(LogLevel.Info, "Script: {0}", SmpTypeKey.ToString);

if (SmpTypeKey.ToString == "West Pipette") {               SampleType = 0; }           else if (SmpTypeKey.ToString == "East Pipette") {               SampleType = 1; }           else if (SmpTypeKey.ToString == "West Air Blank") {               SampleType = 2; }           else if (SmpTypeKey.ToString == "East Air Blank") {               SampleType = 3; }           else {               Logger.Log(LogLevel.Error, "Unknown sample Type"); result = false; }       }        else {           Logger.Log(LogLevel.Info, "Script: Could not identify sample type."); result = false; }

return result; }   ///-    ///     /// This is called when the script should run and all required tasks must be implemented here. ///    ///-    public static bool Run {       bool result = false; result=true; switch (SampleType) {           case 0: {                   m_information = "Starting West Air preparation"; result=PrepareAir("West Air"); }               break; case 1: {                   m_information = "Starting East Air preparation"; result=PrepareAir("East Air"); }               break; case 2: {                   m_information = "Starting West Air blank preparation"; result=PrepareAirBlank("West Air"); }               break; case 3: {                   m_information = "Starting East Air preparation"; result=PrepareAirBlank("East Air"); }               break; }

if (result) {           m_information = "Inlet System: 100% completed"; }       else {           m_information = "Error"; }

// Return true when the task completed successfully. return result; }

private static bool PrepareAirBlank(string pipetteName) {       return prepare_air(pipetteName, true); }   private static bool PrepareAir(string pipetteName) {       return prepare_air(pipetteName, false); }

private static bool prepare_air(string pipetteName, bool isBlank) {       string OUTER_PIPETTE string INNER_PIPETTE

string oOUTER_PIPETTE string oINNER_PIPETTE

string msg if (pipetteName=="West Air") {           OUTER_PIPETTE="Valve W"; INNER_PIPETTE="Valve X";

oOUTER_PIPETTE="Valve Y"; oINNER_PIPETTE="Valve Z";

msg="Prepare West Air" }       else {           OUTER_PIPETTE="Valve Y"; INNER_PIPETTE="Valve Z";

oOUTER_PIPETTE="Valve W"; oINNER_PIPETTE="Valve X";

msg="Prepare East Air"

}

if (isBlank) {           msg=msg+" Blank"; }

Logger.Log(LogLevel.Info, msg);

start_air_prepare;

//make sure other pipette is Close ArgusMC.SetParameter(oOUTER_PIPETTE,Close); Sleep(1, ""); ArgusMC.SetParameter(oINNER_PIPETTE, Close); Sleep(1, "");

//evacuate pipette

ArgusMC.SetParameter("Valve C", Close); ArgusMC.SetParameter(OUTER_PIPETTE, Open); Sleep(20, "Evacuating pipette"); ArgusMC.SetParameter(OUTER_PIPETTE, Close); Sleep(1, "");

if (!isBlank) {           msg="Filling pipette"; }       else {           msg="Filling pipette (NOT)";

}       //filling pipette if (!isBlank) {           ArgusMC.SetParameter("Valve Z", Open); }

Sleep(20, msg);

if (!isBlank) {           ArgusMC.SetParameter("Valve Z", Close);

}       Sleep(1, "");

//set bone and mini bone static ArgusMC.SetParameter("Valve P", Close); Sleep(1, ""); ArgusMC.SetParameter("Valve C", Close); Sleep(1, ""); ArgusMC.SetParameter("Valve D", Close); Sleep(1, "");

//expand airshot into bone and mini bone ArgusMC.SetParameter("Valve Y", Open); Sleep(1, ""); ArgusMC.SetParameter("Valve E", Open); Sleep(20, "Expanding airshot");

//isolate bone ArgusMC.SetParameter("Valve E", Close); Sleep(1,"");

//pump out minibone ArgusMC.SetParameter("Valve P", Open);

//ms static ArgusMC.SetParameter("Valve Ion Pump Set", Close); Sleep(1, "");

//equilibrating airshot ArgusMC.SetParameter("Valve H", Open); ArgusMC.SetTimeZero;

Sleep(20, "Equilibrating gas w/ Mass Spec");

ArgusMC.SetParameter("Valve H", Close); Sleep(1,"");

//pump out bone ArgusMC.SetParameter("Valve C", Open); ArgusMC.SetParameter("Valve D", Open);

//measure gas return true;

}

private static void start_air_prepare {       double sleep_time=1.0

//valves default ArgusMC.SetParameter("Valve Q", Close); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve H", Close); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve E", Close); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve D", Open); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve I", Open); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve Q", Close); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve P", Open); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve C", Open); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve F", Open); Sleep(sleep_time, "");

ArgusMC.SetParameter("Valve Ion Pump Set", Open);

}

///-   ///     /// Checks a hardware parameter and pulse the set value when the readback is not in the correct state. ///    ///-    private static bool CheckAndPulseHW(string readbackHW, bool pulseOnHigh, string setHW, double pulseHigh, double pulseLow, int timeMS) {       double value; if (ArgusMC.GetParameter(readbackHW, out value)) {           if ((pulseOnHigh && (value > 0.0)) || (!pulseOnHigh && (value == 0.0))) {               ArgusMC.SetParameter(setHW, pulseHigh); Thread.Sleep(timeMS); ArgusMC.SetParameter(setHW, pulseLow); }       }        else {           Logger.Log(LogLevel.Error, "Could not read out the current state of the Ion Gauge MS Enabled Readback!"); return false; }       return true; }   ///-    ///     /// This sleeps for the specified number of seconds and prints the given text. ///    ///-    private static bool Sleep(int seconds, string text) {       int numLoop = 0; bool showText = !string.IsNullOrEmpty(text); while (numLoop < seconds) {           Thread.Sleep(1000); if (showText) {               m_information = String.Format(text + "{0} s: {1}", seconds, numLoop); }

if (m_abort) {               return false; }           ++numLoop; }       return true; }   #endregion Public Methods //-   #region Interface Implementation #endregion Interface Implementation //-   #region Non-Public //-   #region Non-Public Members private static bool m_abort; private static string m_information; #endregion Non-Public Members //-   #endregion Non-Public //- } code