Source Code for gp_Temp5 to MBM5 Interface
The original Shared Memory source code by Alex van Kaam may be found on http://mbm.livewiredev.com/ under the heading of MBM 5 Shared Memory and also in the Shared Memory section of the help files found in MBM5. Alex's source code shows additional functions of the shared memory that I have not used in gp_Temp5.
This interface enables the write of the current temperature, highest temperature reached, lowest temperature reached, average temperature, and count of how many times the temperature has been read.
unit mbminit;
interface
uses
Windows, StdCtrls, Controls, Grids, Classes, Forms, SysUtils;
type
TBusType = (btISA, btSMBus,btVIA686ABus, btDirectIO);
TSMBType = (smtSMBIntel, smtSMBAMD, smtSMBALi, smtSMBNForce, smtSMBSIS);
TSensorType = (stUnknown, stTemperature, stVoltage, stFan, stMhz, stPercentage);
TSharedIndex = record
iType : TSensorType; // type of sensor
Count : integer; // number of sensor for that type
end;
TSharedSensor = record
ssType : TSensorType; // type of sensor
ssName : array [0..11] of AnsiChar; // name of sensor
sspadding1: array [0..2] of Char; // padding of 3 byte
ssCurrent : Double; // current value
ssLow : Double; // lowest readout
ssHigh : Double; // highest readout
ssCount : LongInt; // total number of readout
sspadding2: array [0..3] of Char; // padding of 4 byte
ssTotal : Extended; // total amout of all readouts
sspadding3: array [0..5] of Char; // padding of 6 byte
ssAlarm1 : Double; // temp & fan: high alarm; voltage: % off;
ssAlarm2 : Double; // temp: low alarm
end;
TSharedInfo = record
siSMB_Base : Word; // SMBus base address
siSMB_Type : TBusType; // SMBus/Isa bus used to access chip
siSMB_Code : TSMBType; // SMBus sub type, Intel, AMD or ALi
siSMB_Addr : Byte; // Address of sensor chip on SMBus
siSMB_Name : array [0..40] of AnsiChar; // Nice name for SMBus
siISA_Base : Word; // ISA base address of sensor chip on ISA
siChipType : Integer; // Chip nr, connects with Chipinfo.ini
siVoltageSubType : Byte; // Subvoltage option selected
end;
TSharedData = record
sdVersion : Double; // version number (example: 51090)
sdIndex : array [0..9] of TSharedIndex; // Sensor index
sdSensor : array [0..99] of TSharedSensor; // sensor info
sdInfo : TSharedInfo; // misc. info
sdStart : array [0..40] of AnsiChar; // start time
sdCurrent : array [0..40] of AnsiChar; // current time
sdPath : array [0..255] of AnsiChar; // MBM path
end;
PSharedData = ^TSharedData;
function WriteSharedData : Boolean;
var
SharedIndex : TSharedIndex;
SharedSensor : TSharedSensor;
SharedInfo : TSharedInfo;
SharedData : PSharedData;
Temperature : array[1..10] of Double; //ssCurent
TempL : array[1..10] of Real; //ssLow
TempH : array[1..10] of Real; //ssHigh
TempA : array[1..10] of Extended; //ssTotal - Readouts
TempC : array[1..10] of LongInt; //ssCount - # of Readouts
implementation
// Just do something
function WriteSharedData : Boolean;
var myHandle : Integer;
X : integer;
begin
myHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, '$M$B$M$5$S$D$');
if myHandle > 0 then begin
SharedData := MapViewOfFile(myHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
with SharedData^ do begin
for X:=3 to 6 do // 4 sensors - MBM #s 4,5,6, & 7
begin
sdSensor[X].ssCurrent := Temperature[X];
sdSensor[X].ssLow := TempL[X];
sdSensor[X].ssHigh := TempH[X];
sdSensor[X].ssTotal := round(TempA[X]);
sdSensor[X].ssCount := round(TempC[X]);
end;
end;
UnMapViewOfFile(SharedData);
Result := True;
end else result := false;
CloseHandle(myHandle);
end;
end.
|