Jump to content

Detecting if CD-tray is shut.


Recommended Posts

Hi,

see topic-name, is it possible? :whistle:

I use DirveStatus to detect if a tray has a disc or not, and CDTray to eject when it doesn't. However, this gives problems when the event occurs and the CDTray is just closing or is already open.

So can I detect if a cd-tray is shut, even when no disc is inserted?

Tnx in advance,

Link to comment
Share on other sites

Hi,

see topic-name, is it possible? :whistle:

I use DirveStatus to detect if a tray has a disc or not, and CDTray to eject when it doesn't. However, this gives problems when the event occurs and the CDTray is just closing or is already open.

So can I detect if a cd-tray is shut, even when no disc is inserted?

Tnx in advance,

<{POST_SNAPBACK}>

This should help... used first

CDTray ( "drive", "close" )

sleep(5000)

?????

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Got me on that one. The drive close script adds time, and with folks at my work, they might have left thier coffee in the cupholder there. :whistle:

I think there is a drive status DLL call if nothing else, I will take a look if no one finds it first.

You are saying the built in version of drivestatus doesn't meet your needs, correct?

DriveStatus

--------------------------------------------------------------------------------

Returns the status of the drive as a string.

DriveStatus ( "path" )

Parameters

path Path of drive to receive information from.

Return Value

Return Value Interpretation

UNKNOWN Drive may be unformatted (RAW).

READY Typical of hard drives and drives that contain removable media.

NOTREADY Typical of floppy and CD drives that do not contain media.

INVALID May indicate the drive letter does not exist or that a mapped network drive is inaccessible.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Actually I found nothing too in msdn and it seems that not even windows can support that.... But I came up with that code.It might be useful.....

$timer=TimerInit()
while TimerDiff($Timer)<150

CDTray("F:","CLOSE")

WEnd
if DriveStatus("F:")="NOTREADY" Then 
    msgbox(0,"","Cd is now closed and with no CD inserted")
Else
    msgbox(0,"","Cd is now closed and with CD inserted")
EndIf

I timed my cdrom and saw that if the cdtray is already closed the CDTray("F:","CLOSE") close command needs around 100ms to execute.... if it is in another state then it needs above 6500ms...So if the drive is already closed the it will notify right away that it is closed,otherwise it will remain in the loop until it is closed even if no media is inserted....

I'm sorry but i couldnt come up with something better.....

Edited by hgeras
Link to comment
Share on other sites

So there's absolutely no way to check this?

I wouldn't say that, I just couldn't find a program, dll, or any windows call or signal myself.

The closest ones are basically the same as posted, check drive, send a close signal, and check again.

edit.. thought about posting a few other scripts in vb, dll calls, and some hardware checks, but they all did the same thing hgeras' code did pretty much, so I removed it.

:whistle:

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

So there's absolutely no way to check this?

<{POST_SNAPBACK}>

I'm pretty certain that you can check for this using MCI, but I believe that you are limited to checking only the first CD drive in the system and I'm not aware of any way to make MCI calls and receive their results with AutoIt.

Edit: my old MCI documentation confirms that this is indeed possible.

Edited by LxP
Link to comment
Share on other sites

Thanks all again.

@hgeras: thought about that, but I want to use this on both a laptop and desktop. On a laptop you can't close the drive. Also, the time differs from drive to drive. :dance:

@scriptkitty: ditto :whistle:

@LxP: the latest bèta of AutoIT is able to process MCI-commands, so could you post that documentation please? :dance:

Link to comment
Share on other sites

Nanaki:

The While statement doesnt have to do with the cdrom time but how long it takes autoit to process the command .In my computer(A64 3000+) needs 95-105 ms. In a slower a computer might need a little longer thats why i used 150 ms .... In a laptop tends to return 0 but thats not much of a problem since you can alter\enrich the code for that case too and make it wait for someone to close it with timeout function too (e.g 5sex err...secs I meant :whistle: )or you might add it as an option e.g (checkbox)Laptop computer? , and alter tge code accordingly for that case....That's all from my point of view given the fact that if MCI documentation is inadequate then the use of its code would be hell....

LxP: I'd like that code posted too....(You did that just before posting ....)

EDIT:

I checked the documentation and i couldnt find anything useful for your case Nanaki...

BTW where is the MCI processing documentation in autoit?

Edited by hgeras
Link to comment
Share on other sites

Just for the record, I think you'll want a command like status cdaudio mode which will potentially return open or other things. See Contents > Audio CD Commands > status for more info.

Edit: this message is in relation to MCI commands and refers to the help file posted above.

Edited by LxP
Link to comment
Share on other sites

Indeed, the documentation states it can report "open".

http://www.autoitscript.com/forum/index.php?showtopic=10534

Here's some mention of MCI, I'll try asking in another forum.

edit= another one: http://www.autoitscript.com/forum/index.ph...wtopic=8760&hl=

Looks like mciSendString("status cdaudio mode") should do it. Now I don't really know how to edit "device_id" to work on multiple drives, so I'm looking into that. :whistle:

edit2= does anyone know how to specify your own drive?

Edited by Nanaki
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...