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!
  • 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);
    
     pcdApp.WaitUntilReady(60); 
             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.
  • Hey, thanks cappy! I'll try this out asap!

    I assume I need to use the Interop.PCDLRN.dll for this? I have added it as reference to my solution, is that enough (and to distribute it with the app)?

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


    PM!?!? - don't you all go keeping secrets from the rest of us now. Let's keep it all out here in the open. :-)

    Sent from my SPH-L710 using Tapatalk
  • Hey, thanks cappy! I'll try this out asap!

    I assume I need to use the Interop.PCDLRN.dll for this? I have added it as reference to my solution, is that enough (and to distribute it with the app)?


    Yup, Just add that reference and you should be all set!


    Once you get the hang of it I think that you'll really enjoy c#.

    Sent from my SCH-I545 using Tapatalk 4
  • 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
    	     }
    	}
    
    
  • Any reason for going the c# route instead of vb.net?

    I considered it when switching to .net but I really didn't (and still don't) see the benefit, or at least no where near enough to justify learning a new language!
  • Yeah, the benefit is that if you learn C# (or C/C++ for that matter) you can code for a multitude of platforms (FPGA's, Atmel's etc). I am not so sure that VB.NET exists for platforms other than the X86/X64 architecture.

    At least that's what I told myself the first time I started up Visual Studio... xD
    ...oh, and I'm a little of a masochist too.
  • VPT.se, your argument seems to be that you are using C# for this because it is good at doing other things. If you are only interested in doing this (writing applications that interact in some way with PCDMIS in a windows environment) what are the advantages to C#? My understanding is that it compiles to essentially the same thing as VB.net in the end so there shouldn't be a big performance advantage. Are there really useful libraries out there that this allows you to take advantage of or really efficient methods for handling vector arrays?

    Cappy, perhaps you can comment on this?