Device not ready

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 2644 Views - Last Post: 26 November 2012 - 05:03 PM Rate Topic: -----

#1 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Device not ready

Posted 11 November 2012 - 12:00 PM

Hello.

I'm trying to list through all the logical drives in the computer using this code:

for (int i = 0; i < 26; i++)
	{
		if ((GetLogicalDrives() & ( 1 << i )))
		{
			CHAR driveName[MAX_PATH] = {TEXT('A') + i, TEXT(':'), TEXT('\\'), TEXT('\0')};
			std::cout << driveName << std::endl;
		}
	}



It works, but when I try to access the A:\ drive, which in my computer stands for the floppy disk, it displays me an error saying "Device not ready".

try
{
	std::cout << GetFileAttributes(driveName) << std::endl;
}
catch (const std::string& ex)
{
}



Is there any way to check if a logical drive is ready before doing something with it?
Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Device not ready

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,209
  • Joined: 02-June 10

Re: Device not ready

Posted 11 November 2012 - 01:49 PM

Is there a disc in the floppy drive? If there isn't then its not ready.

ANd I believe you just found how to check if its ready or not: It told you its not ready.

Doesn't C++ have a try/catch construct so when you get the error you won't crash and can use that error as notification that the drive isn't ready?
Was This Post Helpful? 1
  • +
  • -

#3 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 11 November 2012 - 02:39 PM

There isn't a disc in the floppy drive, and that's the point: there isn't anything in it so there's no point in using it, that's why I want to check whether it is ready or not.
And if you look at my last code, I included a try-catch block to try and trap the error but it still pops up the error message saying "Device is not ready". Unless I'm doing anything wrong?
Was This Post Helpful? 0
  • +
  • -

#4 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 12 November 2012 - 02:18 PM

I don't know if it's too early to do this, but BUMP?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Device not ready

Posted 12 November 2012 - 02:33 PM

Yes, it is too early!

What's the full code, including the exception catch?
Was This Post Helpful? 1
  • +
  • -

#6 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 12 November 2012 - 03:06 PM

Oh I'm sorry, I'm not used to how things work here :(

for (int i = 0; i < 26; i++)
	{
		if ((GetLogicalDrives() & ( 1 << i )))
		{
			CHAR driveName[MAX_PATH] = {TEXT('A') + i, TEXT(':'), TEXT('\\'), TEXT('\0')};
			std::cout << driveName << std::endl;

			try
			{
				std::cout << GetFileAttributes(driveName) << std::endl; //exception here
			}
			catch (const std::string& ex)
			{
			}
		}
	}


Was This Post Helpful? 0
  • +
  • -

#7 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 15 November 2012 - 02:08 PM

Bump?
Was This Post Helpful? 0
  • +
  • -

#8 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Device not ready

Posted 15 November 2012 - 02:20 PM

View PosttlhIn`toq, on 11 November 2012 - 01:49 PM, said:

Is there a disc in the floppy drive? If there isn't then its not ready.

ANd I believe you just found how to check if its ready or not: It told you its not ready.

Doesn't C++ have a try/catch construct so when you get the error you won't crash and can use that error as notification that the drive isn't ready?


Reread this, because I don't think you've got it understood yet.

The device is not ready, and it won't BE ready, until it has a floppy disk in it and THEN you run your program.

Don't mistake the "device not ready", with the device not being present. If the floppy drive is listed in the BIOS, then the OS should also have it listed, and it is always "ready" (in your meaning of the term), whenever you want to put a disk in it.

This post has been edited by Adak: 15 November 2012 - 02:21 PM

Was This Post Helpful? 1
  • +
  • -

#9 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: Device not ready

Posted 15 November 2012 - 02:26 PM

This might help

GetDriveType function (Windows)

stuck with api getdrivetype
Was This Post Helpful? 1
  • +
  • -

#10 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 15 November 2012 - 02:55 PM

Hello, thanks for the answers, Adak and #define.

To Adak:
I reread it, and let me rephrase my problem again:
I am building a program that lists through all the logical drives in the computer and displays info about them. By no means I want to have access to the floppy drive A:\, but it shows up on the list, so I want to know if there's a way to check whether the drive A:\ is ready or not, as in whether it will display an error and stop my program or not. Here's a link of the error I get, regardless whether I put the code between a try-catch block or not.
English is not my native language, so my windows installation is not in English, but what that message says is: "The device is not ready to be used (...)"

To #define:
I looked it up on MSDN and used that function with all the drives listed, but unfortunately it doesn't give me any info that could be made of use, being DRIVE_REMOVABLE the only thing it does give me for drive A:\


Thank you.

This post has been edited by chipicau: 15 November 2012 - 02:55 PM

Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3663
  • View blog
  • Posts: 11,482
  • Joined: 05-May 12

Re: Device not ready

Posted 15 November 2012 - 04:03 PM

Your use of GetFileAttributes() doesn't really tell you much more about the drive. It seems to me, using GetDriveType()'s returned values are more informative.
Was This Post Helpful? 1
  • +
  • -

#12 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Device not ready

Posted 15 November 2012 - 04:06 PM

Floppy drives weren't made that way - it's an older design. If the drive is listed, it IS "ready" (by your definition, but not by it's definition of ready)- just put in a disk to use it.

Otherwise, it throws the "Device not Ready", error. There is no state that you are looking for, where the device is ready, but has no disk in it.

You can stop looking for it - it doesn't exist.
Was This Post Helpful? 1
  • +
  • -

#13 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3663
  • View blog
  • Posts: 11,482
  • Joined: 05-May 12

Re: Device not ready

Posted 15 November 2012 - 05:50 PM

Unfortunately, if you look closely at his code in the OP, GetLogicalDrives() is returning the A: drive as existing. And hence the problem he is encountering when he is trying to get more details about the drive.
Was This Post Helpful? 1
  • +
  • -

#14 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Device not ready

Posted 15 November 2012 - 06:19 PM

Hi,

I would use Win32_LogicalDisk class for this ...

see msdn....

specifically you need to check for MediaType.

There are a lot of enums so be prepared for long lists... :)

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#15 chipicau  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 15-May 12

Re: Device not ready

Posted 17 November 2012 - 04:47 AM

Thank you all for your answers.

@Skydiver:
For now, I only want to know which drives won't give me an error message when I try to access them, regardless of the method I use to do it.
And you are right, the A:\ drive shows up in the list, and like I said, by no means I intend to use it, but it shows up, what can I do, besides try to trap the error message?

@Adak:
I get it, but I don't want to use the drive A:\, I just want to display some info for every available drive in the computer. It's not my fault that drive A:\ shows up. I just have to deal with it.

@snoopy11:
Perhaps could you give me an example? I'm not too familiar with WMI.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2