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)
47 UdpServer =
new UdpClient();
48 UdpServer.ExclusiveAddressUse =
false;
50 UdpServer.EnableBroadcast =
true;
51 UdpServer.Client.SendTimeout = 100;
52 UdpServer.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress,
true);
57 Log.
Exception(
"Could not initialize UdpServer for ArtNet (Port: 6454).", E);
68 lock (UdpServerLocker)
70 if (UdpServer != null)
84 int SendExceptionCnt = 0;
92 public void SendDMX(
string BroadcastAdress,
short Universe, byte[] Data,
int DataLength)
94 if (UdpServer != null)
96 byte[] packet =
new byte[(0x11 + DataLength) + 1];
97 Buffer.BlockCopy(this.ArtNetHeader, 0, packet, 0, this.ArtNetHeader.Length);
98 packet[8] = Convert.ToByte(this.LoByte(0x5000));
99 packet[9] = Convert.ToByte(this.HiByte(0x5000));
104 packet[14] = Convert.ToByte(this.LoByte(Universe));
105 packet[15] = Convert.ToByte(this.HiByte(Universe));
106 packet[0x10] = Convert.ToByte(this.HiByte(DataLength));
107 packet[0x11] = Convert.ToByte(this.LoByte(DataLength));
111 Buffer.BlockCopy(Data, 0, packet, 0x12, DataLength);
113 catch (Exception exception1)
115 Log.
Exception(
"A exception occured in the ArtNet Engine class.", exception1);
119 lock (UdpServerLocker)
121 if (UdpServer != null)
126 UdpServer.Send(packet, packet.Length, BroadcastAdress, 0x1936);
127 SendExceptionCnt = 0;
132 if (SendExceptionCnt > 10)
136 Log.
Exception(
"More than 10 consuecutive transmissions of ArtNet data have failed. ArtNet enigine will be disabled for the session.", E);
140 if (UdpServer != null)
152 Log.
Exception(
"A exception has occured when sending ArtNet data.", E);
167 #region "Work Around"
170 private object LoByte(
int wParam)
172 return (wParam & 0xffL);
175 private object HiByte(
int wParam)
177 return ((wParam / 0x100) & 0xffL);
186 private object UdpServerLocker =
new object();
187 private UdpClient UdpServer;
190 private byte[] ArtNetHeader;
Artnet Engine used for DMX output. The code of this class is based on the Engine class of eDMX...
A simple logger used to record important events and exceptions.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.
void SendDMX(string BroadcastAdress, short Universe, byte[] Data, int DataLength)
Sends DMX data to a Art-Net node.