Beispiel #1
0
 public int SetModuleDirectory(string ModuleDirectoryPath)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.SetModuleDirectoryExternal(theModel, ModuleDirectoryPath));
 }
Beispiel #2
0
 public int LoadModuleParameters(string ModuleParameterFileName)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.LoadModuleParametersExternal(theModel, ModuleParameterFileName));
 }
Beispiel #3
0
 public void SetLogCallback(LogCallback theCallback)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     DesktopEarlabDLL.SetLogCallbackExternal(theModel, theCallback);
 }
Beispiel #4
0
 public DesktopEarlabDLL()
 {
     theModel = DesktopEarlabDLL.CreateModelExternal();
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Failed to initialize model");
     }
 }
Beispiel #5
0
 public int StopModules()
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.StopModulesExternal(theModel));
 }
Beispiel #6
0
 public int RunModel(int NumFrames)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.RunModelExternal(theModel, NumFrames));
 }
Beispiel #7
0
 public void SetOutputDirectory(string OutputDirectoryPath)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     DesktopEarlabDLL.SetOutputDirectoryExternal(theModel, OutputDirectoryPath);
 }
Beispiel #8
0
 public int UnloadModel()
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     Environment.CurrentDirectory = SavedPath;
     return(DesktopEarlabDLL.UnloadModelExternal(theModel));
 }
Beispiel #9
0
 public int LoadModelConfigFile(string ModelConfigFileName, float FrameSize_uS)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     SavedPath = Environment.CurrentDirectory;
     Environment.CurrentDirectory = Path.GetDirectoryName(ModelConfigFileName);
     return(DesktopEarlabDLL.LoadModelConfigFileExternal(theModel, ModelConfigFileName, FrameSize_uS));
 }
Beispiel #10
0
        private void RunModel()
        {
            int i;
            DesktopEarlabDLL theDLL = new DesktopEarlabDLL();

            mStoppedCleanly      = false;
            btnRun.Enabled       = false;
            btnStop.Enabled      = true;
            udFrameCount.Enabled = false;
            progressBar.Visible  = true;

            ClearLog();

            mRunning         = false;
            sbTextPanel.Text = "Running";
            Log("Starting simulation");

            theDLL.SetLogCallback(mLogCallback);

            Log("Module directory: \"" + mModuleDirectory.Value + "\"");
            if (theDLL.SetModuleDirectory(mModuleDirectory.Value) == 0)
            {
                Log("Error setting module directory");
                return;
            }

            Log("Model configuration: \"" + mDiagramFile.Value + "\"");
            if (theDLL.LoadModelConfigFile(mDiagramFile.Value, 1000.0f) == 0)
            {
                Log("Error loading model config file");
                return;
            }

            Log("Module parameters: \"" + mParameterFile.Value + "\"");
            if (theDLL.LoadModuleParameters(mParameterFile.Value) == 0)
            {
                Log("Error loading module parameter file");
                return;
            }

            Log("Setting current directory to output directory (\"" + mOutputDirectory.Value + "\")");
            theDLL.SetOutputDirectory(mOutputDirectory.Value);

            Log("Starting modules");
            if (theDLL.StartModules() == 0)
            {
                Log("Error starting modules");
                return;
            }

            for (i = 0; i < mFrameCount.Value; i++)
            {
                mRunning = true;
                if (mStopModel)
                {
                    break;
                }
                progressBar.Value = i;
                sbTextPanel.Text  = "Processing frame " + (i + 1) + " of " + mFrameCount.Value;

                Log("Starting frame " + (i + 1) + " of " + mFrameCount.Value);
                try
                {
                    if (theDLL.AdvanceModules() == 0)
                    {
                        Log("Error processing frame " + i + " of " + mFrameCount.Value);
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log("Caught exception: " + e.ToString());
                }
                Application.DoEvents();
                Thread.Sleep(100);
            }

            sbTextPanel.Text = "Stopping";
            Log("Stopping modules");
            if (theDLL.StopModules() == 0)
            {
                Log("Error stopping modules");
                return;
            }

            Log("Unloading modules");
            if (theDLL.UnloadModel() == 0)
            {
                Log("Error unloading model");
                return;
            }

            btnRun.Enabled       = true;
            btnStop.Enabled      = false;
            btnAbort.Enabled     = false;
            udFrameCount.Enabled = true;
            progressBar.Visible  = false;
            UpdateStatusDisplay();
            udFrameCount.Focus();
            mStoppedCleanly = true;
            mRunning        = false;
        }