Exemple #1
0
        public void Test_WhenConnectingOnUsedActiveSocketThenNoConnectionAndRoboDkNotStarted()
        {
            var port = 56252;

            while (!RoboDK.IsTcpPortFree(port))
            {
                port++;
            }

            using (var s = new SocketHelper())
            {
                s.OpenServerAndClient(port);

                RoboDK.IsTcpPortFree(s.ServerPort).Should().BeFalse();
                RoboDK.IsTcpPortFree(s.ClientPort).Should().BeFalse();

                var rdk = new RoboDK
                {
                    RoboDKServerStartPort = port,
                };

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().BeNull();

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().BeNull();

                rdk.Invoking(r => r.CloseRoboDK())
                .Should().Throw <RdkException>();
            }
        }
Exemple #2
0
        public void Test_RoboDkThrowsObjectDisposedExceptionWhenCallingConnectAfterDispose()
        {
            // Given
            var rdk = new RoboDK();

            rdk.Connect().Should().BeTrue();

            // When
            rdk.Dispose();

            // Then
            var whenAction = new Action(() => rdk.Connect());

            whenAction.Should().Throw <ObjectDisposedException>();
        }
Exemple #3
0
        public void Test_ConnectDisconnectWhenRoboDKIsAlreadyRunning()
        {
            var rdk = new RoboDK();

            for (var i = 0; i < 10; i++)
            {
                rdk.Connected().Should().BeFalse();
                rdk.Connect().Should().BeTrue();

                // RoboDK is already running. It is not expected that connect will start a new process
                rdk.Process.Should().BeNull();
                rdk.Connected().Should().BeTrue();

                // Test some properties
                rdk.Version().Should().StartWith("5");
                rdk.ApiVersion.Should().BeGreaterThan(0);
                rdk.RoboDKBuild.Should().BeGreaterThan(0);
                rdk.RoboDKServerPort.Should().BeGreaterThan(0);
                rdk.RoboDKClientPort.Should().BeGreaterThan(0);
                rdk.RoboDKServerIpAddress.Length.Should().BeGreaterThan(0);
                rdk.DefaultSocketTimeoutMilliseconds.Should().BeGreaterThan(1000);

                rdk.Disconnect();
                rdk.Connected().Should().BeFalse();
            }
        }
Exemple #4
0
        public void Test_CommandLineParameter()
        {
            var rdk = new RoboDK
            {
                ApplicationDir        = "C:\\zBuilds\\Bystronic\\repository\\ByRobotManager-2\\ByRobotManager\\bin\\Debug\\RoboDK\\RoboDK.exe",
                RoboDKServerStartPort = 56252,

                //CustomCommandLineArgumentString = "-NOSPLASH -NOSHOW -HIDDEN -PORT=56252  -NOSTDOUT -SKIPINIRECENT -SKIPINI -SKIPCOM -EXIT_LAST_COM -NOUI",
                CustomCommandLineArgumentString = "-PORT=56252  -NOSTDOUT -SKIPINIRECENT -SKIPINI -SKIPCOM -EXIT_LAST_COM -NOUI -TREE_STATE=-1",

                //CustomCommandLineArgumentString = "/NOSPLASH /NOSHOW /HIDDEN /PORT=56252  /NOSTDOUT /SKIPINIRECENT /SKIPINI /SKIPCOM /EXIT_LAST_COM /NOUI /TREE_STATE=-1",
                //CustomCommandLineArgumentString = "/NOSPLASH /NOSHOW /HIDDEN /NOSTDOUT /SKIPINIRECENT /SKIPINI /SKIPCOM /EXIT_LAST_COM /NOUI /TREE_STATE=-1"
                //CustomCommandLineArgumentString = "/NOSTDOUT /SKIPINIRECENT /SKIPINI /SKIPCOM /EXIT_LAST_COM /NOUI"
            };

            rdk.Connect();

//            Thread.Sleep(5000);
            var mainWindow = rdk.Command("MainWindow_ID");

            var item = rdk.AddFile(@"C:\Users\mth\AppData\Local\Temp\ByRobotManager_Geometries\Regrip lower arm NS2+NS3_collision.sld");

            item.SetParam("FilterMesh", "0,0.0001,0.005");

            var mainWindowId = int.Parse(mainWindow);


            rdk.CloseRoboDK();
        }
Exemple #5
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            var rdk    = new RoboDK();
            var status = false;

            //The first connect opens roboDK
            status = rdk.Connect();
            Console.WriteLine($"Connect status: {status}");
            //rdk.CloseStation();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            RoboDK RDK    = new RoboDK();
            bool   status = false;

            //The first connect opens roboDK
            status = RDK.Connect();
            Console.WriteLine("Connect status: " + status.ToString());
            int b = 1;
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var rdk = new RoboDK();

            // Connect to existing RoboDK or start a new one if RoboDK is not running
            var status = rdk.Connect();

            Console.WriteLine($"Connect status: {status}");

            // close RoboDK
            rdk.CloseRoboDK();
        }
Exemple #8
0
        public void Test_WhenStartingOnUsedActiveSocketThenNoConnectionAndRoboDkNotStarted()
        {
            var port = 56252;

            while (!RoboDK.IsTcpPortFree(port))
            {
                port++;
            }

            using (var s = new SocketHelper())
            {
                s.OpenServerAndClient(port);

                RoboDK.IsTcpPortFree(s.ServerPort).Should().BeFalse();
                RoboDK.IsTcpPortFree(s.ClientPort).Should().BeFalse();

                var rdk = new RoboDK
                {
                    StartNewInstance      = true,
                    RoboDKServerStartPort = port,
                };

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().NotBeNull();
                rdk.Process.HasExited.Should().BeTrue();
                Process.GetProcessesByName("RoboDK").Should().BeEmpty();

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().NotBeNull();
                rdk.Process.HasExited.Should().BeTrue();
                Process.GetProcessesByName("RoboDK").Should().BeEmpty();

                rdk.Invoking(r => r.CloseRoboDK())
                .Should().Throw <RdkException>();
            }
        }
