hexagon logo

PCDMIS Automation with Visual CSharp 2010 Express

Introduction to PCDMIS Automation

It will take a number of postings in this thread to present all the topics needed to understand and implement my particular method of PCDMIS automation. If you're interested in this thread or want to comment on some part of it, would you consider doing so by email to me. I will reserve the questions and comments and include them in the relevant posting that should answer the question(s). I think this way the thread stays organized and on topic.

Everything I post will work with PCDMIS any version 3.7 and up and MS Visual C Sharp 2010 Express. Sorry no VB Express examples at this time, maybe later after the entire method is presented, I'll go back and add VB. But if you haven't used C Sharp or the MS Visual C Sharp Express IDE, don't worry, the C Sharp code will be very easy to follow and there will be a number of postings that will explain the IDE and how to use it.

For more in-depth exposure to programming in C Sharp I recommend any of the Visual C Sharp 2010 books available. I'm going to try and stay on topic and focus on presenting the method of PCDMIS automation. If I see that a few of you are stuck on a particular C Sharp issue, I'll present a short side bar, so to speak, to maybe help you out.

I make no claims of expertise in the 'correct method' to measure features using CMM. In fact I frequent this forum to learn of such things from others.

To follow this series of postings you will need:
1. Any version of PCDMIS 3.7 and higher.
2. Online or offline.
3. MS Visual C Sharp Express 2010, installed using default settings.

Express 2010 can be downloaded free at:

https://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express

In addition to the above items, I also recommend using the following PCDMIS file path settings, once you see how things work and interact with each other, then you can modify the code so that your preferred file path settings will still work.

PCDMIS Search Path Settings
Set 'Default Part Program Directory' to anything other than the default installation directory of PCDMIS. I use c:\PcdmisApps\.

Set 'Probe Directory' to a folder located in part program directory. I use c:\PcdmisApps\Probes.

Set 'Recall Directory' to another folder in the part program directory. I use c:\PcdmisApps\Alignments.

At some point we will be creating an application folder, also located in the part program directory. Name this folder something that leaves no doubt what part the application is to measure. I use the name of the part being measured. When ever I use *App-folder* I mean for you to substitute the name that you gave the application folder. I will reference this a lot.

Inside the *App-folder* are several standard folders which I use inside every application folder. They are:
Doc - Contains application user documentation and/or other notes.
Data-sets - Contains data used by application.
Subroutines - PCDMIS subprograms.
DotNet - The DotNet executable and libraries.
Reports - Reports generated by PCDMIS or DotNet application.

All PCDMIS programs (.PRG files) used by the application are located in the *App-folder* for which is was written.

The method for automating PCDMIS being presented here was developed to answer the following requirements.

1. Parametric PCDMIS programs for the measurement of a family of parts using one PCDMIS program.
2. Hide the PCDMIS IDE from the CMM operator.
3. Internationalization (multi-language user interface)
4. Bidirectional interaction with databases for part data and measurements.
5. Bidirectional interaction with Quality documents in MS Excel or Open Office.
6. To resolve performance and maintenance issues with PCDMIS code.

The first objective is to learn how to create a C Sharp application uses the PcdmisSession library to interact with the PCDLRN in various ways.

The second objective is to demonstrate how to create a PCDMIS parametric program

The third objective is explain the contents PcdmisSession library, so that you can make changes to suit your requirements. This library is where the actual connection to PCDMIS happens. I built this library so that I wouldn't have to write the same code for each application.

The fourth objective is to demonstrate how to read/write measurement data from the PCDLRN to a spreadsheet.

I am interested in hearing from you if any of the code shown in this thread is not working for you, please email me if something doesn't seem to work as demonstrated.

In the next post I will start by providing the PcdmisSession library (dll) file which contains everything needed to connect to and bidirectionally interact with PCDMIS or more accurately the PCDLRN process. As I mentioned before, details or source code for the library will be presented last.

