Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do D415 camera have a mechanism to detect the disconnection and connection of camera from usb. #4212

Closed
ghost opened this issue Jun 14, 2019 · 11 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2019

For the real time, i am calling get all device query in every API calls which is taking around 500ms. Do librealsense have a mechanism to detect the connection and disconnection of the D series camera from USB ?

@MartyG-RealSense
Copy link
Collaborator

The discussion linked to below may give you useful insights if you have not seen it already.

#931

@ghost
Copy link
Author

ghost commented Jun 19, 2019

def test():
print('tested')

rs.context().set_devices_changed_callback(test())

This is not working for camera connection and disconnection, test() function is only called when at the initialization of set_devices_changed_callback.

@lramati
Copy link
Contributor

lramati commented Jun 19, 2019

There are a couple errors in your python code there.
First of all, by not saving the context object, you're allowing it to be destroyed, at which point even if you had registered the callback correctly, it would not longer be listening.

Furthermore, by using set_devices_changed_callback(test()), you are feeding set_devices_changed_callback() the results of running the test() function (in this case None), not the function itself.
The correct way to handle this is:

ctx = rs.context()
ctx.set_devices_changed_callback(test) # Note test isn't called

@ghost
Copy link
Author

ghost commented Jun 19, 2019

I tried in that way but it is still not calling the test function at the time of disconnection or connection

@lramati
Copy link
Contributor

lramati commented Jun 19, 2019 via email

@ghost
Copy link
Author

ghost commented Jun 20, 2019

This is the simple code i wrote to test this callback:

rs_context = rs.context()

def test():
print('dsfds')

rs_context.set_devices_changed_callback(test)

But this connection disconnect callback is not working

Note: I am using pyrealsense2 and For connection and disconnection i mean, when i am connecting camera and disconnecting the camera from USB

@ghost
Copy link
Author

ghost commented Jun 25, 2019

Can anyone tell me what is the problem here, why callback is not working at the time of USB connection or disconnection.

Is the problem in the code ?

@RealSenseCustomerSupport
Copy link
Collaborator


Please try this code.

import pyrealsense2 as rs2
import time

current_devices = []

def on_devices_changed(info):
    global current_devices
    devs = info.get_new_devices()
    print("on_devices_changed called new_devices:", devs.size())
    for dev in devs:
        current_devices.append(dev)

    for dev in current_devices:
        print("current:", dev, " added:", info.was_added(dev), " removed:", info.was_removed(dev))

def main():
    ctx = rs2.context()
    ctx.set_devices_changed_callback(on_devices_changed)
    print("Please connect/disconnect your RealSense camera.")
    time.sleep(10)
    print("Done.")

if __name__ == '__main__':
    main()

@RealSenseCustomerSupport
Copy link
Collaborator


@itachi134999 Did you get chance to try? Looking forward to your update. Thanks!

@RealSenseCustomerSupport
Copy link
Collaborator


@itachi134999 Could You please update? Thanks!

@RealSenseCustomerSupport
Copy link
Collaborator


I think your issue has been solved.
If not, please reopen this ticket, and add more details.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants