Exemple #1
0
        /// <summary>
        /// Called every time this plugin is run in the workflow execution.
        /// </summary>
        public void Execute()
        {
            // HOWTO: Use this to show the progress of a plugin algorithm execution in the editor.
            ProgressChanged(1, 100);

            if (IsValidIP(settings.DeviceIP))
            {
                // Init
                endPoint     = new IPEndPoint(IPAddress.Parse(settings.DeviceIP), settings.Port);
                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                using (CStreamReader streamReader = PackageStream.CreateReader())
                {
                    packetData = new byte[1024];


                    while ((bytesRead = streamReader.Read(packetData)) > 0)
                    {
                        var input = new List <byte>();
                        // Note: buffer can contain less data than buffer.Length, therefore consider bytesRead
                        foreach (var zero in packetData)
                        {
                            if (zero != 0)
                            {
                                input.Add(zero);
                            }
                            else
                            {
                                break;
                            }
                        }
                        clientSocket.SendTo(input.ToArray(), endPoint);
                    }
                }
            }
            else
            {
                GuiLogMessage("Ungueltige IP!", NotificationLevel.Error);
            }



            // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully.
            ProgressChanged(1, 1);
        }
Exemple #2
0
        /// <summary>
        ///   Called every time this plugin is run in the workflow execution.
        /// </summary>
        public void Execute()
        {
            ProgressChanged(1, 100);

            //get or create Connection
            if (ConnectionIDInput == 0)
            {
                var con = TryCreateNewConnection();
                if (con == null)
                {
                    GuiLogMessage("Could not create a network connection", NotificationLevel.Error);
                    return;
                }

                ConnectionIDInput = availableConnections.AddConnection(con);
            }
            var connection = availableConnections.GetConnection(ConnectionIDInput);

            //chop and send data
            using (var streamReader = PackageStream.CreateReader())
            {
                var streamBuffer = new byte[65507];
                int bytesRead;
                while ((bytesRead = streamReader.Read(streamBuffer)) > 0)
                {
                    var packetData = new byte[bytesRead];
                    Array.Copy(streamBuffer, packetData, bytesRead);

                    if (TrySendData(connection, packetData, bytesRead))
                    {
                        UpdateOutputs(connection.ID);
                        UpdatePresentation(packetData, connection.RemoteEndPoint);
                    }
                }
            }
            ProgressChanged(1, 1);
        }