Exemple #9
0
        public void Test_WhenEndServerPortSmallerThenStartServerPortThenThrowRdkException()
        {
            var rdk = new RoboDK
            {
                RoboDKServerStartPort = 10000,
                RoboDKServerEndPort   = 9000
            };

            rdk.RoboDKServerStartPort.Should().Be(10000);
            rdk.RoboDKServerEndPort.Should().Be(9000);

            Action act = () => rdk.Connect();

            act.Should().Throw <RdkException>();
        }
Exemple #10
0
        static void Main(string[] args)
        {
            RoboDK RDK = new RoboDK
            {
                RoboDKServerStartPort = 20500,
                RoboDKServerEndPort   = 20500
            };
            bool status = RDK.Connect();

            Console.WriteLine("Connect status: " + status.ToString());
            Console.WriteLine("Last status message: " + RDK.LastStatusMessage);

            var robot = RDK.GetItemByName("", RoboDk.API.Model.ItemType.Robot);

            robot.Connect();
            //robot.;

            int b = 1;
        }
Exemple #11
0
        public void Test_BasicEventListenerApi()
        {
            var rdk = new RoboDK();

            rdk.Connect();

            // Open Event Channel
            var eventListener = rdk.OpenRoboDkEventChannel();
            var noEvent       = eventListener.WaitForEvent();

            noEvent.EventType.Should().Be(EventType.NoEvent);

            // Test Simple Event
            var frame1         = rdk.AddFrame("Frame1");
            var itemMovedEvent = eventListener.WaitForEvent();

            itemMovedEvent.EventType.Should().Be(EventType.ItemMovedPose);
            itemMovedEvent.Item.Name().Should().Be("Frame1");

            // The RoboDK link must be set to the RoboDK API instance
            itemMovedEvent.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort);

            // Open a second event channel
            var eventListener2  = rdk.OpenRoboDkEventChannel();
            var frame2          = rdk.AddFrame("Frame2");
            var eventOnChannel1 = eventListener.WaitForEvent();
            var eventOnChannel2 = eventListener2.WaitForEvent();

            eventOnChannel1.EventType.Should().Be(EventType.ItemMovedPose);
            eventOnChannel1.Item.Name().Should().Be("Frame2");
            eventOnChannel2.EventType.Should().Be(EventType.ItemMovedPose);
            eventOnChannel2.Item.Name().Should().Be("Frame2");
            eventOnChannel1.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort);
            eventOnChannel2.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort);

            // After closing an event channel we should get an exception when calling WaitForEvent
            eventListener.Close();
            var whenAction = new Action(() => eventListener.WaitForEvent());

            whenAction.Should().Throw <ObjectDisposedException>();
        }
Exemple #12
0
        public void Test_ParallelRoboDKConnections()
        {
            var stopAsyncTask = false;
            var rdk           = new RoboDK
            {
                RoboDKServerStartPort = 10000,
                Logfile = Path.Combine(Directory.GetCurrentDirectory(), "RoboDk.log"),
                DefaultSocketTimeoutMilliseconds = 20 * 1000
            };

            rdk.Connect();
            rdk.Render(false);
            rdk.Command("AutoRenderDelay", 50);
            rdk.Command("AutoRenderDelayMax", 300);
            rdk.DefaultSocketTimeoutMilliseconds = 10 * 1000;

            List <IItem> AddStaticParts()
            {
                var parts = new List <IItem>();
                var cwd   = Directory.GetCurrentDirectory();

                parts.Add(rdk.AddFile(Path.Combine(cwd, "TableOut.sld")));
                parts.Add(rdk.AddFile(Path.Combine(cwd, "robot.robot")));
                return(parts);
            }

            List <IItem> AddDynamicParts()
            {
                var parts = new List <IItem>();
                var cwd   = Directory.GetCurrentDirectory();

                for (var n = 0; n < 10; n++)
                {
                    parts.Add(rdk.AddFile(Path.Combine(cwd, "Phone Case Box.sld")));
                    parts.Add(rdk.AddFile(Path.Combine(cwd, "Box.sld")));
                    parts.Add(rdk.AddFile(Path.Combine(cwd, "Phone Case Done.sld")));
                }

                return(parts);
            }

            // Task which opens a temporary new connection
            void DoTemporaryConnectionCalls(IReadOnlyCollection <IItem> staticParts)
            {
                // ReSharper disable once AccessToModifiedClosure
                while (!stopAsyncTask)
                {
                    foreach (var staticPart in staticParts)
                    {
                        Thread.Sleep(1);
                        using (var roboDkLink = new RoboDK.RoboDKLink(staticPart.RDK()))
                        {
                            var clonedItem = staticPart.Clone(roboDkLink.RoboDK);
                            clonedItem.Pose();
                        }
                    }
                }
            }

            var p    = AddStaticParts();
            var task = new Task(() => DoTemporaryConnectionCalls(p));

            task.Start();

            try
            {
                for (var i = 0; i < 20; i++)
                {
                    var dynamicParts = AddDynamicParts();
                    rdk.Command("CollisionMap", "Off");
                    rdk.SetCollisionActive(CollisionCheckOptions.CollisionCheckOff);
                    rdk.Delete(dynamicParts);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                stopAsyncTask = true;
            }

            try
            {
                task.Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                rdk.CloseRoboDK();
            }
        }
Exemple #13
0
 /// <inheritdoc />
 public void NewLink()
 {
     Link = new RoboDK();
     Link.Connect();
 }