Hexxen
Italy
Asked
— Edited
Hi
I'm having some problems stopping the webcam using the C# SDK. StopCamera() method doesn't work and camera is still active. I need to kill the iis express process to make it stop.
My current code that is not working is this: Camera.StopCamera(); Camera.OnNewFrame -= Camera_OnNewFrame; Camera.Dispose(); Camera = null; Ezb.Disconnect();
The camera works - if you're running this in iis express, then i suspect you're re-creating the camera object each time. You will need to assign the camera object to either a static variable or as an application variable.
Thank you Dj. I'm using Signalr to provide movements from phone accelerometer and receive frames from webcam.
The initialization is done when connection is established and camera is initialized once and placed in a global static variable. I'm disposing it when the connection is closed but doesn't work.
OnConnected() is the ezb event? If so, creating a new instance of Ezb will lose the instance which called the function to begin with. Then connecting a second time with the ezb to get the last port? Sorry, but that code really screwy
can you post your project and i'll take a look? Zip it and attach it here with the Upload File button
Sure here's my code: http://pastebin.com/YiDEfCDC
If you want I can send you the entire project but you will need to deploy it on a local IIS server in order to connect with a device that has accelerometer and html5 capability.
the 2 tasks OnConnected and OnDisconnect run with the websocket connection.
There's no need to dispose or null the camera or ezb object. They can live for ever since they are static - it's just harder on the CLR and it may also get confused if there's a bunch of executions of the events at the same time. In the change i made, simply initiate the objects once and let them live for ever.
Also, i'm not quite sure of the logic - but i feel it's correct with my edits. You want the camera to STOP when the EZB is disconnected. And you want the EZB to disconnect when the websocket disconnects. I added an async and await to properly use the Task declaration of the OnDisconnected() override. This is becuase the Thread.Sleep is far too dangerous to use in this instance. Specifically because the Disconnect may be overriden by another Connect while it's sleeping. I don't know if the async and await will fix that without testing, but it's better than what was there.
Also, ensure that you're not running multiple web server instance (i.e. server farm) because the static objects will only exist within their unique space. To share the object amongst other web server iis instances, store the object in an Application Variable. Set the Web.Config to use State Session Manager and start the State Session Manager service in windows. So, ensure you have only 1 web pool!
Anyway, try this...
Hi Dj
just letting you know that your code worked and this is the final result: https://www.facebook.com/alex33x/videos/10207409777592949/
Basically it's a .net webserver that receives the orientation data from any browser compatible with the javascript orientation api. The data is sent to the webserver via websocket. Then the server moves the servos and get the image from the connected webcam and sends it back to the browser
That's fantastic! What a brilliant idea