public UserForm() { try { mDesignMode = (LicenseManager.CurrentContext.UsageMode == LicenseUsageMode.Designtime); InitializeComponent(); if (!mDesignMode) { // Tell normal logging who the parent window is. AppLog.SetParentWindow = this; AppLog.TraceInfo = true; AppLog.TraceDebug = true; mChannels = new Channels(); // Enable the channels that will be controlled by this application. // For the generic IPC client this is all of them! // This just sets flags, it does not actually open the channels. mChannels.AccessApplication = true; mChannels.AccessXray = false; mChannels.AccessManipulator = true; mChannels.AccessImageProcessing = false; mChannels.AccessInspection = false; mChannels.AccessInspection2D = false; mChannels.AccessCT3DScan = false; mChannels.AccessCT2DScan = false; } } catch (Exception ex) { AppLog.LogException(ex); } }
/// <summary>Attach to channel and connect any event handlers</summary> /// <returns>Connection status</returns> private Channels.EConnectionState ChannelsAttach() { try { if (mChannels != null) { Channels.EConnectionState State = mChannels.Connect(); if (State == Channels.EConnectionState.Connected) // Open channels { // Attach event handlers (as required) if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.Manipulator != null) { mChannels.Manipulator.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_Manipulator.EventArgsHeartbeat>(EventHandlerHeartbeatMan); mChannels.Manipulator.mEventSubscriptionManipulatorMove.Event += new EventHandler <CommunicationsChannel_Manipulator.EventArgsManipulatorMoveEvent>(EventHandlerManipulatorMoveEvent); } } return(State); } } catch (Exception ex) { AppLog.LogException(ex); } return(Channels.EConnectionState.Error); }
/// <summary>Attach to channel and connect any event handlers</summary> /// <returns>Connection status</returns> private Channels.EConnectionState ChannelsAttach() { try { if (mChannels != null) { Channels.EConnectionState State = mChannels.Connect(); if (State == Channels.EConnectionState.Connected) // Open channels { // Attach event handlers (as required) if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.ImageProcessing != null) { mChannels.ImageProcessing.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_ImageProcessing.EventArgsHeartbeat>(EventHandlerHeartbeatIP); mChannels.ImageProcessing.mEventSubscriptionImageProcessing.Event += new EventHandler <CommunicationsChannel_ImageProcessing.EventArgsIPEvent>(EventHandlerIPEvent); } } return(State); } } catch (Exception ex) { AppLog.LogException(ex); } return(Channels.EConnectionState.Error); }
/// <summary>Detach channel and disconnect any event handlers</summary> /// <returns>true if OK</returns> private bool ChannelsDetach() { try { if (mChannels != null) { // Detach event handlers if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.Manipulator != null) { mChannels.Manipulator.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_Manipulator.EventArgsHeartbeat>(EventHandlerHeartbeatMan); mChannels.Manipulator.mEventSubscriptionManipulatorMove.Event -= new EventHandler <CommunicationsChannel_Manipulator.EventArgsManipulatorMoveEvent>(EventHandlerManipulatorMoveEvent); } Thread.Sleep(100); // A breather for events to finish! return(mChannels.Disconnect()); // Close channels } } catch (Exception ex) { AppLog.LogException(ex); } return(false); }
/// <summary>Detach channel and disconnect any event handlers</summary> /// <returns>true if OK</returns> private bool ChannelsDetach() { try { if (mChannels != null) { // Detach event handlers if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.ImageProcessing != null) { mChannels.ImageProcessing.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_ImageProcessing.EventArgsHeartbeat>(EventHandlerHeartbeatIP); mChannels.ImageProcessing.mEventSubscriptionImageProcessing.Event -= new EventHandler <CommunicationsChannel_ImageProcessing.EventArgsIPEvent>(EventHandlerIPEvent); } Thread.Sleep(100); // A breather for events to finish! return(mChannels.Disconnect()); // Close channels } } catch (Exception ex) { AppLog.LogException(ex); } return(false); }
/// <summary>Attach to channel and connect any event handlers</summary> /// <returns>Connection status</returns> private Channels.EConnectionState ChannelsAttach() { try { if (mChannels != null) { Channels.EConnectionState State = mChannels.Connect(); if (State == Channels.EConnectionState.Connected) // Open channels { // Attach event handlers (as required) if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.Xray != null) { mChannels.Xray.mEventSubscriptionHeartbeat.Event += new EventHandler <CommunicationsChannel_XRay.EventArgsHeartbeat>(EventHandlerHeartbeatXRay); mChannels.Xray.mEventSubscriptionEntireStatus.Event += new EventHandler <CommunicationsChannel_XRay.EventArgsXRayEntireStatus>(EventHandlerXRayEntireStatus); } } return(State); } } catch (Exception ex) { AppLog.LogException(ex); } return(Channels.EConnectionState.Error); }
/// <summary>Detach channel and disconnect any event handlers</summary> /// <returns>true if OK</returns> private bool ChannelsDetach() { try { if (mChannels != null) { // Detach event handlers if (mChannels.Application != null) { mChannels.Application.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_Application.EventArgsHeartbeat>(EventHandlerHeartbeatApp); } if (mChannels.Xray != null) { mChannels.Xray.mEventSubscriptionHeartbeat.Event -= new EventHandler <CommunicationsChannel_XRay.EventArgsHeartbeat>(EventHandlerHeartbeatXRay); mChannels.Xray.mEventSubscriptionEntireStatus.Event -= new EventHandler <CommunicationsChannel_XRay.EventArgsXRayEntireStatus>(EventHandlerXRayEntireStatus); } Thread.Sleep(100); // A breather for events to finish! return(mChannels.Disconnect()); // Close channels } } catch (Exception ex) { AppLog.LogException(ex); } return(false); }
private void UserForm_FormClosing(object sender, FormClosingEventArgs e) { try { // Detach channels ChannelsDetach(); Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : Disconnected from Inspect-X"); } catch (Exception ex) { AppLog.LogException(ex); } }
void EventHandlerIPEvent(object aSender, CommunicationsChannel_ImageProcessing.EventArgsIPEvent e) { try { if (mChannels == null || mChannels.ImageProcessing == null) { return; } if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate { EventHandlerIPEvent(aSender, e); }); // Make it non blocking if called form this UI thread } else { Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : e.IPEvent.EventType=" + e.IPEvent.EventType.ToString()); switch (e.IPEvent.EventType) { case IpcContract.ImageProcessing.IPEvent.EEventType.Live: // Your code goes here... break; case IpcContract.ImageProcessing.IPEvent.EEventType.Capture: // Your code goes here... break; case IpcContract.ImageProcessing.IPEvent.EEventType.Average: // Your code goes here... break; case IpcContract.ImageProcessing.IPEvent.EEventType.AverageComplete: // flag set to true when image averaging complete mImageAverageComplete = true; break; case IpcContract.ImageProcessing.IPEvent.EEventType.LoadImageComplete: // Your code goes here... break; case IpcContract.ImageProcessing.IPEvent.EEventType.SaveImageComplete: // flag set to true when image saved mImageSaveComplete = true; break; default: // Your code goes here... break; } } } catch (Exception ex) { AppLog.LogException(ex); } }
private void UserForm_Load(object sender, EventArgs e) { try { // Attach channels mApplicationState = ChannelsAttach(); if (mApplicationState == Channels.EConnectionState.Connected) { Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : Connected to Inspect-X"); } else { Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : Problem in connecting to Inspect-X"); } } catch (Exception ex) { AppLog.LogException(ex); } }
void EventHandlerHeartbeatMan(object aSender, CommunicationsChannel_Manipulator.EventArgsHeartbeat e) { try { if (mChannels == null || mChannels.Manipulator == null) { return; } if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate { EventHandlerHeartbeatMan(aSender, e); }); } else { //your code goes here.... } } catch (ObjectDisposedException) { } // ignore catch (Exception ex) { AppLog.LogException(ex); } }
void EventHandlerManipulatorMoveEvent(object aSender, CommunicationsChannel_Manipulator.EventArgsManipulatorMoveEvent e) { try { if (mChannels == null || mChannels.Manipulator == null) { return; } if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate { EventHandlerManipulatorMoveEvent(aSender, e); }); // Make it non blocking if called form this UI thread } else { Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : e.MoveEvent=" + e.MoveEvent.ToString()); switch (e.MoveEvent) { case IpcContract.Manipulator.EMoveEvent.HomingStarted: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.HomingCompleted: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.ManipulatorStartedMoving: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.ManipulatorStoppedMoving: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.FilamentChangePositionGoStarted: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.GoCompleted: // Set mManipulatorGoComplete flag to be true mManipulatorGoComplete = true; break; case IpcContract.Manipulator.EMoveEvent.GoStarted: // Set mManipulatorGoSignalSent flag to be true mManipulatorGoSignalSent = true; break; case IpcContract.Manipulator.EMoveEvent.LoadPositionGoCompleted: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.LoadPositionGoStarted: // Your code goes here... break; case IpcContract.Manipulator.EMoveEvent.Error: // Your code goes here... break; default: break; } } } catch (Exception ex) { AppLog.LogException(ex); } }
void EventHandlerXRayEntireStatus(object aSender, CommunicationsChannel_XRay.EventArgsXRayEntireStatus e) { try { if (mChannels == null || mChannels.Xray == null) { return; } if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate { EventHandlerXRayEntireStatus(aSender, e); }); // Make it non blocking if called form this UI thread } else { if (e.EntireStatus != null) { Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : e.EntireStatus.XRaysStatus.GenerationStatus.State=" + e.EntireStatus.XRaysStatus.GenerationStatus.State.ToString()); switch (e.EntireStatus.XRaysStatus.GenerationStatus.State) { case IpcContract.XRay.GenerationStatus.EXRayGenerationState.Success: // Set mXraysStable Flag to true indicating stability has been reached mXraysStable = true; break; case IpcContract.XRay.GenerationStatus.EXRayGenerationState.WaitingForStability: // Increment stability counter; mXraysStabilityCounter++; // If stability counter is greater than 1 then must manually check update X-ray Entire status if (mXraysStabilityCounter > 1) { // Manual loop to update X-ray Entire Status until "Success" Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : Manually checking for stability"); do { // First sleep for a small amount of time to allow status updates Thread.Sleep(100); // Then get a updated X-ray Entire Status mXrayEntireStatus = mChannels.Xray.GetXRayEntireStatus(); // Find generation part of Entire Status mXrayGenerationStatus = mXrayEntireStatus.XRaysStatus.GenerationStatus.State; Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : mXrayGenerationStatus=" + mXrayGenerationStatus.ToString()); }while (mXrayGenerationStatus != IpcContract.XRay.GenerationStatus.EXRayGenerationState.Success); Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : Manually found stable X-rays- Proceed"); // Once "Success" obtained then set mXraysStable flag to true mXraysStable = true; // Reset stability counter mXraysStabilityCounter = 0; } break; case IpcContract.XRay.GenerationStatus.EXRayGenerationState.NoXRayController: // Your code goes here... break; case IpcContract.XRay.GenerationStatus.EXRayGenerationState.StabilityTimeout: // Your code goes here... break; case IpcContract.XRay.GenerationStatus.EXRayGenerationState.StabilityXRays: // Your code goes here... break; case IpcContract.XRay.GenerationStatus.EXRayGenerationState.SwitchedOff: // Set reset flag when X-rays are turned off mXraysStable = false; break; } Debug.Print(DateTime.Now.ToString("dd/MM/yyyy H:mm:ss.fff") + " : mXraysStable=" + mXraysStable.ToString()); } } } catch (Exception ex) { AppLog.LogException(ex); } }