用GiveIO,SpeedFan就是使用GiveIO的。然后参见主板BIOS厂商提供的pdf文档得到相关CMOS数据在内存中的地址,通过GiveIO直接使用In、Out对I/O端口操作。
相关的C++.Net代码如下:
void CVCGiveIoTestDlg::OnTimer(UINT nIDEvent)
{
int nRead;
TCHAR strTemp[256];
int nPortIndex=0x295;
int nPortData=0x296;
int nSerial_Bus_Address_Register=0x48;
int nTemperature_reading=0x27;
int nFAN1_reading=0x28;
int nFAN2_reading=0x29;
int nFAN3_reading=0x2a;
int nBank_Select_Register=0x4e;
int nBank_Select_Bank1=0x81;
int nBank_Select_Bank2=0x82;
int nTemperature_Sensor_Up8=0x50;//只读要高位8个字节,最低1个字节不要了
//测试是否发生冲突
nRead=_inp((short)nPortIndex);
if((nRead&0x80)==0x80)
{
GetDlgItem(IDC_SENSOR_TEMP1)->SetWindowText("发生冲突");
GetDlgItem(IDC_SENSOR_FAN3)->SetWindowText("发生冲突");
return;
}
//读取系统温度
_outp((short)nPortIndex,nSerial_Bus_Address_Register);
_outp((short)nPortData,nTemperature_reading);
_outp((short)nPortIndex,nTemperature_reading);
nRead=_inp((short)nPortData);
sprintf(strTemp,"%d 度",nRead);
GetDlgItem(IDC_SENSOR_TEMP1)->SetWindowText(strTemp);
//读CPU温度
_outp((short)nPortIndex,nBank_Select_Register);
_outp((short)nPortData,nBank_Select_Bank1);
_outp((short)nPortIndex,nTemperature_Sensor_Up8);
nRead=_inp((short)nPortData);
sprintf(strTemp,"%d 度",nRead);
GetDlgItem(IDC_SENSOR_TEMP2)->SetWindowText(strTemp);
_outp((short)nPortIndex,nBank_Select_Register);
_outp((short)nPortData,nBank_Select_Bank2);
_outp((short)nPortIndex,nTemperature_Sensor_Up8);
nRead=_inp((short)nPortData);
sprintf(strTemp,"%d 度",nRead);
GetDlgItem(IDC_SENSOR_TEMP3)->SetWindowText(strTemp);
//读CPU风扇转速度
for(int nInx=0;nInx<3;nInx++)
{
_outp((short)nPortIndex,nSerial_Bus_Address_Register);
_outp((short)nPortData,nFAN1_reading+nInx);
_outp((short)nPortIndex,nFAN1_reading+nInx);
nRead=_inp((short)nPortData);
if(nRead==0xff) continue;
nRead=1350000/(nRead*4);
sprintf(strTemp,"%d 转",nRead);
GetDlgItem(IDC_SENSOR_FAN1+nInx)->SetWindowText(strTemp);
}
CDialog::OnTimer(nIDEvent);
}
其它东东等着你自己去发现了。