Getting Temperature form HDD via SMART?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lglmi
    New Member
    • Sep 2005
    • 1

    Getting Temperature form HDD via SMART?

    '[FONT=Arial][SIZE=1]*************** *****START OF BAS MODULE********* ***********

    Option Explicit

    Private Type OSVERSIONINFO
    dwOSVersionInfo Size As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    End Type
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersion ExA" (LpVersionInfor mation As OSVERSIONINFO) As Long

    Private Type ATTR_DATA
    AttrID As Byte
    AttrName As String
    AttrValue As Byte
    ThresholdValue As Byte
    WorstValue As Byte
    StatusFlags As STATUS_FLAGS
    End Type

    Public Type DRIVE_INFO
    bDriveType As Byte
    SerialNumber As String
    Model As String
    FirmWare As String
    Cilinders As Long
    Heads As Long
    SecPerTrack As Long
    BytesPerSector As Long
    BytesperTrack As Long
    NumAttributes As Byte
    Attributes() As ATTR_DATA
    End Type

    Public Enum IDE_DRIVE_NUMBE R
    PRIMARY_MASTER
    PRIMARY_SLAVE
    SECONDARY_MASTE R
    SECONDARY_SLAVE
    End Enum

    Private Declare Function CreateFile _
    Lib "kernel32" Alias "CreateFile A" _
    (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, ByVal lpSecurityAttri butes As Long, _
    ByVal dwCreationDispo sition As Long, _
    ByVal dwFlagsAndAttri butes As Long, _
    ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle _
    Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function DeviceIoControl _
    Lib "kernel32" (ByVal hDevice As Long, _
    ByVal dwIoControlCode As Long, _
    lpInBuffer As Any, _
    ByVal nInBufferSize As Long, _
    lpOutBuffer As Any, _
    ByVal nOutBufferSize As Long, _
    lpBytesReturned As Long, _
    ByVal lpOverlapped As Long) As Long
    Public Declare Sub CopyMemory _
    Lib "kernel32" _
    Alias "RtlMoveMem ory" (Destination As Any, _
    Source As Any, ByVal Length As Long)

    Private Const GENERIC_READ = &H80000000
    Private Const GENERIC_WRITE = &H40000000

    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRIT E = &H2
    Private Const OPEN_EXISTING = 3
    Private Const FILE_ATTRIBUTE_ SYSTEM = &H4
    Private Const CREATE_NEW = 1

    Private Const INVALID_HANDLE_ VALUE = -1
    Dim di As DRIVE_INFO

    Public Const MAX_IDE_DRIVES = 4
    ' // Max number of drives assuming primary/secondary, master/slavetopology
    Public Const READ_ATTRIBUTE_ BUFFER_SIZE = 512
    Public Const IDENTIFY_BUFFER _SIZE = 512
    Public Const READ_THRESHOLD_ BUFFER_SIZE = 512
    Public Const OUTPUT_DATA_SIZ E = IDENTIFY_BUFFER _SIZE + 16

    'IOCTL commands
    Public Const DFP_GET_VERSION = &H74080
    Public Const DFP_SEND_DRIVE_ COMMAND = &H7C084
    Public Const DFP_RECEIVE_DRI VE_DATA = &H7C088

    '---------------------------------------------------------------------
    ' GETVERSIONOUTPA RAMS contains the data returned from the
    ' Get Driver Version function.
    '---------------------------------------------------------------------
    Public Type GETVERSIONOUTPA RAMS
    bVersion As Byte ' Binary driver version.
    bRevision As Byte ' Binary driver revision.
    bReserved As Byte ' Not used.
    bIDEDeviceMap As Byte ' Bit map of IDE devices.
    fCapabilities As Long ' Bit mask of driver capabilities.
    dwReserved(3) As Long ' For future use.
    End Type

    'Bits returned in the fCapabilities member of GETVERSIONOUTPA RAMS
    Public Const CAP_IDE_ID_FUNC TION = 1 ' ATA ID commandsupporte d
    Public Const CAP_IDE_ATAPI_I D = 2 ' ATAPI ID commandsupporte d
    Public Const CAP_IDE_EXECUTE _SMART_FUNCTION = 4 ' SMART commanndssuppor ted

    '---------------------------------------------------------------------
    ' IDE registers
    '---------------------------------------------------------------------
    Public Type IDEREGS
    bFeaturesReg As Byte ' // Used for specifying SMART "commands".
    bSectorCountReg As Byte ' // IDE sector count register
    bSectorNumberRe g As Byte ' // IDE sector number register
    bCylLowReg As Byte ' // IDE low order cylinder value
    bCylHighReg As Byte ' // IDE high order cylinder value
    bDriveHeadReg As Byte ' // IDE drive/head register
    bCommandReg As Byte ' // Actual IDE command.
    bReserved As Byte ' // reserved for future use. Must bezero.
    End Type

    '---------------------------------------------------------------------
    ' SENDCMDINPARAMS contains the input parameters for the
    ' Send Command to Drive function.
    '---------------------------------------------------------------------
    Public Type SENDCMDINPARAMS
    cBufferSize As Long ' Buffer size in bytes
    irDriveRegs As IDEREGS ' Structure with drive register values.
    bDriveNumber As Byte ' Physical drive number to send commandto(0,1,2 ,3).
    bReserved(2) As Byte ' Bytes reserved
    dwReserved(3) As Long ' DWORDS reserved
    bBuffer() As Byte ' Input buffer.
    End Type

    ' Valid values for the bCommandReg member of IDEREGS.
    Public Const IDE_ATAPI_ID = &HA1 ' Returns ID sector for
    'ATAPI.
    Public Const IDE_ID_FUNCTION = &HEC ' Returns ID sector for
    'ATA.
    Public Const IDE_EXECUTE_SMA RT_FUNCTION = &HB0 ' Performs SMART cmd.
    ' Requires valid
    'bFeaturesReg,
    ' bCylLowReg, andbCylHighRe

    ' Cylinder register values required when issuing SMART command
    Public Const SMART_CYL_LOW = &H4F
    Public Const SMART_CYL_HI = &HC2

    '---------------------------------------------------------------------
    ' Status returned from driver
    '---------------------------------------------------------------------
    Public Type DRIVERSTATUS
    bDriverError As Byte ' Error code from driver, or 0 if no
    'error.
    bIDEStatus As Byte ' Contents of IDE Error register.
    ' Only valid when bDriverError is
    'SMART_IDE_ERRO R.
    bReserved(1) As Byte
    dwReserved(1) As Long
    End Type

    ' bDriverError values
    Public Enum DRIVER_ERRORS
    SMART_NO_ERROR = 0 ' No error
    SMART_IDE_ERROR = 1 ' Error from IDE controller
    SMART_INVALID_F LAG = 2 ' Invalid command flag
    SMART_INVALID_C OMMAND = 3 ' Invalid command byte
    SMART_INVALID_B UFFER = 4 ' Bad buffer (null, invalid addr..)
    SMART_INVALID_D RIVE = 5 ' Drive number not valid
    SMART_INVALID_I OCTL = 6 ' Invalid IOCTL
    SMART_ERROR_NO_ MEM = 7 ' Could not lock user's buffer
    SMART_INVALID_R EGISTER = 8 ' Some IDE Register not valid
    SMART_NOT_SUPPO RTED = 9 ' Invalid cmd flag set
    SMART_NO_IDE_DE VICE = 10 ' Cmd issued to device not present
    ' although drive number is valid
    ' 11-255 reserved
    End Enum
    '---------------------------------------------------------------------
    ' The following struct defines the interesting part of the IDENTIFY
    ' buffer:
    '---------------------------------------------------------------------
    Public Type IDSECTOR
    wGenConfig As Integer
    wNumCyls As Integer
    wReserved As Integer
    wNumHeads As Integer
    wBytesPerTrack As Integer
    wBytesPerSector As Integer
    wSectorsPerTrac k As Integer
    wVendorUnique(2 ) As Integer
    sSerialNumber(1 9) As Byte
    wBufferType As Integer
    wBufferSize As Integer
    wECCSize As Integer
    sFirmwareRev(7) As Byte
    sModelNumber(39 ) As Byte
    wMoreVendorUniq ue As Integer
    wDoubleWordIO As Integer
    wCapabilities As Integer
    wReserved1 As Integer
    wPIOTiming As Integer
    wDMATiming As Integer
    wBS As Integer
    wNumCurrentCyls As Integer
    wNumCurrentHead s As Integer
    wNumCurrentSect orsPerTrack As Integer
    ulCurrentSector Capacity As Long
    wMultSectorStuf f As Integer
    ulTotalAddressa bleSectors As Long
    wSingleWordDMA As Integer
    wMultiWordDMA As Integer
    bReserved(127) As Byte
    End Type

    ....
    [/FONT][/SIZE]

    (i had to cut it down because of the maxlen of this post*grr*)

    i only found this bas module in this forum.

    ok it works but how do i get out the live temperature ?

    thanks :)

    lglmi
Working...