è circa un anno che scrivo applicazioni di interfaccia tra PC e componenti hardware collegati sulla seriale e anche con XP posso accedere direttamente alla porta e funziona bene.
Le istruzioni assembler che citi, probabilmente sono ad un livello troppo basso x avere la compatibilità con tutti gli OS.
Se vuoi ti mando l'ocx di mscomm, o un componente veramente simile, forse più performante, compreso di sorgenti e programma applicativo demo.
Ho guardato la suite che citava alka è non è niente male.
Ora la scelta è a te, se hai ancora problemi prova ad essere più dettagliato.
se vuoi accedere direttamente alla porta x te non è altro che un file:
codice:
var ComFile: THandle;
{$R *.DFM}
function OpenCOMPort: Boolean;
var DeviceName: array[0..80] of Char;
begin
StrPCopy(DeviceName, 'COM1:');
ComFile := CreateFile(DeviceName,
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if ComFile = INVALID_HANDLE_VALUE then
Result := False
else
Result := True;
end;
function SetupCOMPort: Boolean;
const
RxBufferSize = 256;
TxBufferSize = 256;
var
DCB: TDCB;
Config: string;
CommTimeouts: TCommTimeouts;
begin
Result := True;
if not SetupComm(ComFile, RxBufferSize, TxBufferSize) then
Result := False;
if not GetCommState(ComFile, DCB) then
Result := False;
Config := 'baud=9600 parity=e data=8 stop=1';
if not BuildCommDCB(@Config[1], DCB) then
Result := False;
if not SetCommState(ComFile, DCB) then
Result := False;
with CommTimeouts do
begin
ReadIntervalTimeout := 0;
ReadTotalTimeoutMultiplier := 0;
ReadTotalTimeoutConstant := 500;
WriteTotalTimeoutMultiplier := 0;
WriteTotalTimeoutConstant := 500;
end;
if not SetCommTimeouts(ComFile, CommTimeouts) then
Result := False;
end;
procedure SendText(s: string);
var BytesWritten: DWORD;
begin
WriteFile(ComFile, s[1], Length(s), BytesWritten, nil);
end;
function ReadText: string;
var
d: array[1..80] of Char;
s: string;
i: Integer;
BytesRead:dword;
begin
Result := '';
if not ReadFile(ComFile, d, SizeOf(d), BytesRead, nil) then
begin
{ Raise an exception }
end;
s := '';
for i := 1 to BytesRead do s := s + d[I];
Result := s;
end;
procedure CloseCOMPort;
begin
CloseHandle(ComFile);
end;
In ogni modo l'aiuto di un componente già testato da altri è consigliabile.