Пример #1
0
        public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            if (config == null)
            {
                throw new InvalidOperationException("Robot configuration is not set.");
            }

            Task.Run(() => {
                Task communicationTask = Connect();

                communicationTask.ContinueWith(task => {
                    string robotAdress = ToString();
                    rsiAdapter.Disconnect();

                    if (task.IsFaulted)
                    {
                        var args = new ErrorOccuredEventArgs {
                            RobotIp   = robotAdress,
                            Exception = task.Exception.GetBaseException()
                        };

                        ErrorOccured?.Invoke(this, args);
                    }

                    isInitialized = false;
                    Uninitialized?.Invoke(this, EventArgs.Empty);
                });
            });
        }
Пример #2
0
        private void Connect()
        {
            IsCancellationRequested = false;
            InputFrame receivedFrame = new InputFrame {
                Position     = HomePosition,
                AxisPosition = RobotAxisVector.Zero,
                IPOC         = 0
            };

            generator.Initialize(receivedFrame.Position);

            lock (receivedDataSyncLock) {
                position     = receivedFrame.Position;
                HomePosition = receivedFrame.Position;
            }

            isInitialized = true;
            Initialized?.Invoke(this, EventArgs.Empty);

            // Start loop for receiving and sending data

            try {
                while (!IsCancellationRequested)
                {
                    long IPOC = ReceiveDataAsync();
                    SendData(IPOC);
                    Thread.Sleep(4);
                }
            } catch (Exception e) {
                var args = new ErrorOccuredEventArgs {
                    RobotIp   = ToString(),
                    Exception = e
                };

                ErrorOccured?.Invoke(this, args);
            }

            isInitialized = false;
            Uninitialized?.Invoke(this, EventArgs.Empty);
        }