void StartTimer(DateTime signal)
 {
     //_camPort = ServiceForwarder<cam.WebCamOperations>(FindPartner("WebCam").Service);
     LogInfo(LogGroups.Console, "Subscribe to webcam");
     Activate(
         Arbiter.Choice(
             _camPort.Subscribe(_camNotify),
             OnSubscribed,
             OnSubscribeFailed
             )
         );
 }
Esempio n. 2
0
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new ColorSegmentState();
            }
            else
            {
                for (int set = 0; set < _state.Colors.Count; set++)
                {
                    ColorSet colorSet = _state.Colors[set];

                    for (int index = 0; index < colorSet.Colors.Count; index++)
                    {
                        ColorDefinition color = colorSet.Colors[index];
                        if (!color.Validate())
                        {
                            colorSet.Colors.RemoveAt(index);
                            index--;
                        }
                    }

                    if (colorSet.Colors.Count == 0)
                    {
                        _state.Colors.RemoveAt(set);
                        set--;
                    }
                }
                _state.UpdateColorSetMap();
                _state.ImageSource     = null;
                _state.Processing      = false;
                _state.FrameCount      = 0;
                _state.DroppedFrames   = 0;
                _state.FoundColorAreas = null;
            }

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            _fwdPort = ServiceForwarder <ColorSegmentOperations>(ServiceInfo.Service);

            base.Start();

            Activate <ITask>(
                Arbiter.Receive <webcam.UpdateFrame>(true, _webcamNotify, OnWebcamUpdateFrame)
                );
            _webcamPort.Subscribe(_webcamNotify, typeof(webcam.UpdateFrame));
        }
Esempio n. 3
0
        IEnumerator<ITask> OnConnectWebCamHandler(OnConnectWebCam Opt)
        {
            Fault fault = null;
            SubscribeResponseType s;
            String camera = Opt.Service;

            _webCamPort = ServiceForwarder<cam.WebCamOperations>(camera);


            //cam.Subscribe subscribe = new cam.Subscribe();
            //subscribe.NotificationPort = _webCamNotify;


            yield return Arbiter.Choice(
                _webCamPort.Subscribe(_webCamNotify),
                //                subscribe.ResponsePort,
                delegate(SubscribeResponseType success)
                { s = success; },
                delegate(Fault f)
                {
                    fault = f;
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }
        }       
Esempio n. 4
0
        // TT - New handler for connecting to WebCam
        IEnumerator<ITask> OnConnectWebCamHandler(OnConnectWebCam Opt)
        {
            //ServiceInfoType info = null;
            Fault fault = null;
            SubscribeResponseType s;
            String camera = Opt.Service;

            _webCamPort = ServiceForwarder<cam.WebCamOperations>(camera);

            //cam.Subscribe subscribe = new cam.Subscribe();
            //subscribe.NotificationPort = _webCamNotify;

            //_webCamPort.Post(subscribe);

            yield return Arbiter.Choice(
                _webCamPort.Subscribe(_webCamNotify),
//                subscribe.ResponsePort,
                delegate(SubscribeResponseType success)
                { s = success; },
                delegate(Fault f)
                {
                    fault = f;
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }

            RunForm runForm = new RunForm(CreateWebCamForm);

            WinFormsServicePort.Post(runForm);

            yield return Arbiter.Choice(
                runForm.pResult,
                delegate(SuccessResult success) { },
                delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to Create WebCam window", fault);
                yield break;
            }
            // The following code falls over with a null pointer
            // exception inside MainPortInterleave.CombineWith.
            // Since I don't know why, I have added the message
            // to the interleave that is created at startup.
            // This is a bit tacky, but does not seem to do any harm.
            /*
            Interleave x = Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIterator<cam.UpdateFrame>(true, _webCamNotify, CameraUpdateFrameHandler)
                    ),
                    new ConcurrentReceiverGroup()
            );

            base.MainPortInterleave.CombineWith(x);
            */

            // There is a bug in the simulated webcam. It does not
            // automatically send UpdateFrame messages when you
            // subscribe. If this is a simulated camera, then set
            // up a timer to poke the webcam service and make it
            // send a frame.
            if (camera.ToLower().Contains("simul"))
            {
                Activate(
                    Arbiter.Receive(false, TimeoutPort(_state.Options.CameraInterval), CameraTimer)
                );
            }

            yield break;

        }
Esempio n. 5
0
        IEnumerator <ITask> InitializeCamera()
        {
            ServiceInfoType info  = null;
            Fault           fault = null;

            yield return(Arbiter.Choice(
                             _blobTrackerPort.DsspDefaultLookup(),
                             delegate(LookupResponse success)
            {
                info = success;
            },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Lookup failed on BlobTracker partner", fault);
                yield break;
            }

            PartnerType camera = FindPartner(
                new XmlQualifiedName("WebCam", bt.Contract.Identifier),
                info.PartnerList
                );

            if (camera == null ||
                string.IsNullOrEmpty(camera.Service))
            {
                LogError("No camera partner found for BlobTracker");
                yield break;
            }

            _webCamPort = ServiceForwarder <cam.WebCamOperations>(camera.Service);

            yield return(Arbiter.Choice(
                             _webCamPort.Subscribe(_webCamNotify, typeof(cam.UpdateFrame)),
                             delegate(SubscribeResponseType success) { },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }

            yield return(Arbiter.Choice(
                             _blobTrackerPort.Subscribe(_blobTrackerNotify),
                             delegate(SubscribeResponseType success) { },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to blob tracker", fault);
                yield break;
            }

            RunForm runForm = new RunForm(CreateVisualization);

            WinFormsServicePort.Post(runForm);

            yield return(Arbiter.Choice(
                             runForm.pResult,
                             delegate(SuccessResult success) { },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to Create Visualization window", fault);
                yield break;
            }

            base.MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <cam.UpdateFrame>(true, _webCamNotify, CameraUpdateFrameHandler),
                        Arbiter.Receive <bt.ImageProcessed>(true, _blobTrackerNotify, BlobTrackerImageProcessedHandler),
                        Arbiter.Receive <Shutdown>(true, _shutdownPort, ShutdownHandler)
                        ),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <bt.DeleteBin>(true, _blobTrackerNotify, EmptyHandler),
                        Arbiter.Receive <bt.InsertBin>(true, _blobTrackerNotify, EmptyHandler),
                        Arbiter.Receive <bt.UpdateBin>(true, _blobTrackerNotify, EmptyHandler)
                        )
                    )
                );
        }