Exemple #1
0
        /// <summary>
        /// Creates and configures the sockets by setting the ports, address and Event Handlers
        /// </summary>
        protected void ConfigureSockets()
        {
            //this.FormClosing += new FormClosingEventHandler(VisionForm_FormClosing);
            //PortIn = 2070;
            //PortOut = 2300;

            if ((tcpServer != null) && (tcpServer.Started))
            {
                tcpServer.Stop();
            }
            tcpServer                     = new SocketTcpServer(portIn);
            tcpServer.BufferSize          = DEFAULT_BUFFER_SIZE;
            tcpServer.DataReceived       += new TcpDataReceivedEventHandler(socketTCPIn_DataReceived);
            tcpServer.ClientConnected    += new TcpClientConnectedEventHandler(socketTCPIn_ClientConnected);
            tcpServer.ClientDisconnected += new TcpClientDisconnectedEventHandler(socketTCPIn_ClientDisconnected);

            if ((tcpClient != null) && (tcpClient.IsConnected))
            {
                tcpClient.Disconnect();
            }
            if (portIn != portOut)
            {
                tcpClient            = new SocketTcpClient(remoteServerAddress, portOut);
                tcpClient.BufferSize = DEFAULT_BUFFER_SIZE;

                tcpClient.Connected    += new TcpClientConnectedEventHandler(socketTCPOut_Connected);
                tcpClient.DataReceived += new TcpDataReceivedEventHandler(socketTCPOut_DataReceived);
                tcpClient.Disconnected += new TcpClientDisconnectedEventHandler(socketTCPOut_Disconnected);
            }

            //mainThread.Start();
        }
        /// <summary>
        /// Performs Restart Tasks
        /// </summary>
        private void DoRestartModule()
        {
            Busy = true;

            Unlock();
            dataReceived.Clear();
            if ((server != null) && server.Started)
            {
                try { server.Stop(); }
                catch { }
            }
            ExecuteRestartActions();
            Busy = false;
        }
        public void Run()
        {
            /*
             * Se inicia el SocketTcpServer.
             */
            server.Start();

            // Espero a que conecte
            while (server.ClientsConnected == 0)
            {
                Thread.Sleep(10);
            }

            //Inicia timer
            sw.Start();

            /*
             * Se crea la variable mediante
             * create_var "variable|0"
             */
            server.SendToAll("create_var \"odometryPos|0\"");

            /*
             * Realizo la suscripcion. Para el ejemplo no me interesa verificar lo
             * que responde el Blackboard, pero todo llega a
             *	server_DataReceived(...)
             * incluso la basura, y se imprime en pantalla.
             *
             * Nota que hay un error y dice "suscribe" en lugar de "subscribe".
             * Esto cambiara en la siguiente version, por lo que puedes programar
             * con "subscribe".
             */
            server.SendToAll("suscribe_var \"localizerPos suscribe=writeany report=content\"");

            /*
             * La suscripcion es para la variable 'variable'
             * reportando cuando cualquier modulo escriba y reportando todo
             * el contenido de la variable.
             *
             * Ahora realizo 100 escrituras a intervalo de 100ms aprox.
             * Se reporta el tiempo de demora.
             */
            for (int i = 0; i < 100000; ++i)
            {
                // Se obtiene el valor a escribir en la variable en hex string
                byte[] iData = BitConverter.GetBytes(i);
                string sData = String.Empty;
                for (int j = 0; j < iData.Length; ++j)
                {
                    sData += iData[j].ToString("X2");
                }

                server.SendToAll("write_var \"odometryPos|0x" + sData + "\"");
                Thread.Sleep(100);
            }

            server.Stop();
            sw.Stop();
        }
Exemple #4
0
        private void btnServerStart_Click(object sender, EventArgs e)
        {
            if (!server.Started)
            {
                try
                {
                    int port;

                    if (!Int32.TryParse(txtServerPort.Text, out port))
                    {
                        MessageBox.Show("Invalid port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    server.Port = port;
                    server.Start();
                }
                catch
                {
                    return;
                }
                txtServerPort.AutoCompleteCustomSource.Add(txtServerPort.Text);
                btnServerStart.Text      = "Stop";
                txtServerPort.Enabled    = false;
                txtServerInput.Enabled   = true;
                txtServerConsole.Enabled = true;
                btnServerSend.Enabled    = true;
            }
            else
            {
                try
                {
                    server.Stop();
                }
                catch
                {
                    return;
                }
                btnServerStart.Text      = "Start";
                txtServerPort.Enabled    = true;
                txtServerInput.Enabled   = false;
                txtServerConsole.Enabled = false;
                btnServerSend.Enabled    = false;
            }
        }