예제 #1
0
        public static void Main(string[] args)
        {
            var artnet = new ArtNetSocket();

            artnet.EnableBroadcast = true;

            artnet.Open(IPAddress.Any, IPAddress.Broadcast);

            var dmxDataPerUniverse = new Dictionary <short, byte[]>();

            artnet.NewPacket += (object sender, NewPacketEventArgs <ArtNetPacket> e) =>
            {
                if (e.Packet.OpCode == ArtNetOpCodes.Dmx)
                {
                    var packet = e.Packet as ArtNetDmxPacket;

                    byte[] dmxData;
                    if (!dmxDataPerUniverse.TryGetValue(packet.Universe, out dmxData))
                    {
                        dmxData = new byte[512];
                        dmxDataPerUniverse.Add(packet.Universe, dmxData);
                    }

                    if (!packet.DmxData.SequenceEqual(dmxData))
                    {
                        Console.WriteLine("New DMX data for universe {0}", packet.Universe);

                        for (int y = 0; y < 16; y++)
                        {
                            var sb = new StringBuilder();
                            for (int x = 0; x < 16; x++)
                            {
                                int pos = y * 16 + x;

                                if (sb.Length != 0)
                                {
                                    sb.Append(' ');
                                }

                                sb.AppendFormat("{0:X2}", packet.DmxData[pos]);
                            }

                            Console.WriteLine("{0:X2} - {1}", y * 16, sb.ToString());
                        }

                        Console.WriteLine();

                        if (dmxData.Length < packet.DmxData.Length)
                        {
                            dmxData = new byte[packet.DmxData.Length];
                            dmxDataPerUniverse[packet.Universe] = dmxData;
                        }

                        Array.Copy(packet.DmxData, dmxData, dmxData.Length);
                    }
                }
            };

            Console.ReadLine();
        }
    void Start()
    {
        // 初始化 ArtNet socket
        artnet            = new ArtNetSocket();
        dmxDataMap        = new Dictionary <int, Dictionary <int, byte[]> >();
        dmxToSend.DmxData = new byte[512];

        // 为事件绑定函数
        artnet.NewPacket += OnReceiveDmxPacket;
        artnet.NewPacket += OnReceivePollPacket;

        // 如果该 Controller 为 Server 端,那么看是监听接受数据
        if (isServer)
        {
            // 如果设定了子网掩码,就可以指定给哪个网段发送数据
            //artnet.Open(GetLocalIP(), new IPAddress(new byte[] { 255, 0, 0, 0 }));
            artnet.Open(GetLocalIP(), null);
        }

        // 如果不使用广播模式发送 或者 该 Controller 不接受数据
        if (!useBroadcast || !isServer)
        {
            remote = new IPEndPoint(FindFromHostName(remoteIP), ArtNetSocket.Port);
        }

        artnet.Send(pollReplayPacket);
    }
예제 #3
0
 private void InitSocket()
 {
     socket = new ArtNetSocket {
         EnableBroadcast = true
     };
     socket.Open(
         IPAddress.Parse("192.168.0.104"),
         IPAddress.Parse("255.255.255.0"));
     socketClosed = false;
 }
예제 #4
0
 void OnEnable()
 {
     artnet = new ArtNetSocket();
     remote = new IPEndPoint(FindFromHostName(remoteIP), ArtNetSocket.Port);
     artnet.Open(FindFromHostName("localhost"), null);
     FindDataMap();
     Debug.Log("artnet socket");
     artNetData.dmxUpdate.AddListener(Repaint);
     ArtnetReceiver(CallUpdate);
 }
예제 #5
0
        public static void Main(string[] args)
        {
            s_artnet.Open(IPAddress.Parse("192.168.0.1"), IPAddress.Parse("255.255.255.0"));
            s_artnet.EnableBroadcast = true;
            Console.WriteLine("Broadcast address: " + s_artnet.BroadcastAddress.ToString() + "\nAt FPS=" + SENDER_FPS + "\n");

            Timer timer = new Timer(1000 / SENDER_FPS);

            timer.Elapsed += SendArtNet2;
            timer.Start();
            Console.ReadLine();
        }
예제 #6
0
        public void Start()
        {
            if (socket == null || !socket.PortOpen)
            {
                LocalAdapter = localAdapter;

                socket            = new ArtNetSocket(UId.NewUId(32));
                socket.NewPacket += new EventHandler <Acn.Sockets.NewPacketEventArgs <ArtNetPacket> >(socket_NewPacket);
                socket.Open(LocalAdapter, SubnetMask);

                Discover(DiscoveryType.GatewayDiscovery);
            }
        }
