public bool AttemptToReseatLid(Protocol toModify, AdditionalMethodArguments eargs) { IncubatorServ Incubator = eargs.InstrumentCollection.ReturnInstrumentType<IncubatorServ>(); TransferStation TransStation = eargs.InstrumentCollection.ReturnInstrumentType<TransferStation>(); Twister Robot = eargs.InstrumentCollection.ReturnInstrumentType<Twister>(); TransStation.TurnOnVacuumAndLiftLid(); TransStation.MoveStationOut(); Robot.MovePlateFromTransferStationToPlateReader(eargs); TransStation.MoveStationIn(); TransStation.TurnOffVacuumAndReturnLid(); TransStation.TurnOnVacuumAndLiftLid(); TransStation.MoveStationOut(); Robot.MovePlateFromPlateReaderToIncubator(); TransStation.MoveStationIn(); TransStation.TurnOffVacuumAndReturnLid(); return true; }
//TODO: Convert so that htis uses XML serialization instead //http://support.microsoft.com/kb/815813 public static void ProtocolToXMLFile(Protocol curProtocol, string Filename) { XmlTextWriter XWriter = new XmlTextWriter(Filename, Encoding.ASCII); XWriter.Formatting = Formatting.Indented; XWriter.WriteStartDocument(); XWriter.WriteStartElement("Protocol"); //first to write the name XWriter.WriteStartElement("ProtocolName"); XWriter.WriteString(curProtocol.ProtocolName); XWriter.WriteEndElement(); //now the error emails XWriter.WriteStartElement("ErrorEmailAddress"); XWriter.WriteValue(curProtocol.ErrorEmailAddress); XWriter.WriteEndElement(); //now the phone number XWriter.WriteStartElement("ErrorPhoneNumber"); XWriter.WriteValue(curProtocol.ErrorPhoneNumber); XWriter.WriteEndElement(); //Here we have code to loop through and drop the variables in XWriter.WriteStartElement("Variables"); foreach (string varName in curProtocol.Variables.Keys) { ProtocolVariable PV = curProtocol.Variables[varName]; XWriter.WriteStartElement("Variable"); XWriter.WriteStartElement("Name"); XWriter.WriteString(PV.Name); XWriter.WriteEndElement(); XWriter.WriteStartElement("Value"); XWriter.WriteStartAttribute("Type"); XWriter.WriteValue(PV.DataType.ToString()); XWriter.WriteEndAttribute(); XWriter.WriteValue(PV.Value.ToString()); XWriter.WriteEndElement(); XWriter.WriteEndElement(); } XWriter.WriteEndElement();//end variables XWriter.WriteStartElement("Instructions"); //now to loop through all the instructions and make it happen foreach (object o in curProtocol.Instructions) { XWriter.WriteStartElement("Instruction"); XWriter.WriteStartAttribute("InstType"); XWriter.WriteValue(o.GetType().ToString()); XWriter.WriteEndAttribute(); //now to unload the properties here //System.Windows.Forms.MessageBox.Show(o.GetType().GetProperties().Length.ToString()); var toTest = Type.GetType("System.Object[]"); foreach (FieldInfo PI in o.GetType().GetFields()) { if (PI.FieldType.ToString() == "System.Object[]") //the parameters are always passed as an object array, this is kind of silly now since all my methods only take one argument, but in the future who knows. { object[] Params = (object[])PI.GetValue(o); XWriter.WriteStartElement("Parameters"); foreach (object Param in Params) { XWriter.WriteStartElement("Parameter"); XWriter.WriteStartAttribute("Type"); XWriter.WriteValue(Param.GetType().ToString()); XWriter.WriteEndAttribute(); //XWriter.WriteValue(Param); //switched to accomodate new types XWriter.WriteString(Param.ToString()); XWriter.WriteEndElement(); } XWriter.WriteEndElement(); } else if (PI.FieldType == typeof(Protocol)) continue;//Ignore the containing protocol bit else { XWriter.WriteStartElement(PI.Name); XWriter.WriteStartAttribute("Type"); XWriter.WriteValue(PI.FieldType.ToString()); XWriter.WriteEndAttribute(); XWriter.WriteValue(PI.GetValue(o));//should throw an error if not a valid type XWriter.WriteEndElement(); } } XWriter.WriteEndElement(); } XWriter.WriteEndElement(); XWriter.WriteEndElement(); XWriter.WriteEndDocument(); XWriter.Close(); }
public static Protocol XMLFileToProtocol(string Filename) { //Starting to approach the point where I need to break this up.... //7-27-2012 now trying to select nodes. Protocol NewProtocol = new Protocol(); XmlDocument XmlDoc = new XmlDocument(); XmlTextReader XReader = new XmlTextReader(Filename);//http://dn.codegear.com/article/32384 XmlDoc.Load(XReader); //first node is xml, second is the protocol, this is assumed and should be the case //XmlNode ProtocolXML = XmlDoc.ChildNodes[1]; XmlNode ProtocolXML = XmlDoc.SelectSingleNode("/Protocol"); XmlNode name=ProtocolXML.SelectSingleNode("/ProtocolName"); NewProtocol.ProtocolName = ProtocolXML.SelectSingleNode("ProtocolName").InnerText; NewProtocol.ErrorPhoneNumber = ProtocolXML.SelectSingleNode("ErrorPhoneNumber").InnerText; NewProtocol.ErrorEmailAddress = ProtocolXML.SelectSingleNode("ErrorEmailAddress").InnerText; Assembly assembly = Assembly.GetExecutingAssembly(); XmlNode VariablesNode = ProtocolXML.SelectSingleNode("Variables"); if (VariablesNode != null) { foreach (XmlNode variable in VariablesNode.ChildNodes) { string Name = variable.ChildNodes[0].InnerText; string variableTypeString = variable.ChildNodes[1].Attributes[0].Value; Type VariableType = System.Type.GetType(variableTypeString); object valueAsString = variable.ChildNodes[1].InnerText; var Value = Convert.ChangeType(valueAsString, VariableType); ProtocolVariable PV = new ProtocolVariable(Name, VariableType, Value); NewProtocol.Variables.Add(PV.ToString(), PV); } } XmlNode instructionsNode = ProtocolXML.SelectSingleNode("Instructions"); foreach (XmlNode instruct in instructionsNode.ChildNodes) { string DataType = instruct.Attributes[0].Value; Type InstructionType = assembly.GetType(DataType); object ProtocolInstruction = Activator.CreateInstance(InstructionType); string ValueType, Value; foreach (XmlNode Property in instruct.ChildNodes) { if (Property.Name == "Parameters")//this means I have a static protocol item { ArrayList AL = new ArrayList(); object[] ParameterArray; if (Property.ChildNodes.Count == 0) { ParameterArray = new object[0]; } else { ParameterArray = new object[Property.ChildNodes.Count]; int ParameterIndex = 0; foreach (XmlNode Parameter in Property.ChildNodes) { ValueType = Parameter.Attributes[0].Value; Value = Parameter.InnerText; ParameterArray[ParameterIndex] = ReturnValue(ValueType, Value); ParameterIndex++; } } StaticProtocolItem ProtocolItem = (StaticProtocolItem)ProtocolInstruction; ProtocolItem.Parameters = ParameterArray; ProtocolItem.ContainingProtocol = NewProtocol; } else { FieldInfo FI = ProtocolInstruction.GetType().GetField(Property.Name); ValueType = Property.Attributes[0].Value; Value = Property.InnerText; object ValuetoSet = ReturnValue(ValueType, Value); FI.SetValue(ProtocolInstruction, ValuetoSet); } } NewProtocol.Instructions.Add(ProtocolInstruction as ProtocolInstruction); } XReader.Close(); return NewProtocol; }
/// <summary> /// Sets the current protocol to the next one to run. /// </summary> public void UpdateCurrentProtocol() { if (Protocols.Count > 0) { Protocols.Sort((x, y) => x.NextExecutionTimePoint.CompareTo(y.NextExecutionTimePoint)); CurrentProtocolInUse = Protocols[0]; } }
public void RemoveProtocol(Protocol ProtocolToRemove) { if (Protocols.Count == 1) {//empty out the current protocol in use CurrentProtocolInUse = null; Protocols.Remove(ProtocolToRemove); } else { if (CurrentProtocolInUse == ProtocolToRemove) { CurrentProtocolInUse = null; Protocols.Remove(ProtocolToRemove); FindMilliSecondsUntilNextRunAndChangeCurrentProtocol(); } else { Protocols.Remove(ProtocolToRemove); } } UpdateAlarmProtocols(); }
public void AddProtocol(Protocol ProtocolToAdd) { ProtocolToAdd.NextExecutionTimePoint = DateTime.Now; if (Protocols.Count == 0)//check if this is the most current protocol { CurrentProtocolInUse = ProtocolToAdd; } Protocols.Add(ProtocolToAdd); UpdateAlarmProtocols(); }
public static bool VerifyProtocolVariablesReferences(Protocol ProtocolToRun) { //This is a method that will ensure that all of the references to variables in a protocol work out, //it will go through the instructions and check that the variables that are referenced exist foreach (object o in ProtocolToRun.Instructions) { if (o is StaticProtocolItem) { StaticProtocolItem SP = (StaticProtocolItem)o; //now to move through and check all foreach (object Param in SP.Parameters) { if (Param is string) { //check all variable names in a string List<string> VariableNames = GetAllVaraibleNamesFromText((string)Param); foreach (string vName in VariableNames) { if (!ProtocolToRun.Variables.ContainsKey(vName)) { return false; } } } else if (Param is ReferenceToProtocolVariable) { ReferenceToProtocolVariable CurRef = (ReferenceToProtocolVariable)Param; if (!ProtocolToRun.Variables.ContainsKey(CurRef.ToString())) { return false; } } } } } return true; }
private Protocol CreateProtocolFromForm() { Protocol newProtocol = new Protocol(); if (txtProtocolName.Text == "" | txtEmails.Text == "") { throw new Exception("You must name your protocol and provide an email address"); } if (lstProtocol.Items.Count == 0) { throw new Exception("There are no instructions in your protocol, please add them."); } newProtocol.ErrorEmailAddress = txtEmails.Text; newProtocol.ErrorPhoneNumber = txtNumbers.Text; newProtocol.ProtocolName = txtProtocolName.Text; newProtocol.Instructions = ProtocolListBoxToProtocolInstructionList(lstProtocol); foreach (object o in lstCurrentVariables.Items) { ProtocolVariable PV = (ProtocolVariable)o; newProtocol.Variables.Add(PV.ToString(), PV); } //newProtocol.Instructions = ProtocolConverter.ProtocolWithRepeatsToProtocolWithout(newProtocol.Instructions); return newProtocol; }
/// <summary> /// This method creates a protocol to run a certain type of /// experiment for the user, in this case an experiment that moves plates /// from an incubator to a plate reader periodically. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStartGrowthRate_Click(object sender, EventArgs e) { try { //this will create and start a protocol, first to check for errors int minuteDelay = 0; int cycles = 0; if (txtGrowthRateEmail.Text == "" | txtGrowthRateExperimentName.Text == "" | txtGrowthRateMinutes.Text == "" | txtGrowthRateTimesToMeasure.Text == "") { ShowError("You did not fill out all of the required fields"); } else if (lstGrowthRatesProtocol.SelectedIndex == -1) { ShowError("You did not select any slots"); } // For SkypeAlarm else if (ClarityEngine.UseAlarm && ClarityEngine.Clarity_Alarm!=null && ClarityEngine.Clarity_Alarm.Connected && !ClarityEngine.Clarity_Alarm.ValidNumbers(textbox_number.Text)) { ShowError("Your number is not valid!"); } else { try { minuteDelay = Convert.ToInt32(txtGrowthRateMinutes.Text); cycles = Convert.ToInt32(txtGrowthRateTimesToMeasure.Text); } catch { ShowError("Could not convert your delay or measurement into an integer, please enter an appropriate value"); return; } if (minuteDelay < 9 | minuteDelay > 25 * 60) { ShowError("Your delay time is weird, please make it greater then 9 minutes or less than 25 hours"); return; } if (cycles < 0 | cycles > 200) { ShowError("You seem to have selected less than 0 or more than 200 readings, please pick an alternative"); return; } Protocol NewProt = new Protocol(); NewProt.ProtocolName = txtGrowthRateExperimentName.Text; NewProt.ErrorEmailAddress = txtGrowthRateEmail.Text; NewProt.ErrorPhoneNumber = textbox_number.Text; NewProt.Instructions = new List<ProtocolInstruction>(); for (int i = 0; i < cycles; i++) { foreach (int plateslot in lstGrowthRatesProtocol.SelectedItems) { //move from incubator to platereader StaticProtocolItem SP = new StaticProtocolItem(); SP.InstrumentName = "Macros"; SP.Parameters = new object[1] { plateslot }; SP.MethodName = "MovePlateFromIncubatorToVictor"; NewProt.Instructions.Add(SP); //read plate StaticProtocolItem SP2; if (chk48WellPlate.Checked) { SP2 = new StaticProtocolItem(); SP2.MethodName = "ReadPlate2"; SP2.InstrumentName = "PlateReader"; SP2.Parameters = new object[2] { NewProt.ProtocolName + INSTRUMENT_NAME_DELIMITER + plateslot.ToString(), WELL48_PLATE_PROTOCOL_ID }; NewProt.Instructions.Add(SP2); } else if (chkGBO.Checked) { SP2 = new StaticProtocolItem(); SP2.MethodName = "ReadPlate2"; SP2.InstrumentName = "PlateReader"; SP2.Parameters = new object[2] { NewProt.ProtocolName + INSTRUMENT_NAME_DELIMITER + plateslot.ToString(), GBO_PLATE_PROTOCOL_ID }; NewProt.Instructions.Add(SP2); } else { SP2 = new StaticProtocolItem(); SP2.MethodName = "ReadPlate"; SP2.InstrumentName = "PlateReader"; SP2.Parameters = new object[1] { NewProt.ProtocolName + INSTRUMENT_NAME_DELIMITER + plateslot.ToString() }; NewProt.Instructions.Add(SP2); } //now to move the old plate back SP2 = SP.Clone(); SP2.MethodName = "MovePlateFromVictorToIncubatorWithLidOnTransferStation"; NewProt.Instructions.Add(SP2); } DelayTime DT = new DelayTime(); DT.minutes = minuteDelay; NewProt.Instructions.Add(DT); } DialogResult DR = MessageBox.Show("Are you sure you have entered the right values and are ready to load this protocol?", "Final Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DR == DialogResult.Yes) { ClarityEngine.AddProtocol(NewProt); UpdateLoadedProtocols(); if (ClarityEngine.CurrentRunningState == RunningStates.Idle)//this timer is running while a protocol is waiting to go { DialogResult DR2 = MessageBox.Show("Would you like to start your protocol immediately?", "Begin Protocol", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DR2 == DialogResult.Yes) { ClarityEngine.StartProtocolExecution(); } } } } } catch { ShowError("Weird error occurred"); } }
private void btnGenerateNSFData_Click(object sender, EventArgs e) { try { int tranNum; List<Protocol> ProtsToAdd = new List<Protocol>(); //this will create and start a protocol, first to check for errors if (txtNSFTransferNumber.Text == "" | txtNSFName.Text == "") { ShowError("You did not fill out all of the required fields"); } else if (lstNSFPlates.SelectedIndex == -1) { ShowError("You did not select any slots"); } else { try { tranNum = Convert.ToInt32(txtNSFTransferNumber.Text); } catch { ShowError("Could not convert your transfer number into an integer, please enter an appropriate value"); return; } //NSFExperiment tmp = new NSFExperiment(); foreach (int plateslot in lstNSFPlates.SelectedItems) { Protocol NewProt = new Protocol(); NewProt.ErrorEmailAddress = ""; string baseName = "NSF-" + txtNSFName.Text + "-" + txtNSFTransferNumber.Text.ToString(); NewProt.ProtocolName = baseName + "_" + plateslot.ToString(); StaticProtocolItem SP = new StaticProtocolItem(); SP.MethodName = "CreateProtocol"; //SP.InstrumentName = tmp.Name; SP.Parameters = new object[2] { baseName, plateslot }; NewProt.Instructions.Add(SP); ProtsToAdd.Add(NewProt); } Protocol Watcher = new Protocol(); Watcher.ProtocolName = "NSF-Error-" + txtNSFTransferNumber.Text.ToString(); Watcher.ErrorPhoneNumber = "4158234767"; Watcher.MaxIdleTimeBeforeAlarm = 50; Watcher.ErrorEmailAddress = this.NSFErrorEmails; DelayTime DT = new DelayTime(); DT.minutes = 60 * 70; Watcher.Instructions.Add(DT); ProtsToAdd.Add(Watcher); } DialogResult DR = MessageBox.Show("Are you sure you have entered the right values and are ready to load this protocol?", "Final Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DR == DialogResult.Yes) { foreach (Protocol p in ProtsToAdd) { ClarityEngine.AddProtocol(p); } UpdateLoadedProtocols(); if (ClarityEngine.CurrentRunningState==RunningStates.Idle)//this timer is running while a protocol is waiting to go { DialogResult DR2 = MessageBox.Show("Would you like to start your protocols immediately?", "Begin Protocol", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DR2 == DialogResult.Yes) { ClarityEngine.StartProtocolExecution(); } } } } catch { ShowError("Weird error occurred"); } }