Cancel
Showing results for 
Search instead for 
Did you mean: 

Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Experimenter
Experimenter

Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix? I'm currently able to pass a variable to a custom dll and get a response, but not able to use multiple input parameters. Because there is very little information in the help on the C-interface I would be glad if someone could send me a working example in C#.

 

Kind regards,

 

Mart

5 REPLIES

Re: Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Legend
Legend

Hello!

 

I used the COM-interface to interface with Plant Simulation from C#, this was for running experiments so I'm not sure it's the thing that you're after.

Re: Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Experimenter
Experimenter
Hello verbalins,

I'm interested in two-way communication with C#. It would be kind if you could share an example.

Kind regards,

Mart

Re: Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Legend
Legend

Hello again,

 

This small code example will create a COMObject from the Plant Simulation Remote Interface, then it will start an instance of Plant Simulation, run the EventController in .Models.Frame, and then read the values from .Models.Drain.

 

You will have to adapt it to your version of Plant Simulation and create a model that has the EventController and Drain. I think you need the most recent version of C# to be able to use the dynamic keyword.

 

using System;
using System.Linq;

namespace InteropTest
{
public delegate void SimulationFinishedHandler();

private dynamic plantSimulation;
public dynamic PlantSimulation
{
get { return plantSimulation ; }
set { plantSimulation = value; }
}

class SimulationInstance
{
// Change this to match the version of your installation of Plant Simulation
String COMName = "Tecnomatix.PlantSimulation.RemoteControl.12.2"
PlantSimulation = Activator.CreateInstance(Type.GetTypeFromProgID(COMName));

// Set Plant Simulation to be visible.
PlantSimulation.setVisible(true);

// Subscribe to the SimulationFinished event.
PlantSimulation.SimulationFinished += new SimulationFinishedHandler(rc_SimulationFinished);

// Change the path here to a model file, C:\\Temp\\Model.spp or wherever.
PlantSimulation.LoadModel("ModelPathHere");

// Write some code to set values.
PlantSimulation.setValue(".Models.Frame.EventController.End", "8:00:00:00");

// Run the simulation model.
PlantSimulation.ExecuteSimTalk(".Models.Frame.EventController.reset");
    PlantSimulation.ExecuteSimTalk(".Models.Frame.EventController.startWithoutAnimation");
}

public void rc_SimulationFinished()
{
// This is what will be done when the simulation has finished.
String modelResult = PlantSimulation.getValue(".Models.Frame.Drain.statThroughPutPerHour");

// Exit the application.
PlantSimulation.closeModel();
PlantSimulation.quit();
}
}

 

Hopefully this will be without bugs, but I wrote it by hand and haven't tested it since I'm unable to do so at this time. But that is really all there is to it, create an instance, set values and then run and get the result back.

 

 

Re: Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Experimenter
Experimenter

Can you provide your project settings? Did you hook some DLLs or the COM object?

Is it possible that you mail/PM me the whole example project?

Thanks

Re: Does anybody have examples where C# is used in combination with the C-interface of Tecnomatix?

Experimenter
Experimenter

Thanks for this reply! It helped me a lot!

I had to make a few changes to your code to make it work though. Here's a working code.

 

      public bool endsim = false;
      public string COMName = "Tecnomatix.PlantSimulation.RemoteControl.13.1";
      public bool executePlantSimulation()
        {
            // Change COMName to match the version of your installation of Plant Simulation
            dynamic PlantSimulation = Activator.CreateInstance(Type.GetTypeFromProgID(COMName));

            // Set Plant Simulation to be visible.
            PlantSimulation.setVisible(true);

            // Subscribe to the SimulationFinished Event
            PlantSimulation.SimulationFinished += new SimulationFinishedHandler(() => rc_SimulationFinished(PlantSimulation));

            // try loading the model and if it works execute the SimTalk commands
            try
            {
                PlantSimulation.LoadModel("C:\\myplantsimfile.spp");
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                Console.WriteLine("Failed loading the model");
                return false;
            }

endsim = false; PlantSimulation.ExecuteSimTalk(".Models.MainFrame.EventController.reset"); PlantSimulation.ExecuteSimTalk(".Models.MainFrame.EventController.start"); // Wait until Simulation Ends while (!endsim) { System.Threading.Thread.Sleep(500); } // Exit the application. PlantSimulation.closeModel(); PlantSimulation.quit(); return true; } public delegate void SimulationFinishedHandler(); public void rc_SimulationFinished(dynamic PlantSimulation) { // This is what will be done when the simulation has finished. Console.WriteLine("Simulation finished!"); endsim = true; }