1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR;
using Tango.PMR.Diagnostics;
using Tango.Transport;
using Tango.Transport.Transporters;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Threading;
using Tango.PMR.Common;
using Tango.PMR.Printing;
using Tango.Integration.Observables;
using System.Reactive.Subjects;
using Tango.Integration.Printing;
namespace Tango.Integration.Operators
{
public class MachineOperator : BasicTransporter, IMachineOperator
{
/// <summary>
/// Occurs when there is new diagnostics data available.
/// </summary>
public event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable;
private bool _enableDiagnostics;
/// <summary>
/// Gets or sets a value indicating whether to enable diagnostics messages by requesting diagnostics messages.
/// </summary>
public bool EnableSensorsUpdate
{
get { return _enableDiagnostics; }
set
{
if (_enableDiagnostics != value)
{
_enableDiagnostics = value;
RaisePropertyChangedAuto();
OnEnableSensorsUpdateChanged(value);
}
}
}
/// <summary>
/// Called when the enable sensors update property has been changed
/// </summary>
/// <param name="value">if set to <c>true</c> [value].</param>
protected virtual void OnEnableSensorsUpdateChanged(bool value)
{
if (value && State == TransportComponentState.Connected)
{
SendContinuousRequest<PushDiagnosticsRequest, PushDiagnosticsResponse>(new TangoMessage<PushDiagnosticsRequest>(new PushDiagnosticsRequest()
{
PushMotors = true,
PushSensors = true,
}, MessageType.PushDiagnosticsRequest)).ObserveOn(new NewThreadScheduler()).Subscribe(
(response) =>
{
OnDiagnosticsDataAvailable(response);
},
(ex) =>
{
//Do I need separate event for each one ??
},
() =>
{
//What to do now ??
});
}
}
/// <summary>
/// Invokes the <see cref="DiagnosticsDataAvailable"/> event.
/// </summary>
/// <param name="data">The sensors data.</param>
protected virtual void OnDiagnosticsDataAvailable(PushDiagnosticsResponse data)
{
DiagnosticsDataAvailable?.Invoke(this, data);
}
/// <summary>
/// Called when the component state has changed.
/// </summary>
/// <param name="state">The state.</param>
protected override void OnStateChanged(TransportComponentState state)
{
base.OnStateChanged(state);
OnEnableSensorsUpdateChanged(EnableSensorsUpdate);
}
/// <summary>
/// Prints the specified job.
/// </summary>
/// <param name="job">The job.</param>
/// <param name="processParameters">Process parameters table</param>
/// <returns></returns>
public JobHandler Print(Job job, ProcessParametersTable processParameters)
{
JobRequest request = new JobRequest();
JobTicket ticket = new JobTicket();
ticket.EnableInterSegment = job.EnableInterSegment;
ticket.InterSegmentLength = job.InterSegmentLength;
ticket.Length = job.Length;
ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code;
ProcessParameters process = new ProcessParameters();
process.DyeingSpeed = processParameters.DyeingSpeed;
process.MinInkUptake = processParameters.MinInkUptake;
process.MixerTemp = processParameters.MixerTemp;
process.HeadZone1Temp = processParameters.HeadZone1Temp;
process.HeadZone2Temp = processParameters.HeadZone2Temp;
process.HeadZone3Temp = processParameters.HeadZone3Temp;
process.HeadAirFlow = processParameters.HeadAirFlow;
process.FeederTension = processParameters.FeederTension;
process.PullerTension = processParameters.PullerTension;
process.DryerBufferLength = processParameters.DryerBufferLength;
process.DryerZone1Temp = processParameters.DryerZone1Temp;
process.DryerZone2Temp = processParameters.DryerZone2Temp;
process.DryerZone3Temp = processParameters.DryerZone3Temp;
process.DryerAirFlow = processParameters.DryerAirFlow;
process.WinderTension = processParameters.WinderTension;
ticket.ProcessParameters = process;
request.JobTicket = ticket;
JobHandler handler = null;
handler = new JobHandler(async () =>
{
try
{
var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest());
handler.RaiseCanceled();
}
catch (Exception)
{
//TODO: What to do in case job failed to cancel ??
}
});
SendContinuousRequest<JobRequest, JobResponse>(request).Subscribe((response) =>
{
handler.RaiseStatusReceived(response.Message.Status);
},(ex) =>
{
if (!handler.IsCanceled)
{
handler.RaiseFailed(ex);
}
},() =>
{
handler.RaiseCompleted();
});
return handler;
}
}
}
|