Virtual Pascal

Classic Object Pascal for free

I am trying to write a program in VP to read the CPU temperature and Fan speed from the BIOS on my motherboard.
If I use the the code

uses os2base;
//Procedure Read_reg;
var
fd:longint ;
action:longint;
type
par= record
port:smallword ;
size:smallword;
end;
dta=record
data:longint ;
end;
var
parm:par;
d:dta;
res, len1,len2:LONGint ;
begin
DosOpen('testcfg$',fd, action, 0, FILE_NORMAL, FILE_OPEN,OPEN_ACCESS_READWRITE or OPEN_SHARE_DENYNONE,NiL);
parm.port := $D05;
parm.size := sizeof(longint);
len1:=1;
len2:=sizeof(d);
d.data:=$58;
res := DosDevIOCtl(fd,$80,$42,@parm, sizeof(par), @len1,@d, sizeof(dta), @len2);
//* check error code.... */
parm.port := $D05+1;
parm.size := 1;
len1:=sizeof(parm);
d.data:=$0;
res := DosDevIOCtl(fd, $80,$41,@parm, sizeof(par), @len1,@d, sizeof(dta), @len2);
//* check error code.... */
//result:=d.data;
DosClose(fd);
end.

then the data in d.data after the second DOSDEVIOCTL call is the correct value I expect with the chip on my motherboard.
But if I use the code (call the whole thing as a procedure or function)

uses os2base;
Procedure Read_reg;
var
fd:longint ;
action:longint;
type
par= record
port:smallword ;
size:smallword;
end;
dta=record
data:longint ;
end;
var
parm:par;
d:dta;
res, len1,len2:LONGint ;
begin
DosOpen('testcfg$',fd, action, 0, FILE_NORMAL, FILE_OPEN,OPEN_ACCESS_READWRITE or OPEN_SHARE_DENYNONE,NiL);
parm.port := $D05;
parm.size := sizeof(longint);
len1:=1;
len2:=sizeof(d);
d.data:=$58;
res := DosDevIOCtl(fd,$80,$42,@parm, sizeof(par), @len1,@d, sizeof(dta), @len2);
//* check error code.... */
parm.port := $D05+1;
parm.size := 1;
len1:=sizeof(parm);
d.data:=$0;
res := DosDevIOCtl(fd, $80,$41,@parm, sizeof(par), @len1,@d, sizeof(dta), @len2);
//* check error code.... */
//result:=d.data;
DosClose(fd);
end
begin
Read_reg
end.

then by the time I get to DOsClose(fd) d.data is 0. Can anyone explain why?

Views: 114

Reply to This

Replies to This Discussion

Hi !

Well the only difference is that you use global variables and type declarations in the first code and local ones in the second one ?!?
I suppose you tested that DosDevIOCtl didn't return any error ?
Unfortunately I have no OS/2 system to test your code. I have no explanation, sorry.

Bye for now,
Alcatiz.
Yes, DosDevIOCtl returns 0 each time
By the way, how do you test the value of d.data ? Within the debugger ?
Yes, so I wondered if the error was in my code or in the debugger.
To be sure, you should create a screen output to display the value and run your program "for real" :-)

RSS

© 2022   Created by Allan Mertner.   Powered by

Report an Issue  |  Terms of Service