Disconnect() public method

Disconnect from SRV-1 Blackfin robot.

The method disconnects from SRV-1 robot making all other methods unavailable (except Connect method). In the case if user obtained instance of camera using GetCamera method, the video will be stopped automatically (and those SRV1Camera instances should be discarded).

public Disconnect ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Disconnect from SVS device.
        /// </summary>
        ///
        /// <remarks><para>The method disconnects from SVS board making all other methods
        /// unavailable (except <see cref="Connect"/> method). In the case if user
        /// obtained instance of left or right camera using <see cref="GetCamera"/>
        /// method, the video will be stopped automatically (and those <see cref="SRV1Camera"/>
        /// instances should be discarded).
        /// </para></remarks>
        ///
        public void Disconnect()
        {
            lock (sync1)
            {
                lock (sync2)
                {
                    hostAddress = null;

                    // signal cameras to stop
                    if (leftCamera != null)
                    {
                        leftCamera.SignalToStop();
                    }
                    if (rightCamera != null)
                    {
                        rightCamera.SignalToStop();
                    }

                    // wait until cameras stop or abort them
                    if (leftCamera != null)
                    {
                        // wait for aroung 250 ms
                        for (var i = 0; (i < 5) && (leftCamera.IsRunning); i++)
                        {
                            System.Threading.Thread.Sleep(50);
                        }
                        // abort camera if it can not be stopped
                        if (leftCamera.IsRunning)
                        {
                            leftCamera.Stop();
                        }
                        leftCamera = null;
                    }
                    if (rightCamera != null)
                    {
                        // wait for aroung 250 ms
                        for (var i = 0; (i < 5) && (rightCamera.IsRunning); i++)
                        {
                            System.Threading.Thread.Sleep(50);
                        }
                        // abort camera if it can not be stopped
                        if (rightCamera.IsRunning)
                        {
                            rightCamera.Stop();
                        }
                        rightCamera = null;
                    }

                    if (communicator1 != null)
                    {
                        communicator1.Disconnect();
                        communicator1 = null;
                    }
                    if (communicator2 != null)
                    {
                        communicator2.Disconnect();
                        communicator2 = null;
                    }
                }
            }
        }