I'm going to assume that most have not used the C Sharp Express IDE, so I will present some pointers to help you get started and include an avi movie file of my screen as I demonstrate concepts.
  • So, apparently there is some interest in this topic since I started it, which was some time ago. No need to to try to reverse engineer the library I'll include the source here.

    Regarding the source files:
    There are two zip files, both are C# projects created on the free version of Visual C# 2015.
    One zip will create a folder named DmisLib, this a collection of C# library projects - Calc, Dmis, DmisSession, Geometry and Utilites
    The other zip will create a folder named PcdmisMenu. This is a sample C# app which uses the DmisLib to connect with Pcdmis.

    The DmisLib is a stripped down version of the library of reusable code which I created for use in my current employment. I am not able to share that code because is represents work product paid for by current employer. The code I present here is standard stuff any of you guys/gals could have figured out directly from the PCDMIS automation manuals.

    The source provide demonstrates:
    1. Code to allow the C# application choose which version of Pcdmis to execute. Andersi above is correct, it is necessary to run PCDMIS once in Admin mode to write important registry info. The sample C# app provided was able to launch and connect with versions "2011 MR1", "2013 MR1" and "2015" on my Wind7 box. 2011 is 32bit the others are 64bit.
    2. How the C# application can capture measurement results, on the fly while program inspection is in progress. Interesting side note: If your Pcdmis measurement program has nested If/Endif statements this won't work. Took me a year to figure that one out. Weird.
    3. How to launch Pcdmis (PCDLRN) into the background in asynchronous mode. This is necessary so that your C# application can remain active while measurement program is executing.
    4. Conversion of the Pcdmis Dimension command to a dimensionData object, this requires legency dimensions to be turned on. I'm working on a new version which will handle both new dimension and legency.

    What's included but not demonstrated:
    1. Calc library - If you create an instance of exceldocument object by passing the fullpath of an excel document, you can switch between sheets and read/write to any cell. You can also save as a pdf file or xps file. This lib was compiled using a reference to the "Microsoft Excel 15.0 Object", if you don't have this you will need to delete the reference and add whichever version is on your box.
    2. The PcdmisHelper code includes code to open a subroutine Pcdmis file and write Pcdmis commands into the file. which look like the following lines.

    ASSIGN/H1TVMAT=55.06200
    ASSIGN/PCMAT=16.72800
    ASSIGN/CLR_HEIGHT_ADJ=0
    ASSIGN/CAST_THK_ADJ=0
    ASSIGN/ALIGN_AXIS="Y"
    ASSIGN/CAST_LOCX_ADJ=3
    ASSIGN/CAST_LOCY_ADJ=3

    ASSIGN/PLN_MAT_27_B_CNT=4
    ASSIGN/ARR_PLN_MAT_27_B[1]=ARRAY(-150.848,-79.218,36.140,0.99991,0.00000,-0.01309,1)
    ASSIGN/ARR_PLN_MAT_27_B[2]=ARRAY(-151.237,-77.228,6.491,0.99991,0.00000,-0.01309,2)
    ASSIGN/ARR_PLN_MAT_27_B[3]=ARRAY(-151.242,76.927,6.082,0.99991,0.00000,-0.01309,3)
    ASSIGN/ARR_PLN_MAT_27_B[4]=ARRAY(-150.882,76.455,33.623,0.99991,0.00000,-0.01309,4)

    This is my way of creating parametric programs, which is by creating a subroutine file with all variables defined for the current part to be measured, saving and closing the file, then opening the main measurement program which calls the variable subroutine first thing. All variables are set to be global variables. All of this is performed by the C# application using the library.

    If there is any further interest, I'm somewhat available to answer questions. This topic is really something for which a three day class would be ideal to cover the basics, maybe another two days to include some additional advance topics. I've taught classes on similar topics in the past, I regret that this forum thread is not a easy way to cover a complex topic. Maybe this could be a topic at a user group meeting.

    I had to remove the binaries from the attachments to get them small enough. Build DmisLib first, you may have to build a couple of time cause some of the libs are dependent on other libs. Build the PcdmisMenu app second.

  • A few notes regarding the PcdmisMenu application:
    This application is launched first, it will launch Pcdmis do not start Pcdmis first. Also, give it time to start Pcdmis especially the first time.
    Pcdmis once started will disapper intto the background, notice it does not appear in the program tab at the bottom of the screen. On the menu application there is a button in the lower right corner that will bring Pcdmis window in and out of view. I had to add this button because some Pcdmis programs have forms which can only be seen in the Pcdmis window. Most Pcdmis program have no interaction with the operator except through the DotNet application so usually it is not necessary for the operator to have visibility of the Pcdmis window.

    Configure menu is to add, edit or delete program selections from the main menu. Selecting any of the three will bring up another window. In this window the top textbox is to enter a man readable line for the program to execute, this is what appears on the main application window. The second line is the name of the folder under the default Pcdmis program folder set in the Pcdmis path settings.

    Third line is the Pcdmis program located in the fold selected previously.

    Fourth line is a pulldown to select a probe tip, doesn't do anything at this point except write the name of the tip into a file called TIP in the folder for subroutines set in the Pcdmis path settings.

    In our application we have data files formatted as DMIS files containing information about the part to measure, we use the copy file function to copy this files from the central repository to the local CMM.

    This application uses the pcdmis program folder layout as described in my first entry at the beginning of this thread.
  • Well, I'd sure like to learn more using C# and PC-DMIS... Anything anyone can share is helpful, regardless of complexity.
  • Well, I'd sure like to learn more using C# and PC-DMIS... Anything anyone can share is helpful, regardless of complexity.


    Just out of curiosity may I ask if you have an application in mind that would use PC-DMIS and C#?
  • Several ideas, mostly for automation. My biggest issue is to be able to connect to PC-DMIS regardless of state and version (if it is closed, open it - if it is open, connect to it). I have small helper apps that I had used VBS for earlier which would be great to port to C#.

    I have tried to connect to PC-DMIS using GetMarshalObject/GetObjectMarshal but since PC-DMIS wasn't displayed in the ROT, this didn't work. The source you posted will help me much though, but please keep them coming!
  • "...connect to PC-DMIS regardless of state..." I did not consider this in my code, have not tested the behavior of my code if PC-DMIS is already open. I suspect it will just open another copy of PCDMIS. At my site we always use a C# to open PC-DMIS. Some of the issues I have found with connecting with open PC-DMIS is that it may already be connected with another DotNet app. It gets confused if another tries to connect, the resulting behavior is unpredictable. I also found some unpredictable CMM behavior when any two versions of PC-DMIS are open, which makes sense if they're both trying to control the machine.

    I've opted to eliminate the confusion by making sure there are no copies of PC-DMIS already running before attempting to start and connect to version requested by the DotNet app.

    You can see in the connect() method in the PcdmisHelper code where existing processes with the name PCDLRN are identified and killed.

    I'm currently working on a project to integrate a robot and CMM. The C# program will be used to manage the operations of both machines and keep them in sync. The robotic software has similar automation software as PC-DMIS. So if you know how to control PC-DMIS and CMM via PC-DMIS Automation it's not hard at all to do the same with the robot and robot software.

  • I have a little time, I thought I would provide a little more info about the code.

    The PcdmisHelper class is the interface between C# applications and PC-DMIS. The goal and purpose of this class is:
    1. Provide code reuse for a complicated task
    2. Separate the C# application code from PC-DMIS, It is not necessary for the C# application to have a reference to the PCDLRN.

    In the application PcdmisMenu there is a source code file PcdmisMain. It is a partial class of the Mainform class. For those not familiar with partial classes, it's just a way of separating the code of a single class into multiple source code files.

    The partial class PcdmisMain contains all the code necessary to interface with PcdmisHelp class. If you create a new C# app that you want to use with PC-DMIS just include the code from PcdmisMain to your new app code and it will have everything it needs to interface with PC-DMIS.

    For the most part the code in PcdmisMain is independent of the code in your app main form code. But there are a few of lines that are dependent on your app that you will need to change.

    Near the beginning of the code there are two lines: "namespace DmisMenu" and "using Settings = DmisMenu.Properties.Settings;" The "DmisMenu" needs to match your app namespace.

    The line "CMMsession = new PcdmisHelper(Settings.Default.PcdmisVersion, UNIT_OPTION.MM)" uses a Setting value called "PcdmisVersion" that needs to be defined in your app Settings. See the PcdmisMenu Settings. The string assigned to "PcdmisVersion" is one of the strings listed in the comment in PcdmisHelper code on Pcdmis version selection. If you're not using settings replace the setting with a string for your version of PC-DMIS like this "CMMsession = new PcdmisHelper("2013", UNIT_OPTION.MM)" . if you're using inches replace UNIT_OPTION.MM with UNIT_OPTION.IN.

    The line "public partial class Mainform" the work Mainform needs to match the name of your app main class. The default name for this class when you create a new windows app is Form1, I always rename it to MainForm. ( if this line in your copy of PcdmisMain source code includes " : Form " you can remove that portion of the line. PcdmisMain does not use the Form interface.)

    For your app to connect with Pcdmis you add PcdmisMain code as describe above and in your main form constructor method add the call to method InitializePcdmis(). See the method public Mainform() in the PcdmisMenu app.
  • I don't know how you manage to start two PC-DMIS at the same time, unless you're using virtual machines (but then you wouldn't be able to see what's running in the other 'computer'?)? I thought PC-DMIS itself acted against double start? At least it does when clicking the shortcut.
  • Anderl, thank you for your comment. I thought so too, but I've been called out to the shop more than one to fix an erratic behaving CMM only to find two PCDLRN running in the task manager process window. I haven't really dug into the issue other than to assume the first session was started by C# app and the second session was started by the operator double clicking on the PC-DMIS icon.
  • So, apparently there is some interest in this topic since I started it, which was some time ago.


    Of course, this is amazing stuff. Please, keep it coming.


    Edit:
    I get a "Missing Probe Folder ParameterNotFound" what did I do wrong?