Пример #1
0
 public void OnChange()
 {
     for (int i = 0; i < 8; i++)
     {
         var dmxPacket = new ArtDmx
         {
             ProtVerHi = 6,
             ProtVerLo = 9,
             Sequence  = 0x00,
             Physical  = 0,
             SubUni    = 0,
             Net       = 0,
             LengthHi  = 0,
             LengthLo  = 0,
             Data      = new byte[512]
         };
         dmxPacket.Length   = 512;
         dmxPacket.Universe = i;
         for (int j = 0; j < 58; j++)
         {
             dmxPacket.Data[j * 4]     = (byte)Color.R;
             dmxPacket.Data[j * 4 + 1] = (byte)Color.G;
             dmxPacket.Data[j * 4 + 2] = (byte)Color.B;
             dmxPacket.Data[j * 4 + 3] = (byte)Color.W;
         }
         socket.Send(dmxPacket);
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            var artnet = new ArtNet.Sockets.ArtNetSocket
            {
                EnableBroadcast = true
            };
            var localIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList
                          .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork)
                          .FirstOrDefault();

            Console.WriteLine(artnet.GetBroadcastAddress());
            Console.WriteLine(localIP.ToString());

            artnet.Begin(localIP, IPAddress.Parse("255.255.255.0"));
            artnet.NewPacket += (object sender, ArtNet.Sockets.NewPacketEventArgs <ArtNetPacket> e) =>
            {
                Console.WriteLine(e.Packet.ToString());
                if (e.Packet.OpCode == OpCodes.OpDmx)
                {
                    ArtDmx dmx = ArtDmx.FromData(e.Packet.PacketData);
                    Console.WriteLine(dmx.ToString());
                }
                if (e.Packet.OpCode == OpCodes.OpPoll)
                {
                    var pollReply = new ArtPollReply
                    {
                        IP   = localIP.GetAddressBytes(),
                        Port = (short)artnet.Port,
                        Mac  = NetworkInterface.GetAllNetworkInterfaces()
                               .Where(nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                               .Select(nic => nic.GetPhysicalAddress().GetAddressBytes())
                               .FirstOrDefault(),

                        GoodInput   = new byte[] { 0x08, 0x08, 0x08, 0x08 },
                        GoodOutput  = new byte[] { 0x80, 0x80, 0x80, 0x80 },
                        PortTypes   = new byte[] { 0xc0, 0xc0, 0xc0, 0xc0 },
                        ShortName   = "Art.Net\0",
                        LongName    = "A c# Art-Net 4 Library\0",
                        VersInfoH   = 6,
                        VersInfoL   = 9,
                        Oem         = 0xFFFF,
                        Status1     = 0xd2,
                        Style       = (byte)StyleCodes.StNode,
                        NumPortsLo  = 4,
                        Status2     = 0x08,
                        BindIp      = localIP.GetAddressBytes(),
                        SwIn        = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                        SwOut       = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                        GoodOutput2 = new byte[] { 0x80, 0x80, 0x80, 0x80 },

                        NodeReport = "Up and running\0",
                        Filler     = new byte[168]
                    };

                    artnet.Send(pollReply);
                    Console.WriteLine(pollReply.ToString());
                }
            };
            var artPoll = new ArtPoll
            {
                ProtVer  = 14,
                Priority = PriorityCodes.DpLow
            };

            artnet.SendWithInterval(artPoll, 3000);

            Console.ReadLine();
            artnet.Close();
        }