Testing if CD-Tray is open or closed

How can I get the status of the tray? How the one of maybe a caddy or so on?