private void RunProtocol(int ProtocolID, string PlateName) { counter = 0; //int ProtocolID = 2000103;//This is my OD Protocol //returns true if successful, false otherwise try { //First have to make sure the machine is working UpdateStatus(); if (CurrentStatus != InstrumentState.Ready) {//if the instrument isn't ready, try for 10 seconds to make it ready, then abort for (int i = 0; i < 20; i++) { UpdateStatus(); if (CurrentStatus == InstrumentState.Ready) { break; } Thread.Sleep(500); } //if this fails, return false if (CurrentStatus != InstrumentState.Ready) { LastCommandResult = new CommandResult("Instrument Status Was Never Ready"); PulseObject(); return; } } //Onwards with the protocol MlrServ.AssayRunDefinitionClass AssayRunDef = new AssayRunDefinitionClass(); AssayRunDef.ProtocolID = ProtocolID; AssayRunDef.LoadFirstPlate = true; AssayRunDef.Notes = NextPlateName; //Create new m_Assay (and run if in demo mode) m_Assay = InstrumentServ.NewAssay(AssayRunDef as AssayRunDefinition) as Assay; //Check that the object was created if (m_Assay == null) { txtErrors.Text += "\nUnable to start new m_Assay (" + InstrumentServ.GetLastErrorText() + ")"; LastCommandResult = new CommandResult("Was unable to start assay"); PulseObject(); return; } } catch { txtErrors.Text += "\nUnexplained Error During Reading"+DateTime.Now.ToString()+"\n"; LastCommandResult = new CommandResult("Unexplained Error"); PulseObject(); CurrentStatus = InstrumentState.Busted; return; } return; }
private void MovePlateDataToNewDirectory(string PlateName,string FileName) { string TimeOutError = "File Did Not Appear Within The Required Time"; string DirectoryToPlace = DataDirectory + PlateName; try { if (!Directory.Exists(DirectoryToPlace)) { Directory.CreateDirectory(DirectoryToPlace); } //Now to grab the file string OldFileName = DataDirectory + FileName + ".txt"; string OldFileName2 = DataDirectory + FileName + ".xls"; string NewFileName = DataDirectory + PlateName + "\\" + PlateName + "_" + FileName + ".txt"; string NewFileName2 = DataDirectory + PlateName + "\\" + PlateName + "_" + FileName + ".xls"; int MaxCounter = 14; if (counter == MaxCounter) { LastCommandResult = new CommandResult(TimeOutError); LastCommandResult.ErrorSetAlready = true; txtErrors.Text += "Failed to Move DataFile: " + FileName + " for " + PlateName+"\n"+TimeOutError; throw new Exception(TimeOutError); } while (!File.Exists(OldFileName) && !File.Exists(OldFileName2) && counter < MaxCounter)//the program often fires the event finished event before it finishes, so this attempts this several times { Thread.Sleep(3000); counter++; } //keep it in xls if needed if (!File.Exists(OldFileName)) { OldFileName = OldFileName2; NewFileName = NewFileName2; } ValidateName(NewFileName); File.Move(OldFileName, NewFileName); counter = 0; } catch(Exception thrown) { if (thrown.Message == TimeOutError || thrown.Message.Contains("not valid")) throw thrown; else { Thread.Sleep(15000);//wait 10 seconds in case the victor has a file lock on it MovePlateDataToNewDirectory(PlateName, FileName); } } }
private void EventFinishedSuccessfully() { try { if (m_Assay != null && LastCommandResult != null && !LastCommandResult.ErrorSetAlready) { string Filename = m_Assay.GetAssayID().ToString(); MovePlateDataToNewDirectory(NextPlateName, Filename); LastCommandResult = new CommandResult(); if (CompletedAssayIDs.Count > 5) { CompletedAssayIDs.Clear(); } CompletedAssayIDs.Add(m_Assay.GetAssayID()); } } catch { txtErrors.Text += "\n\nProblem Moving File and Ending Assay\n"; } finally { PulseObject(); txtErrors.Text += "\nEvent Finish Call at: " + DateTime.Now.ToString(); } // }
void InstrumentServ_OnError(string ErrorMessage, int ErrorCode, int Choices, ref ErrorAction Action) { //This is vital and I believe means that the dang thing will no longer throw //a dialog box up, thus blocking the code (which of course would be unknown to the other programs) Action = ErrorAction.Abort; LastCommandResult = new CommandResult(ErrorMessage); PulseObject(); //by setting the action I effectively make a decision, I expect this program to usually work //and so am always going to abort, in the future I could try the default options, or ok, or whatever }
public void RunDifferentProtocol() { //This method is used to run a non-standard protocol, (anyone that does not use OD600, very similar to the one above) try { LastCommandResult = new CommandResult("Object Never Was Initialized Except At The Start Of Method, Big Problem"); LastCommandResult.ErrorSetAlready = false; RunProtocol(NextProtocolIdentifier, NextPlateName); } catch { } }