Пример #1
0
 public MOTMasterSequence GetSequence()
 {
     MOTMasterSequence s = new MOTMasterSequence();
     s.DigitalPattern = GetDigitalPattern();
     s.AnalogPattern = GetAnalogPattern();
     return s;
 }
Пример #2
0
        public MOTMasterSequence GetSequence()
        {
            MOTMasterSequence s = new MOTMasterSequence();

            s.DigitalPattern = GetDigitalPattern();
            s.AnalogPattern  = GetAnalogPattern();
            return(s);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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");
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
        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();
        }
Пример #8
0
 private void buildPattern(MOTMasterSequence sequence, int patternLength)
 {
     sequence.DigitalPattern.BuildPattern(patternLength);
     sequence.AnalogPattern.BuildPattern();
 }
Пример #9
0
 private void runPattern(MOTMasterSequence sequence)
 {
     initializeHardware(sequence);
     run(sequence);
     releaseHardwareAndClearDigitalPattern(sequence);
 }
Пример #10
0
        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");
            }
        }
Пример #11
0
 private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence)
 {
     sequence.DigitalPattern.Clear(); //No clearing required for analog (I think).
     pg.StopPattern();
     apg.StopPattern();
 }
Пример #12
0
 private void runPattern(MOTMasterSequence sequence)
 {
     initializeHardware(sequence);
     run(sequence);
     releaseHardwareAndClearDigitalPattern(sequence);
 }
Пример #13
0
 private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence)
 {
     clearDigitalPattern(sequence);
     releaseHardware();
 }
Пример #14
0
 private void buildPattern(MOTMasterSequence sequence, int patternLength)
 {
     sequence.DigitalPattern.BuildPattern(patternLength);
     sequence.AnalogPattern.BuildPattern();
 }
Пример #15
0
 private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence)
 {
     clearDigitalPattern(sequence);
     releaseHardware();
 }
Пример #16
0
 private void clearDigitalPattern(MOTMasterSequence sequence)
 {
     sequence.DigitalPattern.Clear(); //No clearing required for analog (I think).
 }
Пример #17
0
        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;
        }
Пример #18
0
        private MOTMasterSequence getSequenceFromScript(MOTMasterScript script)
        {
            MOTMasterSequence sequence = script.GetSequence();

            return(sequence);
        }
Пример #19
0
 private void releaseHardwareAndClearDigitalPattern(MOTMasterSequence sequence)
 {
     sequence.DigitalPattern.Clear(); //No clearing required for analog (I think).
     pg.StopPattern();
     apg.StopPattern();
 }
Пример #20
0
 private void clearDigitalPattern(MOTMasterSequence sequence)
 {
     sequence.DigitalPattern.Clear(); //No clearing required for analog (I think).
 }
Пример #21
0
 private void initializeHardware(MOTMasterSequence sequence)
 {
     pg.Configure(pgClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true);
     apg.Configure(sequence.AnalogPattern, apgClockFrequency);
 }
Пример #22
0
 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);
 }
Пример #23
0
 private void run(MOTMasterSequence sequence)
 {
     apg.OutputPatternAndWait(sequence.AnalogPattern.Pattern);
     pg.OutputPattern(sequence.DigitalPattern.Pattern);
 }
Пример #24
0
 private void run(MOTMasterSequence sequence)
 {
     apg.OutputPatternAndWait(sequence.AnalogPattern.Pattern);
     pg.OutputPattern(sequence.DigitalPattern.Pattern);
 }
Пример #25
0
 private void initializeHardware(MOTMasterSequence sequence)
 {
     pg.Configure(pgClockFrequency, false, true, true, sequence.DigitalPattern.Pattern.Length, true, false);
     apg.Configure(sequence.AnalogPattern, apgClockFrequency);
 }
Пример #26
0
 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);
 }