View my account

Camera connection and disconnection / C#

Comments

9 comments

  • MartyG

    It is possible to detect camera unplug (detach) and plug-in (attach) events.  I only know of versions of the code for C++ and Python though.

    C++

    https://github.com/IntelRealSense/librealsense/issues/931 

    Python

    https://github.com/IntelRealSense/librealsense/issues/4212 

     

    In both cases it involves a function called set_devices_changed_callback

    0
    Comment actions Permalink
  • Thomas Chenus33

    Thx Marty! I tried to translate to C#, but I can't call the same function as in cpp or python in C#.

    Cpp exemple :

    C# exemple : 

    On this exemple you can show I can't found the fonction "Get_active_profile().get_device();" I only found "pp.Device", but I dont think it's the same. 

    And what is ctx on cpp code?? Before the set_devices_changed_callback

    I can't find any examples of how to do that.

    0
    Comment actions Permalink
  • MartyG

    Apologies for the delay in responding further, as I was researching this case.  I could not find any C# examples of use of set_devices_changed_callback either.  Though I found C# scripts that check for whether a device can be found.  It should be applicable to any camera supported by RealSense SDK 2.0, as it is just checking for whether the device list is empty.

    https://github.com/IntelRealSense/librealsense/issues/6166 

    0
    Comment actions Permalink
  • Thomas Chenus33

    No problem, for me it was the end of the day. I tried just now and actually I'm able to retrieve the device in question. But I can't get the information from this one. My goal would be to record it, to be able to reconnect it automatically when I plug it back in. 

    Here I just get the device, to access the sensor, that's how I change the values of my IR sensor for example in my application. But I can't find any info on the USB connection...

    0
    Comment actions Permalink
  • MartyG

    My thoughts when offering the code was that if you checked the device list continuously then when the list = 0 then that is registered as being a disconnection, and if the device list = 1 then it is connected.

    0
    Comment actions Permalink
  • Thomas Chenus33

    Yes, that would work. But when I plug the camera back in, I can't retrieve the login information.But I'll already work with that, if I have to do a new init of my camera in a try catch. Thank you !

    0
    Comment actions Permalink
  • Thomas Chenus33

    Hello Marty.

    I need now to be able to connect several cameras on a single application. To do this I would need the connection information of the cameras I gess, so that I can then launch a thread per camera.

    I think it's similar to the disconnection and reconnection of the camera while the program is running. But I hadn't succeeded, for lack of example in C#, which is the language I use. 

    I found this perfect C++ exemple at the last of this topic : https://forums.intel.com/s/question/0D70P0000069uDhSAI/d435-streams-work-once-then-crash

    But I don't succed to translate it into C# and use the function that are used in the example. May be some one already do something like that in c# ?

    Please let me know if you need any other information, and thanks in advance!

    0
    Comment actions Permalink
  • MartyG

    There is a C# script here for creating a pipeline for each camera:

    https://github.com/IntelRealSense/librealsense/issues/3432#issuecomment-472570380

    0
    Comment actions Permalink
  • Thomas Chenus33

    Ok thank you so much

    0
    Comment actions Permalink

Please sign in to leave a comment.