473,659 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Temperature form HDD via SMART?

1 New Member
'[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
Sep 14 '05 #1
0 5498

Sign in to post your reply or Sign up for a free account.

Similar topics

1
12126
by: deanfamily11 | last post by:
I'm trying to have this program do a simple temperature conversion from Fahrenheit to Celsius. I have confirmed that the other variable is receiving and calculating the conversion, but it is just outputting as "0". Any thoughts? (Code is below) #include <iostream> #include <iomanip> using namespace std;
16
2884
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the form order to do that ? My point is for the client to be able to re-read the modified data.
1
2779
by: VM | last post by:
I'm working on a web form that displays the temperature of a certain room and I'd like to display the temperature as a thermometer where I send it the value (eg. 78 degrees F) and the thermometer changes and displays that value. Where can I find a control for a web form that looks like that? Thanks.
2
1733
by: Jeff Van Epps | last post by:
We've been unable to get events working going from C# to VJ++. We think that the C# component is being exposed properly as a ConnectionPoint, and the Advise() from the VJ++ side seems to be working, because the delegate on the C# side has 1 item in its invocation list after the Advise(). However when we try to make the callback, we get: System.NullReferenceException: Object reference not set to an instance of an object at...
5
32467
by: anthony | last post by:
One the computer I am programmig I could see the CPU temperature in the BIOS, is there a system DLL in VB.NET that I can call to display the temperature in my software? Thanks!
4
3404
by: Gary | last post by:
Hi, I have a temperature conversion program down pat, but I was told to add an average, meaning, i need to get the average temperature for as many times as it was entered. i do not know where to start, and my stpid book doesnt seem to help. here is my program #include <iostream.h> void main( ) {
2
2695
by: lifeshortlivitup | last post by:
I am a java beginner and am trying to tackle a temperature conversion problem but I don't exactly know how to begin. The problem asks that I write a program that allows the user to conver either from degrees Celsius to Fahrenheit or from degrees Fahrenheit to Celsius. I have the following formulas to accomplish this already: degreesC = 5(degreesF - 32)/9 degreesF = (9(degreesC)/5)+32 Then it asks to prompt the use to enter a temperature...
3
2329
by: shk253 | last post by:
Hi - This program converts temperature from C to F and F to C and averages the Celsius outputs in one variable and Fahrenheit outputs in another. My professor asked us to modify this program to use functions. After I created functions and got it running, the csum and fsum variables seem to get the wrong values. It would be great if somebody could spot the problem and give me a hint. Thanks. //Fahrenheit and Celsius conversion using functions...
16
4418
by: Brigitte Behrmann | last post by:
I am absolutely stuck with this one. I have to create a temperature conversion calculator that rounds the resulting temperature to the nearest whole number & vice versa. The result must be displayed in a window alert. The given formula is (Fahrenheit_temp - 32) * .55 The only tip/clue I have is to use var tempInCelcius = (document.Converter.fahrenheit.value - 32) * .55; var tempInFahrenheit = (document.Converter.celcius.value * 1.8) + 32 ...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.