示例#1
0
        void ShutdownInternalService()
        {
            if (_queue != null)
            {
                if (_streamPort != null)
                {
                    _streamPort.Post(new Shutdown());
                    _streamPort = null;
                }

                ResourceManagerPort.Post(new FreeExecutionResource(_queue));
                _queue = null;
            }
        }
示例#2
0
 void DropHandler(DsspDefaultDrop drop)
 {
     try
     {
         if (_link != null)
         {
             // release dispatcher queue resource
             ResourceManagerPort.Post(new FreeExecutionResource(_link.TaskQueue));
             _link.Close();
             _link = null;
         }
     }
     finally
     {
         base.DefaultDropHandler(drop);
     }
 }
示例#3
0
        Choice InitializeInternalService()
        {
            AllocateExecutionResource allocExecRes = new AllocateExecutionResource(0, "Srv1Camera");

            ResourceManagerPort.Post(allocExecRes);

            return(Arbiter.Choice(
                       allocExecRes.Result,
                       delegate(ExecutionAllocationResult result)
            {
                _queue = result.TaskQueue;
            },
                       delegate(Exception e)
            {
                LogError(e);
            }
                       ));
        }
示例#4
0
        Choice InitializeInternalService()
        {
            AllocateExecutionResource allocExecRes = new AllocateExecutionResource(
                true,
                1,
                "WebCamResourceGroup",
                ServiceInfo.Service
                );

            ResourceManagerPort.Post(allocExecRes);

            return(Arbiter.Choice(
                       allocExecRes.Result,
                       delegate(ExecutionAllocationResult result)
            {
                _queue = result.TaskQueue;
            },
                       delegate(Exception e)
            {
                LogError(e);
            }
                       ));
        }
示例#5
0
        void DropHandler(DsspDefaultDrop drop)
        {
            Tracer.Trace("TrackRoamerBrickProximityBoardService::DropHandler()");

            _state.LinkState   = "Dropping service - Closing link to Proximity Board";
            _state.IsConnected = false;

            try
            {
                if (_pbCommander != null)
                {
                    // release dispatcher queue resource
                    ResourceManagerPort.Post(new FreeExecutionResource(_pbCommander.TaskQueue));
                    _pbCommander.Close();
                    _pbCommander       = null;
                    _state.IsConnected = false;
                }
            }
            finally
            {
                base.DefaultDropHandler(drop);
            }
        }
示例#6
0
        /// <summary>
        /// Start conversation with the SickLRF device.
        /// </summary>
        IEnumerator <ITask> StartLRF(int timeout, int comPort)
        {
            Tracer.Trace("SickLRF::StartLRF() comPort=" + comPort);

            if (timeout > 0)
            {
                //
                // caller asked us to wait <timeout> milliseconds until we start.
                //

                yield return(Arbiter.Receive(false, TimeoutPort(timeout),
                                             delegate(DateTime dt)
                {
                    LogInfo("Done Waiting");
                }
                                             ));
            }

            if (_queue == null)
            {
                //
                // The internal services run on their own dispatcher, we need to create that (once)
                //

                AllocateExecutionResource allocExecRes = new AllocateExecutionResource(0, "SickLRF");

                ResourceManagerPort.Post(allocExecRes);

                yield return(Arbiter.Choice(
                                 allocExecRes.Result,
                                 delegate(ExecutionAllocationResult result)
                {
                    _queue = result.TaskQueue;
                },
                                 delegate(Exception e)
                {
                    LogError(e);
                }
                                 ));
            }

            string comName;

            if (comPort <= 0)
            {
                //
                // We default to COM4, because
                // a) that was our previous behavior and
                // b) the hardware that we have uses COM4
                //
                comName = "COM4";
            }
            else
            {
                comName = "COM" + comPort;
            }

            _link         = new CommLink(_queue ?? TaskQueue, comName, _internalPort);
            _link.Parent  = ServiceInfo.Service;
            _link.Console = ConsoleOutputPort;

            FlushPortSet(_internalPort);
            yield return(
                Arbiter.Choice(
                    _link.Open(),
                    delegate(SuccessResult success)
            {
                LogInfo("Opened link to LRF");
            },
                    delegate(Exception exception)
            {
                LogError(exception);
            }
                    )
                );
        }