예제 #7
0
    void Start()
    {
        artnet = new ArtNetSocket();

        if (isServer)
        {
            artnet.Open(FindFromHostName(remoteIP), null);
        }
        //サブネットマスクを設定すると、自分に送らないアドレスを設定してくれる(便利!)
        //なのだが、デバッグがめんどくさくなる
        dmxToSend.DmxData = new byte[512];

        artnet.NewPacket += (object sender, NewPacketEventArgs <ArtNetPacket> e) =>
        {
            newPacket = true;
            if (e.Packet.OpCode == ArtNet.Enums.ArtNetOpCodes.Dmx)
            {
                var packet = latestReceivedDMX = e.Packet as ArtNetDmxPacket;

                if (packet.DmxData != _dmxData)
                {
                    _dmxData = packet.DmxData;
                }

                var universe = packet.Universe;
                if (dmxDataMap.ContainsKey(universe))
                {
                    dmxDataMap[universe] = packet.DmxData;
                }
                else
                {
                    dmxDataMap.Add(universe, packet.DmxData);
                }
            }
        };

        if (!useBroadcast || !isServer)
        {
            remote = new IPEndPoint(FindFromHostName(remoteIP), ArtNetSocket.Port);
            Debug.Log(ArtNetSocket.Port + "port genutzt, kein server oder kein boreadcast");
        }

        dmxDataMap = new Dictionary <int, byte[]>();
    }
예제 #8
0
        public void Start()
        {
            if (socket == null)
            {
                InitSocket();
            }

            try
            {
                if (TryGetIp(out IPAddress ip) && TryGetSubnetmask(out IPAddress subnet))
                {
                    socket.Open(ip, subnet);
                    Talk.Info("Socket sucessfully binded to " + ip + " / " + subnet);
                }
                else
                {
                    throw new ArgumentException("Ip or subnet mask is currupt");
                }
            }
예제 #9
0
        void Start()
        {
            artnet = new ArtNetSocket();

            if (isServer)
            {
                artnet.Open(FindFromHostName("localhost"), null);
            }

            dmxToSend.DmxData = new byte[512];

            artnet.NewPacket += (object sender, NewPacketEventArgs <ArtNetPacket> e) =>
            {
            };

            if (!useBroadcast || !isServer)
            {
                remote = new IPEndPoint(FindFromHostName(remoteIP), ArtNetSocket.Port);
            }
        }
예제 #10
0
        void Start()
        {
            artnet = new ArtNetSocket();
            InitPackets();
            IPAddress myAddress1 = FindFromHostName(localIP);

            Debug.Log(myAddress1);
            if (isServer)
            {
                artnet.Open(FindFromHostName(localIP), null);
            }

            artnet.NewPacket += (object sender, NewPacketEventArgs <ArtNetPacket> e) =>
            {
                if (e.Packet.OpCode != ArtNetOpCodes.Dmx)
                {
                    return;
                }

                if (ReceiveDMX == null)
                {
                    return;
                }

                var    packet   = e.Packet as ArtNetDmxPacket;
                var    universe = packet.Universe;
                byte[] data     = packet.DmxData.ToArray();
                ReceiveDMX(this, new CCArtNetDMXPaket(universe, data));
            };

            if (remoteIP != null && (!useBroadcast || !isServer))
            {
                IPAddress myAddress = FindFromHostName(remoteIP);
                if (myAddress == null)
                {
                    return;
                }
                remote = new IPEndPoint(myAddress, ArtNetSocket.Port);
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            var configRoot = new ConfigurationBuilder()
                             .AddJsonFile("config.json")
                             .Build();

            var config = configRoot.Get <Configuration>();

            _universe = config.Universe;

            var devices = config.Devices;

            var socket = new ArtNetSocket
            {
                EnableBroadcast = true
            };

            socket.NewPacket += ArtnetReceived;

            foreach (var device in devices)
            {
                _sshClients.Add(new SshClient(device.Host, device.Port, device.Username, device.Password));
            }

            socket.Open(IPAddress.Any, IPAddress.Broadcast);

            while (true)
            {
                foreach (var client in _sshClients)
                {
                    if (!client.IsConnected)
                    {
                        client.Connect();
                        Console.WriteLine($"Connected to {client.ConnectionInfo.Host}");
                    }
                }
                Thread.Sleep(10000);
            }
        }
예제 #12
0
 void OnEnable()
 {
     m_Listener = new ArtNetSocket();
     m_Listener.Open(IPAddress.Parse(LocalIP), null);
     m_Listener.NewPacket += OnInput;
 }
예제 #13
0
 void OnEnable()
 {
     m_Sender = new ArtNetSocket();
     m_Sender.Open(IPAddress.Parse(LocalIP), null);
 }