2 using System.Threading;
3 using DirectOutput.Cab.Out.DMX.ArtnetEngine;
4 using System.Xml.Serialization;
7 namespace DirectOutput.Cab.Out.DMX
24 private byte[] DMXData =
new byte[512];
25 private int LastDMXChannel = 0;
26 private bool UpdateRequired =
true;
27 private object UpdateLocker =
new object();
29 private short _Universe = 0;
39 get {
return _Universe; }
40 set { _Universe = value; }
43 private string _BroadcastAddress=
"";
53 public string BroadcastAddress
55 get {
return _BroadcastAddress; }
56 set { _BroadcastAddress = value; }
64 private void AddOutputs()
66 for (
int i = 1; i <= 512; i++)
68 if (!Outputs.Any(x => ((
DMXOutput)x).DmxChannel == i))
70 Outputs.Add(
new DMXOutput() { Name =
"{0}.{1:000}".Build(Name, i), DmxChannel=i });
86 throw new Exception(
"The OutputValueChanged event handler for ArtNet node {0} (controlling Dmx universe {1}) has been called by a sender which is not a DmxOutput.".Build(Name, Universe));
89 DMXOutput O = (DMXOutput)Output;
93 Log.
Exception(
"ArtNet node {0} has received a update for a illegal dmx channel number ({1}).".Build(Name, O.
DmxChannel));
94 throw new ArgumentOutOfRangeException(
"ArtNet node {0} has received a update for a illegal dmx channel number ({1}).".Build(Name, O.
DmxChannel));
107 UpdateRequired =
true;
118 public override void Update()
122 UpdaterThreadSignal();
138 Log.
Write(
"ArtNet node {0} (controlling universe {1}) initialized and updater thread started.".Build(Name,Universe));
144 public override void Finish()
146 FinishUpdaterThread();
147 Log.
Write(
"ArtNet node {0} (controlling universe {1}) finished and updater thread stopped.".Build(Name, Universe));
153 #region UpdaterThread
158 private void InitUpdaterThread()
161 if (!UpdaterThreadIsActive)
163 KeepUpdaterThreadAlive =
true;
166 UpdaterThread =
new Thread(UpdaterThreadDoIt);
167 UpdaterThread.Name =
"ArtNet node {0} updater thread ".Build(Name);
168 UpdaterThread.Start();
172 Log.
Exception(
"Artnet node {0} updater thread could not start.".Build(Name), E);
173 throw new Exception(
"Artnet node {0} updater thread could not start.".Build(Name), E);
182 private void FinishUpdaterThread()
184 if (UpdaterThread != null)
188 KeepUpdaterThreadAlive =
false;
189 lock (UpdaterThreadLocker)
191 Monitor.Pulse(UpdaterThreadLocker);
193 if (!UpdaterThread.Join(1000))
195 UpdaterThread.Abort();
197 UpdaterThread = null;
201 Log.Exception(
"A error occured during termination of ArtNet updater thread.", E);
202 throw new Exception(
"A error occured during termination of ArtNet updater thread.", E);
211 public bool UpdaterThreadIsActive
215 if (UpdaterThread != null)
217 if (UpdaterThread.IsAlive)
229 private void UpdaterThreadSignal()
232 lock (UpdaterThreadLocker)
234 Monitor.Pulse(UpdaterThreadLocker);
239 private Thread UpdaterThread {
get;
set; }
240 private object UpdaterThreadLocker =
new object();
241 private bool KeepUpdaterThreadAlive =
true;
249 private void UpdaterThreadDoIt()
260 while (KeepUpdaterThreadAlive)
267 UpdateRequired =
false;
273 if (KeepUpdaterThreadAlive)
275 lock (UpdaterThreadLocker)
277 while (UpdateRequired ==
false && KeepUpdaterThreadAlive)
279 Monitor.Wait(UpdaterThreadLocker, 50);
285 Engine.
SendDMX(BroadcastAddress, Universe,
new byte[512], 512);