Check that CD is spun up ?

Check that CD is spun up ?

Hi All,

A colleague is currently writing a fairly large console app. that reads in data from CD and processes it into a GIS format. Depending on user input, the application will ask for the insertion of up to 4 CDs over the execution of the program.

The problem is that it always takes while from when you insert a CD to when it is readable. This is causing problems as the application will ask you to insert a CD. The user will insert the CD then press ENTER to continue. The application will immediately try to read the required file, but if the CD hasn't spun up, you get a "Device not ready" error.

Is there anyway from within CVF that you can check "IsCDMounted" ? Or similar. I did think of just trying to read the necessary file and keep looping around until it is readable, but that feels like a cludge.

I know you could just add a 10 second delay between when the user presses ENTER and when it trys to read the CD, but if the CD was 'mounted' in 3 seconds, that is just a waste, and it feels cludgy as well.

Any ideas.



3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Sounds more like a driver issue, in general I would expect the read to hang until the disk spun up. Either that or reprompt you to insert the CD. Retrying internally is a reasonable solution in this case.


Maybe FindFirstChangeNotification API could solve the problem. It raises an event when anything in given directory changes. I'm not sure if it's applicable in the case in question but it's simple enough to give it a try:

WRITE(*,*) "Please insert next CD"
hEvent = FindFirstChangeNotification("E:"C, .FALSE., FILE_NOTIFY_CHANGE_SIZE)
iSt = WaitForSingleObject(hEvent)
iSt = FindCloseChangeNotification(hEvent)

Maybe WaitForSingleObject should be applied twice (once CD is removed and once it's inserted). I used it when monitoring changes of "ordinary" directories -- I don't know how it would behave for removable drives.



Leave a Comment

Please sign in to add a comment. Not a member? Join today