예제 #1
0
파일: Tests.cs 프로젝트: OsOmE1/Art.Net
        public void TestPacketSerialization()
        {
            var data      = new ArtNetData();
            var pollReply = new ArtPollReply
            {
                IP   = IPAddress.Parse("127.0.0.1").GetAddressBytes(),
                Port = 0x1936,
                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   = "ShortName Test",
                LongName    = "Art.Net LongName Test",
                EstaManLo   = 0,
                VersInfoH   = 6,
                VersInfoL   = 9,
                SubSwitch   = 0,
                OemHi       = 0,
                Oem         = 0xFF,
                UbeaVersion = 0,
                Status1     = 0xd2,
                SwMacro     = 0,
                SwRemote    = 0,
                Style       = StyleCodes.StNode,
                NumPortsHi  = 0,
                NumPortsLo  = 4,
                Status2     = 0x08,
                BindIp      = IPAddress.Parse("127.0.0.1").GetAddressBytes(),
                SwIn        = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                SwOut       = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                GoodOutput2 = new byte[] { 0x80, 0x80, 0x80, 0x80 },

                NodeReport = "NodeReport Test",
                Filler     = new byte[168]
            };

            data.Buffer = pollReply.ToArray();

            var altPacket = ArtNetPacket.FromData(data);

            Assert.AreEqual(altPacket.OpCode, pollReply.OpCode);

            var pollReplyPacket = altPacket.Cast <ArtPollReply>();

            Assert.AreEqual(pollReplyPacket.ShortName, pollReply.ShortName);
            Assert.AreEqual(pollReplyPacket.LongName, pollReply.LongName);

            Assert.AreEqual(pollReplyPacket.NodeReport, pollReply.NodeReport);

            Assert.Pass();
        }
예제 #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();
        }