hexagon logo

PC-DMIS automation

hey all,

I've just recently started trying to Automate PC-DMIS. We need a front end here for our operators, along w/ a few other things that pc-dmis is just plain slow at.

so far i've tried 3 different languages (VC++, VB.NET and C#.NET) and I get the same error in all of them (80040154 COM not Registered)
I can get pc-dmis to open, and it is visible, but i can't do anything past that. Is there something i'm not doing?



here is my code for C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace _1st_attempt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           

            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            PCDLRN.Application App= new PCDLRN.ApplicationClass();//this works pc-dmis is open
            App.Visible = true;//pc-dmis is visible
            App.SetActive();//no error here
            PCDLRN.PartPrograms Parts = new PCDLRN.PartProgramsClass(); //COM ERROR 80040154


        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            textBox1.Text = openFileDialog1.FileName;
        }
    }
}


and for VB

#pragma once

namespace junk {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System:[emoticon:6D505171FAA4497C85C5CA27290C555D]ata;
	using namespace System:[emoticon:6D505171FAA4497C85C5CA27290C555D]rawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->SuspendLayout();
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System:[emoticon:6D505171FAA4497C85C5CA27290C555D]rawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System:[emoticon:6D505171FAA4497C85C5CA27290C555D]rawing::Size(284, 262);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
	PCDLRN::ApplicationClass App; //this works, PC-DMIS opens
	App.Visible = true; //PC-Dmis is visible
	App.SetActive(); //Still no Error
	PCDLRN::ApplicationObjectEventsClass AppEvents; //COM ERROR 80040154 Class not registered
			 }
	};
}



and again for VB


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim App As New PCDLRN.Application 'this works pc-dmis is open
        App.Visible = True 'pc-dmis is visible
        App.SetActive() 'no issue here
        Dim parts As New PCDLRN.PartPrograms 'COM Error 80040154

    End Sub
End Class




Hopefully someone will be able to help. Any of these languages will do.

Thanks in advance




