3 using System.Net.Sockets;
8 namespace DirectOutput.Cab.Out.DMX.ArtnetEngine
17 private static readonly Lazy<Engine> lazy =
new Lazy<Engine>(() =>
new Engine());
25 public static Engine Instance {
get {
return lazy.Value; } }
39 ArtNetHeader =
new byte[] { 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0 };
42 lock (UdpServerLocker)
46 UdpServer =
new UdpClient(0x1936);
47 UdpServer.EnableBroadcast =
true;
48 UdpServer.Client.SendTimeout = 100;
49 UdpServer.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress,
true);
53 Log.
Exception(
"Could not initialize UdpServer for ArtNet (Port: 6454).", E);
64 lock (UdpServerLocker)
66 if (UdpServer != null)
79 int SendExceptionCnt = 0;
87 public void SendDMX(
string BroadcastAdress,
short Universe, byte[] Data,
int DataLength)
89 if (UdpServer != null)
91 byte[] packet =
new byte[(0x11 + DataLength) + 1];
92 Buffer.BlockCopy(this.ArtNetHeader, 0, packet, 0, this.ArtNetHeader.Length);
93 packet[8] = Convert.ToByte(this.LoByte(0x5000));
94 packet[9] = Convert.ToByte(this.HiByte(0x5000));
99 packet[14] = Convert.ToByte(this.LoByte(Universe));
100 packet[15] = Convert.ToByte(this.HiByte(Universe));
101 packet[0x10] = Convert.ToByte(this.HiByte(DataLength));
102 packet[0x11] = Convert.ToByte(this.LoByte(DataLength));
106 Buffer.BlockCopy(Data, 0, packet, 0x12, DataLength);
108 catch (Exception exception1)
110 Log.
Exception(
"A exception occured in the ArtNet Engine class.", exception1);
114 lock (UdpServerLocker)
116 if (UdpServer != null)
121 UdpServer.Send(packet, packet.Length, BroadcastAdress, 0x1936);
122 SendExceptionCnt = 0;
127 if (SendExceptionCnt > 10)
131 Log.
Exception(
"More than 10 consuecutive transmissions of ArtNet data have failed. ArtNet enigine will be disabled for the session.", E);
135 if (UdpServer != null)
147 Log.
Exception(
"A exception has occured when sending ArtNet data.", E);
162 #region "Work Around"
165 private object LoByte(
int wParam)
167 return (wParam & 0xffL);
170 private object HiByte(
int wParam)
172 return ((wParam / 0x100) & 0xffL);
181 private object UdpServerLocker =
new object();
182 private UdpClient UdpServer;
185 private byte[] ArtNetHeader;