PC-DMIS Application Events via C#

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:
    Code:
    Using PCDLRN;
    
    public void pcdLaunch() 
    { 
    Type PCDRLN_Application = null; 
    
    object PCDObj = null; 
    
    PCDLRN.Application PCDApp = null; 
    
    try 
    { 
    PCDRLN_Application = Type.GetTypeFromProgID("PCDLRN.Application"); 
    
    PCDObj = Activator.CreateInstance(PCDRLN_Application); 
    } 
    catch (System.Exception em) 
    { 
    MessageBox.Show(em.Message); 
    } 
    
    PCDApp = new PCDLRN.Application(); 
    
    PCDApp.OperatorMode = true; 
    
    PCDApp.Visible = false; 
    } 
    TIA

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

    Code:
    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
    		}
    		}
    PcDmis 2015.1 SP10 CAD++
    Global 7-10-7 DC800S

    Comment


    • Kp61dude!
      Kp61dude! commented
      Editing a comment
      Good source for C#: https://www.pcdmisforum.com/forum/pc...p-2010-express

      Had the please of speaking with that man.... he's a LEGEND!
      Last edited by Kp61dude!; 02-25-2020, 11:57 AM.

    • Kp61dude!
      Kp61dude! commented
      Editing a comment
      I did not come across anything for IsMachineConnected, have you used that before?

    • CodeWarrior
      CodeWarrior commented
      Editing a comment
      Thank you I will look into this and report back. For the "IsMachineConnected" I meant "OnMachineConnected" sorry for the typo there

  • #3
    Kp61dude! 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

    Comment


    • Kp61dude!
      Kp61dude! commented
      Editing a comment
      Thanks CodeWarrior ! 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#).
      Last edited by Kp61dude!; 02-25-2020, 04:47 PM.

  • #4
    Below is the working solution to detect when PC-DMIS detects being connected to the CMM during the startup process. Many thanks to Kp61dude!
    Code:
    private void PCDMIS_Startup(object sender, StartupEventArgs e)
    {
    LoadScreen loadScreen = new LoadScreen(); loadScreen.Show();
    bool startCondition = true; Process[] pcdStartupCheck = Process.GetProcessesByName("PCDLRN"); if (pcdStartupCheck.Length > 0) {
    startCondition = false;
    } else {
    Type PCDRLN_Application = null; object PCDObj = null; PCDLRN.Application PCDApp = null; try {
    PCDRLN_Application = Type.GetTypeFromProgID("PCDLRN.Application"); PCDObj = Activator.CreateInstance(PCDRLN_Application);
    } catch (System.Exception em) {
    MessageBox.Show(em.Message);
    } PCDApp = new PCDLRN.Application(); PCDApp.OperatorMode = true; PCDApp.Visible = false; PCDApp.ApplicationEvents.OnMachineConnected += new IApplicationEvents_OnMachineConnectedEventHandler( onMachineConnect); void onMachineConnect(Machine machine) {
    //MessageBox.Show("machine connected"); startCondition = false;
    } if(startCondition) {
    WindowSearcher homeWindowSearch = new WindowSearcher(); homeWindowSearch.BeginWindowLook_Home();
    }
    } new MainWindow().Show(); loadScreen.Close();
    }

    Comment

    Related Topics

    Collapse

    Working...
    X