btw i'm using PC-DMIS 2011 MR1 and Visual Studio 2010
Parents
  • sorry i haven't been on in a while, pretty busy here... finally getting around to paperwork.

    ok Here is some of the main pc-dmis class that i created called PCDHelper... this shows how to start/restart/close pc-dmis...
    that's really the hard part... from there you can do pretty much anything you need to.

    after declaring the event handlers you can create a function for them. the basic script help menu has a list of the required overloads to set up the actual functions for them.

    PCDonoff requires 1 overload of either "OPEN" or "CLOSE". OPEN will check to see if pc-dmis is already open, save and close all existing programs and re-start pc-dmis.
    "CLOSE" will close PC-DMIS.

    ConnectPCD is the actual function for opening pc-dmis. The overload for this function is an integer. it is used to pause the thread so pc-dmis can initialize the cmm(this happens automatically at startup) if you don't wait for pc-dmis to initialize the machine the rest of the program will crash...

    all of the code is in c#.

    and since the PCDHelper is a non-static class, in your main program you need to declare a PCDHelper object. ie

    
    PCDHelper PCDMIS = new PCDHelper();
    
    


    then to connect to pc-dmis you would use

    
    PCDMIS.PCDonoff("OPEN");
    
    


    then to Close pc-dmis would be
    
    PCDMIS.PCDonoff("CLOSE");
    
    


    then here is the actual code

    
    Using System.Windows.Forms;
    Using System.Threading;
    Using PCDLRN;
    
     public class PCDHelper
        {
            // create space for pc-dmis application
            private IApplication PCDApp;
            //create space for pc-dmis part programs
            private IPartPrograms PCDProgs;
            //create space for pc-dmis application events
            private ApplicationObjectEvents PCDEvents;
    
     public void PCDonoff(string verb)
            {
                ///
                ///function to open, close, or restart pc-dmis
                ///
                ///verb will tell whether to open, close or restart pc-dmis
                ///written by B. Capuana 11/3/12
                ///.netframework 4.0/pc-dmis 2011
                ///
                ///
               //check to see if pc-dmis is running
                System.Diagnostics.Process[] PCDProc = System.Diagnostics.Process.GetProcessesByName("PCDLRN");
                if (verb=="Open")
                {
                 if (PCDProc.Count() > 0)
                    {
                          System.Windows.Forms.MessageBox.Show("PC-DMIS Found. All work will be saved.\n" +
                          "PC-DMIS will Restart");
                          ConnectPCD(0);
                          killPCD();
                    }
                    connectPCD(20);
                if (verb == "Close")
                {
                    killPCD();
                }
            }
    
            private void killPCD()
            {
                //PCDApp.UserExit must be set to true in order to close pc-dmis via the api
                PCDApp.UserExit = true;
                if (PCDProgs.Count > 0)
                {
                    PCDProgs.CloseAll();
                }
                PCDApp.Quit();
            }
    
            private void connectPCD(int sleeptime)
            {
               PCDApp = new Application();
               //make the thread sleep to wait for pc-dmis to initialize machine
               Thread.Sleep(sleeptime * sleepmultiplier);
               PCDProgs = PCDApp.PartPrograms;
                //connect to pc-dmis events
                PCDEvents = PCDApp.ApplicationEvents;
                //create event handlers
                PCDEvents.OnOpenPartProgram+=new IApplicationEvents_OnOpenPartProgramEventHandler(PCDEvents_OnOpenPartProgram);
                PCDEvents.OnEndExecution+=new IApplicationEvents_OnEndExecutionEventHandler(PCDEvents_OnEndExecution);
    }
    
    
    }
    
    



    Hope this helps everyone!

    -Cappy
Reply
  • sorry i haven't been on in a while, pretty busy here... finally getting around to paperwork.

    ok Here is some of the main pc-dmis class that i created called PCDHelper... this shows how to start/restart/close pc-dmis...
    that's really the hard part... from there you can do pretty much anything you need to.

    after declaring the event handlers you can create a function for them. the basic script help menu has a list of the required overloads to set up the actual functions for them.

    PCDonoff requires 1 overload of either "OPEN" or "CLOSE". OPEN will check to see if pc-dmis is already open, save and close all existing programs and re-start pc-dmis.
    "CLOSE" will close PC-DMIS.

    ConnectPCD is the actual function for opening pc-dmis. The overload for this function is an integer. it is used to pause the thread so pc-dmis can initialize the cmm(this happens automatically at startup) if you don't wait for pc-dmis to initialize the machine the rest of the program will crash...

    all of the code is in c#.

    and since the PCDHelper is a non-static class, in your main program you need to declare a PCDHelper object. ie

    
    PCDHelper PCDMIS = new PCDHelper();
    
    


    then to connect to pc-dmis you would use

    
    PCDMIS.PCDonoff("OPEN");
    
    


    then to Close pc-dmis would be
    
    PCDMIS.PCDonoff("CLOSE");
    
    


    then here is the actual code

    
    Using System.Windows.Forms;
    Using System.Threading;
    Using PCDLRN;
    
     public class PCDHelper
        {
            // create space for pc-dmis application
            private IApplication PCDApp;
            //create space for pc-dmis part programs
            private IPartPrograms PCDProgs;
            //create space for pc-dmis application events
            private ApplicationObjectEvents PCDEvents;
    
     public void PCDonoff(string verb)
            {
                ///
                ///function to open, close, or restart pc-dmis
                ///
                ///verb will tell whether to open, close or restart pc-dmis
                ///written by B. Capuana 11/3/12
                ///.netframework 4.0/pc-dmis 2011
                ///
                ///
               //check to see if pc-dmis is running
                System.Diagnostics.Process[] PCDProc = System.Diagnostics.Process.GetProcessesByName("PCDLRN");
                if (verb=="Open")
                {
                 if (PCDProc.Count() > 0)
                    {
                          System.Windows.Forms.MessageBox.Show("PC-DMIS Found. All work will be saved.\n" +
                          "PC-DMIS will Restart");
                          ConnectPCD(0);
                          killPCD();
                    }
                    connectPCD(20);
                if (verb == "Close")
                {
                    killPCD();
                }
            }
    
            private void killPCD()
            {
                //PCDApp.UserExit must be set to true in order to close pc-dmis via the api
                PCDApp.UserExit = true;
                if (PCDProgs.Count > 0)
                {
                    PCDProgs.CloseAll();
                }
                PCDApp.Quit();
            }
    
            private void connectPCD(int sleeptime)
            {
               PCDApp = new Application();
               //make the thread sleep to wait for pc-dmis to initialize machine
               Thread.Sleep(sleeptime * sleepmultiplier);
               PCDProgs = PCDApp.PartPrograms;
                //connect to pc-dmis events
                PCDEvents = PCDApp.ApplicationEvents;
                //create event handlers
                PCDEvents.OnOpenPartProgram+=new IApplicationEvents_OnOpenPartProgramEventHandler(PCDEvents_OnOpenPartProgram);
                PCDEvents.OnEndExecution+=new IApplicationEvents_OnEndExecutionEventHandler(PCDEvents_OnEndExecution);
    }
    
    
    }
    
    



    Hope this helps everyone!

    -Cappy
Children
No Data