public MOTMasterSequence GetSequence() { MOTMasterSequence s = new MOTMasterSequence(); s.DigitalPattern = GetDigitalPattern(); s.AnalogPattern = GetAnalogPattern(); return s; }
public MOTMasterSequence GetSequence() { MOTMasterSequence s = new MOTMasterSequence(); s.DigitalPattern = GetDigitalPattern(); s.AnalogPattern = GetAnalogPattern(); return(s); }
public void StoreRun(string saveFolder, int batchNumber, string pathToPattern, string pathToHardwareClass, MOTMasterSequence sequence, Dictionary <String, Object> dict, Dictionary <String, Object> report, string externalFilesPath, string externalFilePattern) { string fileTag = getDataID(element, batchNumber); saveToFiles(fileTag, saveFolder, batchNumber, pathToPattern, pathToHardwareClass, dict, report, sequence); string[] files = putCopiesOfFilesToZip(saveFolder, fileTag, externalFilesPath, externalFilePattern); deleteFiles(files); }
public void Run(Dictionary <String, Object> dict) { Stopwatch watch = new Stopwatch(); MOTMasterScript script = prepareScript(scriptPath, dict); if (script != null) { MOTMasterSequence sequence = getSequenceFromScript(script); try { prepareCameraControl(); armTranslationStageForTimedMotion(script); GrabImage((int)script.Parameters["NumberOfFrames"]); buildPattern(sequence, (int)script.Parameters["PatternLength"]); waitUntilCameraIsReadyForAcquisition(); watch.Start(); runPattern(sequence); watch.Stop(); //MessageBox.Show(watch.ElapsedMilliseconds.ToString()); if (saveEnable) { waitUntilCameraAquisitionIsDone(); try { checkDataArrived(); } catch (DataNotArrivedFromHardwareControllerException) { return; } Dictionary <String, Object> report = GetExperimentReport(); save(script, scriptPath, imageData, report); } finishCameraControl(); disarmAndReturnTranslationStage(); } catch (System.Net.Sockets.SocketException e) { MessageBox.Show("CameraControllable not found. \n Is there a hardware controller running? \n \n" + e.Message, "Remoting Error"); } } else { MessageBox.Show("Unable to load pattern. \n Check that the script file exists and that it compiled successfully"); } }
private void initializeHardware(MOTMasterSequence sequence) { if (triggered == true) { pg.Configure(config.DigitalPatternClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true, true); } else { pg.Configure(config.DigitalPatternClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true, false); } apg.Configure(sequence.AnalogPattern, config.AnalogPatternClockFrequency, false); }
private void storeAnalogPattern(string dataStoreFilePath, MOTMasterSequence sequence) { Dictionary <String, Dictionary <Int32, Double> > analogPatterns = sequence.AnalogPattern.AnalogPatterns; var settings = new DataContractJsonSerializerSettings(); settings.UseSimpleDictionaryFormat = true; // Make format of json file {key : value} instead of {"Key": key, "Value": value} DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary <String, Dictionary <Int32, Double> >), settings); TextWriter output = File.CreateText(dataStoreFilePath); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, analogPatterns); output.Write(Encoding.Default.GetString(ms.ToArray())); output.Close(); } }
private void storeDigitalPattern(string dataStoreFilePath, MOTMasterSequence sequence) { Hashtable digitalChannelsHash = DAQ.Environment.Environs.Hardware.DigitalOutputChannels; Dictionary <string, int> digitalChannels = new Dictionary <string, int>(); foreach (DictionaryEntry pair in digitalChannelsHash) { string patternGeneratorBoard = (string)DAQ.Environment.Environs.Hardware.GetInfo("PatternGeneratorBoard"); if (((DigitalOutputChannel)pair.Value).Device == patternGeneratorBoard) { digitalChannels.Add((string)pair.Key, ((DigitalOutputChannel)pair.Value).BitNumber); } } var settings = new DataContractJsonSerializerSettings(); settings.UseSimpleDictionaryFormat = true; // Make format of json file {key : value} instead of {"Key": key, "Value": value} DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary <string, int>), settings); string digitalPatternString = sequence.DigitalPattern.Layout.ToString(); TextWriter output = File.CreateText(dataStoreFilePath); output.Write("{"); output.Write("\"channels\":"); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, digitalChannels); output.Write(Encoding.Default.GetString(ms.ToArray())); } output.Write(","); output.Write("\"pattern\":"); output.Write("\""); output.Write(System.Web.HttpUtility.JavaScriptStringEncode(digitalPatternString)); output.Write("\""); output.Write("}"); output.Close(); }
private void buildPattern(MOTMasterSequence sequence, int patternLength) { sequence.DigitalPattern.BuildPattern(patternLength); sequence.AnalogPattern.BuildPattern(); }
private void runPattern(MOTMasterSequence sequence) { initializeHardware(sequence); run(sequence); releaseHardwareAndClearDigitalPattern(sequence); }
public void Run(Dictionary <String, Object> dict) { Stopwatch watch = new Stopwatch(); MOTMasterScript script = prepareScript(scriptPath, dict); if (script != null) { MOTMasterSequence sequence = getSequenceFromScript(script); try { prepareCameraControl(); Console.WriteLine("prepared Camera Control"); armTranslationStageForTimedMotion(script); GrabImage((int)script.Parameters["NumberOfFrames"]); Console.WriteLine("'grabbed image'"); buildPattern(sequence, (int)script.Parameters["PatternLength"]); Console.WriteLine("built pattern"); waitUntilCameraIsReadyForAcquisition(); watch.Start(); Console.WriteLine("watch started"); runPattern(sequence); Console.WriteLine("sequence finished"); watch.Stop(); Console.WriteLine("watch stopped"); //MessageBox.Show(watch.ElapsedMilliseconds.ToString()); if (saveEnable) { Console.WriteLine("waiting for camera acquisition to finish"); waitUntilCameraAquisitionIsDone(); Console.WriteLine("waited for camera acquisition to finish"); try { checkDataArrived(); } catch (DataNotArrivedFromHardwareControllerException) { Console.WriteLine("Data not arrived from hardware controller"); return; } int[] ROIforImageProcessing = { (int)script.Parameters["ROIforImageProcessingx1"], (int)script.Parameters["ROIforImageProcessingx2"], (int)script.Parameters["ROIforImageProcessingy1"], (int)script.Parameters["ROIforImageProcessingy2"] }; processImages(ROIforImageProcessing); Console.WriteLine("processed images"); Dictionary <String, Object> report = GetExperimentReport(); Console.WriteLine("got experiment report"); if (absImage == null) { save(script, scriptPath, imageData, report); } else { save(script, scriptPath, imageData, absImage, columnSum, rowSum, report); } Console.WriteLine("saved images"); } else { Console.WriteLine("waiting for camera acquisition to finish"); waitUntilCameraAquisitionIsDone(); Console.WriteLine("waited for camera acquisition to finish"); } finishCameraControl(); Console.WriteLine("finished camera control"); disarmAndReturnTranslationStage(); } catch (System.Net.Sockets.SocketException e) { MessageBox.Show("CameraControllable not found. \n Is there a hardware controller running? \n \n" + e.Message, "Remoting Error"); } } else { MessageBox.Show("Unable to load pattern. \n Check that the script file exists and that it compiled successfully"); } }
private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence) { sequence.DigitalPattern.Clear(); //No clearing required for analog (I think). pg.StopPattern(); apg.StopPattern(); }
private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence) { clearDigitalPattern(sequence); releaseHardware(); }
private void clearDigitalPattern(MOTMasterSequence sequence) { sequence.DigitalPattern.Clear(); //No clearing required for analog (I think). }
public void Go(Dictionary <String, Object> dict) { status = RunningState.running; Stopwatch watch = new Stopwatch(); MOTMasterScript script = prepareScript(scriptPath, dict); if (script != null) { MOTMasterSequence sequence = getSequenceFromScript(script); try { if (config.CameraUsed) { prepareCameraControl(); } if (config.TranslationStageUsed) { armTranslationStageForTimedMotion(script); } if (config.CameraUsed) { GrabImage((int)script.Parameters["NumberOfFrames"]); } buildPattern(sequence, (int)script.Parameters["PatternLength"]); if (config.CameraUsed) { waitUntilCameraIsReadyForAcquisition(); } watch.Start(); if (controllerWindow.RunUntilStoppedState) { while (status == RunningState.running) { if (!config.Debug) { runPattern(sequence); } } } else { for (int i = 0; i < controllerWindow.GetIterations() && status == RunningState.running; i++) { if (!config.Debug) { runPattern(sequence); } } } if (!config.Debug) { clearDigitalPattern(sequence); } watch.Stop(); //MessageBox.Show(watch.ElapsedMilliseconds.ToString()); if (saveEnable) { if (config.CameraUsed) { waitUntilCameraAquisitionIsDone(); try { checkDataArrived(); } catch (DataNotArrivedFromHardwareControllerException) { return; } Dictionary <String, Object> report = null; if (config.ReporterUsed) { report = GetExperimentReport(); } save(script, scriptPath, imageData, report); } else { Dictionary <String, Object> report = null; if (config.ReporterUsed) { report = GetExperimentReport(); } save(script, scriptPath, report); } } if (config.CameraUsed) { finishCameraControl(); } if (config.TranslationStageUsed) { disarmAndReturnTranslationStage(); } } catch (System.Net.Sockets.SocketException e) { MessageBox.Show("CameraControllable not found. \n Is there a hardware controller running? \n \n" + e.Message, "Remoting Error"); } } else { MessageBox.Show("Unable to load pattern. \n Check that the script file exists and that it compiled successfully"); } status = RunningState.stopped; }
private MOTMasterSequence getSequenceFromScript(MOTMasterScript script) { MOTMasterSequence sequence = script.GetSequence(); return(sequence); }
private void initializeHardware(MOTMasterSequence sequence) { pg.Configure(pgClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true); apg.Configure(sequence.AnalogPattern, apgClockFrequency); }
private void saveToFiles(string fileTag, string saveFolder, int batchNumber, string pathToPattern, string pathToHardwareClass, Dictionary <String, Object> dict, Dictionary <String, Object> report, MOTMasterSequence sequence) { storeDigitalPattern(saveFolder + fileTag + "_digitalPattern.json", sequence); storeAnalogPattern(saveFolder + fileTag + "_analogPattern.json", sequence); storeDictionary(saveFolder + fileTag + "_parameters.txt", dict); File.Copy(pathToPattern, saveFolder + fileTag + "_script.cs"); File.Copy(pathToHardwareClass, saveFolder + fileTag + "_hardwareClass.cs"); storeDictionary(saveFolder + fileTag + "_hardwareReport.txt", report); }
private void run(MOTMasterSequence sequence) { apg.OutputPatternAndWait(sequence.AnalogPattern.Pattern); pg.OutputPattern(sequence.DigitalPattern.Pattern); }
private void initializeHardware(MOTMasterSequence sequence) { pg.Configure(pgClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true, false); apg.Configure(sequence.AnalogPattern, apgClockFrequency); }
private void save(MOTMasterSequence sequence, MOTMasterScript script, string pathToPattern, Dictionary <String, Object> report) { ioHelper.StoreRun(motMasterDataPath, controllerWindow.GetSaveBatchNumber(), pathToPattern, hardwareClassPath, sequence, script.Parameters, report, externalFilesPath, config.ExternalFilePattern); }