This project is read-only.

Sample

A typical usage of MaxSMART library look like this:

 // get SmartDrive objects by enumerating \\.\PhysicalDrive* of the system.
SmartDrive[] drives = SmartDrive.EnumeratePhysicalDrives();

foreach (SmartDrive drive in drives) {
    // specific rule for your actuall system
    if ( drive.BusType == ...... ) {                        
        if ( drive.ScsiAddress.TargetId == ...... ) {
            // setting the index property of the SmartDrive object
            drive.Index = ......
            // use the correct method
            SmartMethod method = ......
            // read Serial and Model of the drive
            drive.ExecuteCommand ( method, SmartCommand.IdentifyDevice );
            Console.WriteLine( "Drive {0} Model = {1} Serial = {2}",
                drive.Name, drive.Model, drive.Serial );
            method = ......
            // read SMART attributes of the drive
            drive.ExecuteCommand ( method, SmartCommand.ReadAttributes );
            Console.WriteLine( "Drive {0} Temperate = {1}",
                drive.Name, drive.Attributes[SmartAttributes.Temperature] );
        } else if ......
    } else if .....
}

Guide

For successfully reading SMART data from your hard drives, its important for you to properly setting up this parameter:
  • SmartDrive.Index property, Type: Byte
Index usually ranges from 0 to 3, it is essentially the device index of a hard drive in an IDE interface,
0 =Primary Master, 1 = Primary Slave, 2 = Secondary Master, 3 = Secondary Slave.
and actually the significant part is setting Master or Slave correctly. Even if your hard drive is not connected to an IDE interface, maybe SATA or SCSI or SATA on an extension adaptor card using SCSI, this property may still be critical, since the operating system and drivers may be using an IDE concept under the hood, the driver maybe using this parameter to help detemine the correct device you are talking to.
actually when you construct the SmartDrive object, it will try to guess a correct Index value for you, using this logic, but it is not guranteed to work, you still need to set it up yourself.
  • method argument of SmartDrive.ExecuteCommand(method, command) method, Type: SmartMethod
    • SmartMethod.Smart: use SMART_* io control codes, MSDN
    • SmartMethod.ScsiMiniport: use IOCTL_SCSI_MINIPORT io control code, MSDN
    • SmartMethod.Storage: use IOCTL_STORAGE_* io control codes, only supports IdentifyDevice and ReadAttributes command, and Index is irrelevant for this method, MSDN
SmartMethod enumeration indicates the SmartDrive object to use the correct method for executing a command, the actual working method differ between different system configurations, some methods may fail to execute, some may return incorrect result, you must know which method to use.
To detemine the correct Index and method to use, you may need these infomation:
  • SmartDrive.HasRights property, Type: Boolean, indicates whether the drive is being accessed with admin rights or not, you may try to Run as admin on Vista/7 to see the difference.
  • SmartDrive.BusType property, Type: BusType enumeration, See MSDN: STORAGE_BUS_TYPE Enumeration
  • SmartDrive.ScsiAddress property, Type: ScsiAddress class, See MSDN: SCSI_ADDRESS Structure
You can use the included demo application GetSMART to try the combinations of Index and method, then you may see the relationship between the properties above and the parameter that generates accurate results, do remember to try to run GetSMART using Run as admin on Windows Vista or later.

Last edited Mar 29, 2011 at 1:41 AM by WalkingCat, version 9

Comments

No comments yet.