示例#7
0
        /// <summary>
        /// Start conversation with the TrackRoamer Proximity Board device.
        /// </summary>
        IEnumerator <ITask> StartProximityBoard(int timeout)
        {
            Tracer.Trace(string.Format("TrackRoamerBrickProximityBoardService::StartProximityBoard() timeout={0} ms", timeout));

            _state.LinkState = "Initializing";

            if (timeout > 0)
            {
                //
                // caller asked us to wait <timeout> milliseconds until we start.
                //

                yield return(Arbiter.Receive(false, TimeoutPort(timeout),
                                             delegate(DateTime dt)
                {
                    LogInfo(string.Format("StartProximityBoard() - Done Waiting {0} ms", timeout));
                }
                                             ));
            }

            if (_pbCommanderTaskQueue == null)
            {
                //
                // The internal services run on their own dispatcher, we need to create that (once)
                //

                AllocateExecutionResource allocExecRes = new AllocateExecutionResource(0, "TrackRoamerProximityBoard");

                ResourceManagerPort.Post(allocExecRes);

                yield return(Arbiter.Choice(
                                 allocExecRes.Result,
                                 delegate(ExecutionAllocationResult result)
                {
                    _pbCommanderTaskQueue = result.TaskQueue;
                },
                                 delegate(Exception e)
                {
                    LogError(e);
                }
                                 ));
            }

            _pbCommander         = new ProximityBoardCcrServiceCommander(_pbCommanderTaskQueue ?? TaskQueue, _pbCommanderDataEventsPort, _state.VendorId, _state.ProductId);
            _pbCommander.Parent  = ServiceInfo.Service;
            _pbCommander.Console = ConsoleOutputPort;
            _state.IsConnected   = false;

            // Open is an empty operatiion, but we need to flush the internal queue - so let it be.

            FlushPortSet(_pbCommanderDataEventsPort);

            bool failed = false;

            yield return(
                Arbiter.Choice(
                    _pbCommander.Open(),
                    delegate(SuccessResult success)
            {
                _state.LinkState = "Initializing - link opened";

                LogInfo("Opened link to Proximity Board");
            },
                    delegate(Exception exception)
            {
                _state.LinkState = "Error Initializing - could not open link";

                failed = true;
                LogError(exception);
            }
                    )
                );

            if (failed)
            {
                yield break;
            }

            //
            // Set the servo sweep rate:
            //

            yield return(
                Arbiter.Choice(
                    _pbCommander.SetServoSweepRate(),
                    delegate(SuccessResult success)
            {
                _state.LinkState = "Servo Sweep Rate Set";
                LogInfo(_state.LinkState);
            },
                    delegate(Exception exception)
            {
                _state.LinkState = "Error Initializing - could not set Servo Sweep Rate";
                failed = true;
                LogError(exception);
            }
                    )
                );

            if (failed)
            {
                yield break;
            }

            //
            // start continuous measurements.
            //

            yield return(
                Arbiter.Choice(
                    _pbCommander.SetContinuous(),
                    delegate(SuccessResult success)
            {
                _state.LinkState = "Started Continuous Measurement";
                _state.IsConnected = true;
                LogInfo(_state.LinkState);
            },
                    delegate(Exception failure)
            {
                _state.LinkState = "Error Initializing - could not start Continuous Measurement";
                _pbCommanderDataEventsPort.Post(failure);
                failed = true;
            }
                    )
                );

            if (failed)
            {
                yield break;
            }

            // somehow the board skips commands on startup, send it twice after a wait:

            yield return(Arbiter.Receive(false, TimeoutPort(1000),
                                         delegate(DateTime dt)
            {
            }
                                         ));

            //
            // start continuous measurements - try 2.
            //

            yield return(
                Arbiter.Choice(
                    _pbCommander.SetContinuous(),
                    delegate(SuccessResult success)
            {
                _state.LinkState = "Started Continuous Measurement";
                _state.IsConnected = true;
                LogInfo(_state.LinkState);
            },
                    delegate(Exception failure)
            {
                _state.LinkState = "Error Initializing - could not start Continuous Measurement";
                _pbCommanderDataEventsPort.Post(failure);
                failed = true;
            }
                    )
                );

            if (failed)
            {
                yield break;
            }
        }