hexagon logo

Got Visual Studio and the Interop.PCDLRN.dll... Now what?

As I upgraded one CMM to Windows 7 64-bit, my small VBS helpers died in the process (still kickin' butt on XP though).
So, I have begun re-coding them in Visual Studio 2010 (I think). I have gotten so far in the coding where I need to connect to PC-DMIS and start interfacing with it. Now, I managed to find the DLL that is supposed to expose some interfaces and methods and I have successfully added it to my project.

Then what? How do I use the DLL to connect to PC-DMIS and expose the PartPrograms collection for instance?

Oh, I am using C# for this...

Any and all input, examples or suggestions are VERY welcome!

TIA!
Parents
  • vpt,

    I'll start with a question. How would you connect to a currently running program in a PC-DMIS script?
    dim app as object
    set app = CreateObject("PCDLRN.Application")
    


    the c# equivalent is very easy, there is actually a doc burried in the script editor help file called "Windows 7 automation notes"

    the following code is derived from that.

    // code to open pc-dmis, if pc-dmis is open, this c# application will connect to the currently running instance of PC-DMIS
    
    using PCDLRN;
    
    
    // class containing functions for interacting with pcdmis
    public class PCDMISInterop
    {
    	Appliction pcdApp; // don't use IAppliction, instances of interface types cannot be created, Interfaces can only be inherated
    
    	public Application PCDMISApplication
    	{
    		get{return this.Application;}
    	}
    	
    	public PCDMISInterop()
    	{
    		startPCDMIS();
    	}
    
    	bool StartPCDMIS()
    	{
    	     try
    	     {
    	          Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application");
    	          this.pcdApp = Activator.CreateInstance(pcdObjType);
    	          string status = "";
    	          /*
    	              this while loop starts with status = "", and will query PC-DMIS for the text in the status bar at the bottom of the screen.
    	              when it finally says "READY" or it contains "DONE INIT", the loop will exit
    	           */
    	          while (status != "READY" && !status.Contains("DONE INIT")) 
    	          {
    	               System.Threading.Thread.Sleep(1000); // give pc-dmis a second to work
    	               status = this.pcdApp.StatusBar.ToUpper();
    	          }
    	          return true; //pc-dmis started
    	     }
    	     catch
    	     {
    	          return false; // an error occured
    	     }
    	}
    	
    	// Gets the active part program
    }
    
    


    this is how you would use it in the main part of the program

    
    using PCDLRN;
    
    int main(void)
    {
    	PCDMISInterop PCDMIS = new PCDMISInterop();
    	
    	PartProgram pcdProgram = PCDMIS.PCDMISApplication.ActivePartProgram
    	
    	// the following 2 methods could be put into the PCDMISInterop Class to simplify the coding.
    	
    	// to open a part program
    	PCDMIS.PCDMISApplication.PartPrograms.Open("C:\test.prg","CMM1"); // "CMM1" for online, "OFFLINE" for offline
    	
    	// to create a new part program
    	PCDMIS.PCDMISApplication.PartPrograms.Add("C:\test2.prg",UNITTYPE.INCH/*UNITTYPE.MM for metric*/,"TESTPROBE");
    	
    	
    }
    
    

    I hope this helps.

    I do a lot of Interop with PC-DMIS in C# so if you need anything send me a PM.





    i some how ended up back on this page, in the method "StartPCDMIS()", I noticed that i should have used a different command to check when PC-DMIS is ready... so here's the Edit:

    bool StartPCDMIS()
    	{
    	     try
    	     {
    	          Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application");
    	          this.pcdApp = Activator.CreateInstance(pcdObjType);
    
                      int timeout = 100; // the number of seconds to wait...
                      pcdApp.WaitUntilReady(timeout);
    
    
    	          return true; //pc-dmis started
    	     }
    	     catch
    	     {
    	          return false; // an error occured
    	     }
    	}
    
    
Reply
  • vpt,

    I'll start with a question. How would you connect to a currently running program in a PC-DMIS script?
    dim app as object
    set app = CreateObject("PCDLRN.Application")
    


    the c# equivalent is very easy, there is actually a doc burried in the script editor help file called "Windows 7 automation notes"

    the following code is derived from that.

    // code to open pc-dmis, if pc-dmis is open, this c# application will connect to the currently running instance of PC-DMIS
    
    using PCDLRN;
    
    
    // class containing functions for interacting with pcdmis
    public class PCDMISInterop
    {
    	Appliction pcdApp; // don't use IAppliction, instances of interface types cannot be created, Interfaces can only be inherated
    
    	public Application PCDMISApplication
    	{
    		get{return this.Application;}
    	}
    	
    	public PCDMISInterop()
    	{
    		startPCDMIS();
    	}
    
    	bool StartPCDMIS()
    	{
    	     try
    	     {
    	          Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application");
    	          this.pcdApp = Activator.CreateInstance(pcdObjType);
    	          string status = "";
    	          /*
    	              this while loop starts with status = "", and will query PC-DMIS for the text in the status bar at the bottom of the screen.
    	              when it finally says "READY" or it contains "DONE INIT", the loop will exit
    	           */
    	          while (status != "READY" && !status.Contains("DONE INIT")) 
    	          {
    	               System.Threading.Thread.Sleep(1000); // give pc-dmis a second to work
    	               status = this.pcdApp.StatusBar.ToUpper();
    	          }
    	          return true; //pc-dmis started
    	     }
    	     catch
    	     {
    	          return false; // an error occured
    	     }
    	}
    	
    	// Gets the active part program
    }
    
    


    this is how you would use it in the main part of the program

    
    using PCDLRN;
    
    int main(void)
    {
    	PCDMISInterop PCDMIS = new PCDMISInterop();
    	
    	PartProgram pcdProgram = PCDMIS.PCDMISApplication.ActivePartProgram
    	
    	// the following 2 methods could be put into the PCDMISInterop Class to simplify the coding.
    	
    	// to open a part program
    	PCDMIS.PCDMISApplication.PartPrograms.Open("C:\test.prg","CMM1"); // "CMM1" for online, "OFFLINE" for offline
    	
    	// to create a new part program
    	PCDMIS.PCDMISApplication.PartPrograms.Add("C:\test2.prg",UNITTYPE.INCH/*UNITTYPE.MM for metric*/,"TESTPROBE");
    	
    	
    }
    
    

    I hope this helps.

    I do a lot of Interop with PC-DMIS in C# so if you need anything send me a PM.





    i some how ended up back on this page, in the method "StartPCDMIS()", I noticed that i should have used a different command to check when PC-DMIS is ready... so here's the Edit:

    bool StartPCDMIS()
    	{
    	     try
    	     {
    	          Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application");
    	          this.pcdApp = Activator.CreateInstance(pcdObjType);
    
                      int timeout = 100; // the number of seconds to wait...
                      pcdApp.WaitUntilReady(timeout);
    
    
    	          return true; //pc-dmis started
    	     }
    	     catch
    	     {
    	          return false; // an error occured
    	     }
    	}
    
    
Children
No Data