Link to home
Start Free TrialLog in
Avatar of Duebel
Duebel

asked on

Serial communication with Win32

I need to send and receive data over a serial connection. How can I access the comm ports under Windows 95 and NT and how can I send data over such a connection. Please provide some sample code or give me an URL where I can find more informations. (I need something like a terminal app.)
ASKER CERTIFIED SOLUTION
Avatar of eugenem
eugenem

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dhardyanto
dhardyanto

Here is some code example:

procedure OpenCom1;
begin
  Port:='COM1';
  hPort:=CreateFile(PChar(Port),GENERIC_READ or GENERIC_WRITE,0,nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
end;

// This is to send a stream of chars to comm port

procedure WriteToCom1(S: string);
var ByteWritten: longword;
begin
  WriteFile(hPort, PChar(S)^, Length(S), ByteWritten, nil);
end;

procedure CloseCom1;
begin
  CloseHandle(hPort);
end;

Consult your Windows SDK help in your Delphi (Help|Windows SDK) or simple press F1 in the function for more detail about function's parameters. :)

Donny