Ejemplo n.º 1
0
        //internal bool Monitor()
        //{
        //    if (TryConnectMonitor())
        //    {
        //        // Establish a MotionCursor on `Control`
        //        this._parentDriver.parentControl.InitializeMotionCursor();
        //        this._motionCursor = this._parentDriver.parentControl.MotionCursor;

        //        return true;
        //    }

        //    return false;
        //}

        private bool TryConnectMonitor()
        {
            try
            {
                _monitorClientSocket = new TcpClient();
                _monitorClientSocket.Connect(this._monitorIP, this._monitorPort);
                _monitorStatus = TCPConnectionStatus.Connected;
                _monitorClientSocket.ReceiveBufferSize = 1024;
                _monitorClientSocket.SendBufferSize    = 1024;

                _monitoringThread = new Thread(MonitoringMethod);
                _monitoringThread.IsBackground = true;
                _monitoringThread.Start();

                _isMonitored = true;

                return(_monitorClientSocket.Connected);
            }
            catch (Exception ex)
            {
                logger.Info("Real-time monitoring not available on this device");
                DisconnectMonitor();
            }

            return(false);
        }
Ejemplo n.º 2
0
        private bool DisconnectMonitor()
        {
            if (_monitorClientSocket != null && _isMonitored)
            {
                try
                {
                    if (_monitorClientSocket.Connected != null && _monitorClientSocket.Connected)
                    {
                        _monitorClientSocket.Client.Disconnect(false);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Something went wrong trying to disconnect from monitor");
                    logger.Error(ex.ToString());
                }

                _monitorClientSocket.Close();
                _monitorStatus = TCPConnectionStatus.Disconnected;
                _isMonitored   = false;

                return(true);
            }

            return(false);
        }
        internal bool Disconnect()
        {
            if (_clientSocket != null)
            {
                // Upload an empty script to stop the running program
                LoadEmptyScript();
                UploadScriptToDevice(_driverScript, false);

                ClientSocketStatus = TCPConnectionStatus.Disconnected;
                _clientSocket.Client.Disconnect(false);
                _clientSocket.Close();
                if (_clientNetworkStream != null)
                {
                    _clientNetworkStream.Dispose();
                }

                _isServerListeningRunning = false;

                // TESTING
                _robotSocket.Close();
                _robotSocket.Dispose();
                _robotSocket = null;

                _serverSocket.Stop();
                _serverSocket = null;

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        internal bool Connect()
        {
            try
            {
                clientSocket = new TcpClient();
                clientSocket.Connect(this._ip, this._port);
                Status = TCPConnectionStatus.Connected;
                clientNetworkStream            = clientSocket.GetStream();
                clientSocket.ReceiveBufferSize = 1024;
                clientSocket.SendBufferSize    = 1024;

                sendingThread = new Thread(SendingMethod);
                sendingThread.IsBackground = true;
                sendingThread.Start();

                receivingThread = new Thread(ReceivingMethod);
                receivingThread.IsBackground = true;
                receivingThread.Start();

                return(clientSocket.Connected);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw new Exception("ERROR: could not establish TCP connection");
            }

            //return false;
        }
        internal bool Connect()
        {
            try
            {
                clientSocket = new TcpClient();
                clientSocket.Connect(this._ip, this._port);
                Status = TCPConnectionStatus.Connected;
                clientNetworkStream            = clientSocket.GetStream();
                clientSocket.ReceiveBufferSize = 1024;
                clientSocket.SendBufferSize    = 1024;

                sendingThread = new Thread(SendingMethod);
                sendingThread.IsBackground = true;
                sendingThread.Start();

                receivingThread = new Thread(ReceivingMethod);
                receivingThread.IsBackground = true;
                receivingThread.Start();

                if (!WaitForInitialization())
                {
                    Console.WriteLine("Machina error: timeout when waiting for initialization data from the controller");
                    return(false);
                }

                return(clientSocket.Connected);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw new Exception("ERROR: could not establish TCP connection");
            }

            //return false;
        }
        internal bool Connect()
        {
            try
            {
                _clientSocket = new TcpClient();
                _clientSocket.Connect(this._robotIP, this._robotPort);
                ClientSocketStatus              = TCPConnectionStatus.Connected;
                _clientNetworkStream            = _clientSocket.GetStream();
                _clientSocket.ReceiveBufferSize = 2048;
                _clientSocket.SendBufferSize    = 1024;

                //// We don't need a sending thread to the client anymore, since the driver script will only be uplaoded once.
                //_clientSendingThread = new Thread(ClientSendingMethod);
                //_clientSendingThread.IsBackground = true;
                //_clientSendingThread.Start();

                _clientReceivingThread = new Thread(ClientReceivingMethod);
                _clientReceivingThread.IsBackground = true;
                _clientReceivingThread.Start();

                if (!Machina.Net.GetLocalIPAddressInNetwork(_robotIP, "255.255.255.0", out _serverIP))
                {
                    throw new Exception("ERROR: Could not figure out local IP");
                }
                Console.WriteLine("Machina local IP: " + _serverIP);

                _serverSocket = new TcpListener(IPAddress.Parse(_serverIP), _serverPort);
                _serverSocket.Start();

                _isServerListeningRunning           = true;
                _serverListeningThread              = new Thread(ServerReceivingMethod);
                _serverListeningThread.IsBackground = true;
                _serverListeningThread.Start();

                //LoadStreamProgramParts();
                LoadDriverScript();
                UploadScriptToDevice(_driverScript, false);

                return(_clientSocket.Connected);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: something went wrong trying to connect to robot...");
                Console.WriteLine(ex);
                throw new Exception();
            }

            //return false;
        }
Ejemplo n.º 7
0
        internal bool Disconnect()
        {
            if (clientSocket != null)
            {
                Status = TCPConnectionStatus.Disconnected;
                clientSocket.Client.Disconnect(false);
                clientSocket.Close();
                if (clientNetworkStream != null)
                {
                    clientNetworkStream.Dispose();
                }
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        internal bool Connect()
        {
            try
            {
                _clientSocket = new TcpClient();
                _clientSocket.Connect(this._ip, this._port);
                _clientStatus                   = TCPConnectionStatus.Connected;
                _clientNetworkStream            = _clientSocket.GetStream();
                _clientSocket.ReceiveBufferSize = 1024;
                _clientSocket.SendBufferSize    = 1024;

                _sendingThread = new Thread(SendingMethod);
                _sendingThread.IsBackground = true;
                _sendingThread.Start();

                _receivingThread = new Thread(ReceivingMethod);
                _receivingThread.IsBackground = true;
                _receivingThread.Start();

                if (!WaitForInitialization())
                {
                    logger.Error("Timeout when waiting for initialization data from the controller");
                    Disconnect();
                    return(false);
                }

                // During YuMi development I was having a really weird problem: if a monitor is running, I cannot connect to another driver in the same unit...
                // So, for the time being, let's make monitoring an explicit process with its own API?
                if (TryConnectMonitor())
                {
                    // Establish a MotionCursor on `Control`
                    this._parentDriver.parentControl.InitializeMotionCursor();
                    this._motionCursor = this._parentDriver.parentControl.MotionCursor;
                }

                return(_clientSocket.Connected);
            }
            catch (Exception ex)
            {
                logger.Debug(ex);
                //throw new Exception("ERROR: could not establish TCP connection");
                Disconnect();
            }

            return(false);
        }
Ejemplo n.º 9
0
        internal bool Disconnect()
        {
            if (_clientSocket != null)
            {
                ClientSocketStatus = TCPConnectionStatus.Disconnected;
                _clientSocket.Client.Disconnect(false);
                _clientSocket.Close();
                if (_clientNetworkStream != null)
                {
                    _clientNetworkStream.Dispose();
                }

                _isServerListeningRunning = false;

                return(true);
            }

            return(false);
        }
        internal bool Disconnect()
        {
            if (_clientSocket != null)
            {
                // Upload an empty script to stop the running program
                string emptyScript = LoadEmptyScript();
                if (!UploadScriptToDevice(emptyScript, false))
                {
                    Logger.Error("Could not load empty script to robot");
                }

                try
                {
                    ClientSocketStatus = TCPConnectionStatus.Disconnected;
                    _clientSocket.Client.Disconnect(false);
                    _clientSocket.Close();
                    if (_clientNetworkStream != null)
                    {
                        _clientNetworkStream.Dispose();
                    }

                    _isServerListeningRunning = false;

                    // TESTING
                    _robotSocket.Close();
                    _robotSocket.Dispose();
                    _robotSocket = null;

                    _serverSocket.Stop();
                    _serverSocket = null;
                    return(true);
                }
                catch (Exception ex)
                {
                    logger.Error("Something went wrong on disconnection:");
                    logger.Error(ex);
                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 11
0
        internal bool Disconnect()
        {
            DisconnectMonitor();

            if (_clientSocket != null)
            {
                _clientStatus = TCPConnectionStatus.Disconnected;
                try
                {
                    _clientSocket.Client.Disconnect(false);
                }
                catch { }
                _clientSocket.Close();
                if (_clientNetworkStream != null)
                {
                    _clientNetworkStream.Dispose();
                }
                return(true);
            }

            return(false);
        }
        internal bool Connect()
        {
            try
            {
                _clientSocket = new TcpClient();
                _clientSocket.Connect(this._robotIP, this._robotPort);
                ClientSocketStatus              = TCPConnectionStatus.Connected;
                _clientNetworkStream            = _clientSocket.GetStream();
                _clientSocket.ReceiveBufferSize = 2048;
                _clientSocket.SendBufferSize    = 1024;

                //// We don't need a sending thread to the client anymore, since the driver script will only be uplaoded once.
                //_clientSendingThread = new Thread(ClientSendingMethod);
                //_clientSendingThread.IsBackground = true;
                //_clientSendingThread.Start();

                _clientReceivingThread = new Thread(ClientReceivingMethod);
                _clientReceivingThread.IsBackground = true;
                _clientReceivingThread.Start();

                if (!Net.Net.GetLocalIPAddressInNetwork(_robotIP, "255.255.255.0", out _serverIP))
                {
                    throw new Exception("ERROR: Could not figure out local IP");
                }
                logger.Debug("Machina local IP: " + _serverIP);

                _serverSocket = new TcpListener(IPAddress.Parse(_serverIP), _serverPort);
                _serverSocket.Start();

                _isServerListeningRunning           = true;
                _serverListeningThread              = new Thread(ServerReceivingMethod);
                _serverListeningThread.IsBackground = true;
                _serverListeningThread.Start();

                string drScript = LoadDriverScript();
                if (!UploadScriptToDevice(drScript, false))
                {
                    logger.Error("Could not upload driver to robot");
                    Disconnect();
                    return(false);
                }

                if (!WaitForInitialization())
                {
                    logger.Error("Timeout when waiting for initialization data from the controller");
                    Disconnect();
                    return(false);
                }

                return(_clientSocket.Connected);
            }
            catch (Exception ex)
            {
                logger.Error("Something went wrong trying to connect to robot...");
                logger.Debug(ex);
                Disconnect();
                return(false);
            }

            //return false;
        }