function readport(port: string; bytes: dword): string;
var
InputBuffer : string;
NumberOfBytesRead : dword;
MaxBytesToRead : dword;
hCommFile : THandle;
i: integer;
begin
hCommFile := CreateFile(PChar(port),GENERIC_WRITE,0,nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if hCommFile=INVALID_HANDLE_VALUE then exit;
setlength(inputbuffer, bytes);
for i := 1 to bytes do
inputbuffer[I] := '1';
MaxBytesToRead := bytes;
if ReadFile(hCommFile, PChar(InputBuffer)^, MaxBytesToRead, NumberOfBytesRead, nil) = false then
begin
ShowMessage('Unable to read from comport');
exit;
end;
result := copy(InputBuffer, 1, NumberOfBytesRead);
closehandle(hCommfile);
end;
readport('COM4', 24);
noget ala dette?
Jeppe Johansen
Jeppesoftware@hotmail.com
[Redigeret d. 06/01-05 09:25:29 af Jeppe]