using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Integration.Operation; using Tango.Integration.Services; using Tango.MachineStudio.Common.StudioApplication; using Tango.PMR.Diagnostics; namespace Tango.MachineStudio.Common.Diagnostics { /// /// Represents the default diagnostics frame provider. /// /// public class DefaultDiagnosticsFrameProvider : ExtendedObject, IDiagnosticsFrameProvider { private IStudioApplicationManager _application; private bool _disable; /// /// Disables the frame delivery from the current connected machine and enables the manual push frame method. /// public bool Disable { get { return _disable; } set { _disable = value; } } /// /// Occurs when a new data frame is available. /// public event EventHandler FrameReceived; /// /// Initializes a new instance of the class. /// /// The application manager. public DefaultDiagnosticsFrameProvider(IStudioApplicationManager applicationManager) { _application = applicationManager; applicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; } /// /// Applications the manager connected machine changed. /// /// The sender. /// The machine. private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) { if (machine != null) { machine.DiagnosticsDataAvailable += DefaultDiagnosticsFrameProvider_DiagnosticsDataAvailable; } } /// /// Defaults the diagnostics frame provider diagnostics data available. /// /// The sender. /// The frame. private void DefaultDiagnosticsFrameProvider_DiagnosticsDataAvailable(object sender, StartDiagnosticsResponse frame) { if (!Disable) { OnFrameReceived(frame); } } /// /// Push frames manual. (Only when Disable = true) /// /// The frame. public void PushFrame(StartDiagnosticsResponse frame) { if (Disable) { OnFrameReceived(frame); } } /// /// Raises the event. /// /// The frame. protected virtual void OnFrameReceived(StartDiagnosticsResponse frame) { FrameReceived?.Invoke(this, frame); } } }