diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-28 14:29:19 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-28 14:29:19 +0200 |
| commit | 3e725887814383f6f18b1e6e951e1322104ebd1c (patch) | |
| tree | 86f4c697307c811556ec273cd01b5cc635835c2c /Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs | |
| parent | c726e1f7697d9f0fe8cff387dc64dd00c4980b82 (diff) | |
| download | Tango-3e725887814383f6f18b1e6e951e1322104ebd1c.tar.gz Tango-3e725887814383f6f18b1e6e951e1322104ebd1c.zip | |
Lots of work !!!
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs | 148 |
1 files changed, 147 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs index 272bde432..6432e279c 100644 --- a/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs @@ -15,6 +15,10 @@ using Tango.PMR.Printing; using Tango.Integration.Observables; using System.Reactive.Subjects; using Tango.Integration.Printing; +using Tango.PMR.Debugging; +using Tango.Logging; +using Tango.Settings; +using System.IO; namespace Tango.Integration.Operators { @@ -26,6 +30,14 @@ namespace Tango.Integration.Operators public class MachineOperator : BasicTransporter, IMachineOperator { private bool _diagnosticsSent; + private bool _debugSent; + private LogManager _embeddedLogger; + + public MachineOperator() : base() + { + EnableEmbeddedDebugging = true; + LogEmbeddedDebuggingToFile = true; + } #region Events @@ -33,6 +45,7 @@ namespace Tango.Integration.Operators /// Occurs when there is new diagnostics data available. /// </summary> public event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable; + public event EventHandler<DebugLogResponse> DebugLogAvailable; #endregion @@ -56,6 +69,52 @@ namespace Tango.Integration.Operators } } + private bool _enableEmbeddedDebugging; + /// <summary> + /// Gets or sets a value indicating whether to allow incoming debugging messages. + /// </summary> + /// <exception cref="System.NotImplementedException"> + /// </exception> + public bool EnableEmbeddedDebugging + { + get + { + return _enableEmbeddedDebugging; + } + set + { + if (_enableEmbeddedDebugging != value) + { + _enableEmbeddedDebugging = value; + RaisePropertyChangedAuto(); + OnEnableEmbeddedDebuggingChanged(value); + } + } + } + + private bool _logEmbeddedDebuggingToFile; + /// <summary> + /// Gets or sets a value indicating whether to automatically save incoming log data from the embedded device. + /// </summary> + public bool LogEmbeddedDebuggingToFile + { + get { return _logEmbeddedDebuggingToFile; } + set + { + _logEmbeddedDebuggingToFile = value; RaisePropertyChangedAuto(); + + if (_logEmbeddedDebuggingToFile && _embeddedLogger == null) + { + _embeddedLogger = new LogManager(); + + String folder = SettingsManager.DefaultFolder + "\\embedded logs"; + Directory.CreateDirectory(folder); + FileLogger fileLogger = new FileLogger(Path.Combine(folder, String.Format("{1}-{0:yyyy-MM-dd_hh-mm-ss}.log", DateTime.Now, "embedded"))) { Enabled = true }; + _embeddedLogger.RegisterLogger(fileLogger); + } + } + } + #endregion #region Virtual Methods @@ -97,6 +156,39 @@ namespace Tango.Integration.Operators } /// <summary> + /// Called when the enable embedded debugging has been changed + /// </summary> + /// <param name="value">if set to <c>true</c> [value].</param> + protected void OnEnableEmbeddedDebuggingChanged(bool value) + { + if (value && State == TransportComponentState.Connected && !_debugSent) + { + SendContinuousRequest<DebugLogRequest, DebugLogResponse>(new DebugLogRequest()).ObserveOn(new NewThreadScheduler()) + .Subscribe + ( + (response) => + { + _debugSent = true; + OnDebugLogAvailable(response); + }, + (ex) => + { + _debugSent = false; + //Do I need separate event for each one ?? + }, + () => + { + _debugSent = false; + //What to do now ?? + }); + } + else + { + _debugSent = false; + } + } + + /// <summary> /// Invokes the <see cref="DiagnosticsDataAvailable"/> event. /// </summary> /// <param name="data">The sensors data.</param> @@ -105,6 +197,20 @@ namespace Tango.Integration.Operators DiagnosticsDataAvailable?.Invoke(this, data); } + /// <summary> + /// Invokes the <see cref="DebugLogAvailable"/> event. + /// </summary> + /// <param name="data">The sensors data.</param> + protected virtual void OnDebugLogAvailable(DebugLogResponse data) + { + if (LogEmbeddedDebuggingToFile && _embeddedLogger != null) + { + _embeddedLogger.Log(new EmbeddedLogItem(data)); + } + + DebugLogAvailable?.Invoke(this, data); + } + #endregion #region Protected Methods @@ -120,9 +226,11 @@ namespace Tango.Integration.Operators if (state != TransportComponentState.Connected) { _diagnosticsSent = false; + _debugSent = false; } OnEnableDiagnosticsChanged(EnableDiagnostics); + OnEnableEmbeddedDebuggingChanged(EnableEmbeddedDebugging); } #endregion @@ -146,6 +254,7 @@ namespace Tango.Integration.Operators ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; ProcessParameters process = new ProcessParameters(); + process.Name = processParameters.Name; process.DyeingSpeed = processParameters.DyeingSpeed; process.MinInkUptake = processParameters.MinInkUptake; process.MixerTemp = processParameters.MixerTemp; @@ -164,6 +273,43 @@ namespace Tango.Integration.Operators ticket.ProcessParameters = process; + foreach (var segment in job.Segments) + { + JobSegment jobSegment = new JobSegment(); + jobSegment.Length = segment.Length; + jobSegment.Name = segment.Name; + + foreach (var stop in segment.BrushStops) + { + JobBrushStop jobStop = new JobBrushStop(); + jobStop.Index = stop.Index; + jobStop.OffsetPercent = stop.OffsetPercent; + jobStop.OffsetMeters = stop.OffsetMeters; + + foreach (var liquidVolume in stop.LiquidVolumes) + { + JobDispenser dispenser = new JobDispenser(); + dispenser.Index = liquidVolume.IdsPack.PackIndex; + dispenser.Volume = liquidVolume.Volume; + dispenser.DispenserLiquidType = (DispenserLiquidType)liquidVolume.IdsPack.LiquidType.Code; + dispenser.DispenserStepDivision = (DispenserStepDivision)liquidVolume.DispenserStepDivision; + + dispenser.NanoliterPerPulse = liquidVolume.IdsPack.DispenserType.NlPerPulse; + + dispenser.LiquidMaxNanoliterPerCentimeter = liquidVolume.LiquidMaxNanoliterPerCentimeter; + dispenser.NanoliterPerCentimeter = liquidVolume.NanoliterPerCentimeter; + dispenser.NanolitterPerSecond = liquidVolume.NanoliterPerSecond; + dispenser.PulsePerSecond = liquidVolume.PulsePerSecond; + + jobStop.Dispensers.Add(dispenser); + } + + jobSegment.BrushStops.Add(jobStop); + } + + ticket.Segments.Add(jobSegment); + } + request.JobTicket = ticket; JobHandler handler = null; @@ -285,7 +431,7 @@ namespace Tango.Integration.Operators /// <returns></returns> public Task<TangoMessage<SetDigitalOutResponse>> SetDigitalOut(SetDigitalOutRequest request) { - return SendRequest<SetDigitalOutRequest, SetDigitalOutResponse>(request); + return SendRequest<SetDigitalOutRequest, SetDigitalOutResponse>(request); } /// <summary> |
