hexagon logo

PC-DMIS Application Events via C#

So through the process of improving my app for automating pc-dmis I have undertaken the task of converting parts of my app from vbscripts to all C# code. When "interacting" with pc-dmis in previous versions, I would call the vbscripts to automate pc-dmis and wait for the script to finish before doing anything else.

Through converting my code in vbscripts to c# I have come across the problem that I don't know how to handle application events in c#. I am having trouble matching the syntax differences between vbscripts and c#.

The application event in particular i'm looking to handle is the "IsMachineConnected" event during startup of pc-dmis.

So if anyone has an example or input they'd like to share, I would greatly appreciate it.

Here is my working code to launch pc-dmis:
Using PCDLRN;

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]public[/FONT][/COLOR] [COLOR=#0000ff][FONT=Consolas]void[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]pcdLaunch[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]()[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]Type [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]object[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDObj[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDApp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]try[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Type.GetTypeFromProgID[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]"[/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDObj[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Activator.CreateInstance[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]catch[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] ([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]System.Exception[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]em[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]MessageBox.Show[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]em.Message[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]new[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]();[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp.OperatorMode[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]true[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp.Visible[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]false[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]


TIA
  • Reference the Interop.Pcdlrn library and type similar to the following... (minus the class stuff).

    using PCDLRN;
    
    namespace SmartPattern_PcdApp
    {
    	public partial class Form1 : Form
    	{
    		// Globals
    		ArrayList CmdItems = new ArrayList();
    		PcDmisCls oPcdApp = new PcDmisCls();
    
    		public Form1()
    		{
    			InitializeComponent();
    		}
    
    
    		private void Form1_Load(object sender, EventArgs e)
    		{			
    			PartProgram part = oPcdApp.Part();
    			EditWindow ew = oPcdApp.editWindow;			
    
    			oPcdApp.application.ApplicationEvents.OnSavePartProgram += new IApplicationEvents_OnSavePartProgramEventHandler(onSavePart);
    			part.OnAddObject += new IPartProgramEvents_OnAddObjectEventHandler(addedObject);			
    
    			part = null;
    			ew = null;			
    		}
    
    		// Triggers when part is saved...
    		void onSavePart(PartProgram prg)
    		{
    			// what do I put here?
    			MessageBox.Show("Part Saved!");
    		}
    
    		// Triggers when an object is added
    		void addedObject(Command cmd)
    		{
    			MessageBox.Show("Item: " + cmd.ID + " was added!");
    
    			// Create cmds in C
    		}
    		}
    
  • I did not come across anything for IsMachineConnected, have you used that before?
  • Thank you I will look into this and report back. For the "IsMachineConnected" I meant "OnMachineConnected" sorry for the typo there
  • I've gotten your part program save example to work perfectly, I just have to test the "OnMachineConnected" event when I have a few moments with the CMM. I'll update this when I have a complete solution.

    That was a very interesting thread to read through, impressive work by him. Don't sell yourself short.. you're a legend in my book Sunglasses
  • Thanks ! Glad to help. Keep at it with C# I feel that it is much easier to get stuff done than VB.NET (after the learning curve going from VB to C#).
  • Below is the working solution to detect when PC-DMIS detects being connected to the CMM during the startup process. Many thanks to
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]private [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]void[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] PCDMIS_Startup([/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]object[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] sender, StartupEventArgs e)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR] [INDENT][COLOR=#000000][FONT=Consolas][SIZE=10px]LoadScreen loadScreen = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]new[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] LoadScreen();[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]loadScreen.Show();[/SIZE][/FONT][/COLOR][/INDENT]
        [INDENT][COLOR=#0000ff][FONT=Consolas][SIZE=10px]bool[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] startCondition = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]true[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Consolas][SIZE=10px]Process[] pcdStartupCheck = Process.GetProcessesByName([/SIZE][/FONT][/COLOR][COLOR=#a31515][FONT=Consolas][SIZE=10px]"PCDLRN"[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px]);[/SIZE][/FONT][/COLOR]
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]if[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] (pcdStartupCheck.Length > 0)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]startCondition = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]false[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT][COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]else[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]Type PCDRLN_Application = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]null[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]object[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] PCDObj = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]null[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDLRN.Application PCDApp = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]null[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]try[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=3][COLOR=#000000][FONT=Consolas][SIZE=10px]PCDRLN_Application = Type.GetTypeFromProgID([/SIZE][/FONT][/COLOR][COLOR=#a31515][FONT=Consolas][SIZE=10px]"PCDLRN.Application"[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px]);[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDObj = Activator.CreateInstance(PCDRLN_Application);[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]catch[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] (System.Exception em)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=3][COLOR=#000000][FONT=Consolas][SIZE=10px]MessageBox.Show(em.Message);[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDApp = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]new[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] PCDLRN.Application();[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDApp.OperatorMode = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]true[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDApp.Visible = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]false[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Consolas][SIZE=10px]PCDApp.ApplicationEvents.OnMachineConnected += [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]new[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] IApplicationEvents_OnMachineConnectedEventHandler( onMachineConnect);[/SIZE][/FONT][/COLOR]
    
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]void[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] onMachineConnect(Machine machine)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=3][COLOR=#008000][FONT=Consolas][SIZE=10px]//MessageBox.Show("machine connected");[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]startCondition = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]false[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px];[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]
    
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]if[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px](startCondition)[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]{[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=3][COLOR=#000000][FONT=Consolas][SIZE=10px]WindowSearcher homeWindowSearch = [/SIZE][/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas][SIZE=10px]new[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] WindowSearcher();[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]homeWindowSearch.BeginWindowLook_Home();[/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT=2][COLOR=#000000][FONT=Consolas][SIZE=10px]} [/SIZE][/FONT][/COLOR][/INDENT]
      [INDENT][COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]
    [COLOR=#0000ff][FONT=Consolas][SIZE=10px]new[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Consolas][SIZE=10px] MainWindow().Show();[/SIZE][/FONT][/COLOR]
    [COLOR=#000000][FONT=Consolas][SIZE=10px]loadScreen.Close();[/SIZE][/FONT][/COLOR][/INDENT]
     [COLOR=#000000][FONT=Consolas][SIZE=10px]}[/SIZE][/FONT][/COLOR]