Hi,
Can someone assist me to locate
a Serial Comms Package for the old
Delphi V5,6,7 (early 2000's) ?
I wish to do basic comms IO routines.
I used to have a package called CPort(V.3?), but
my pc crashed and I was unable to obtain it again.
Maybe there are other working shareware Comms
Packages available? I appreciate your input?
Regards,
Gerhard

Or you can do it yourself...

Var
ComFile: THandle;

function TCServer.OpenDeviceSerial: Boolean;
Const
   RxBufferSize = 32768;
   TxBufferSize = 32768;
Var
   DeviceName: Array[0..80] of Char;
   DCB: TDCB;
   Config : String;
   CommTimeouts : TCommTimeouts;
begin
  Result := True;

  StrPCopy(DeviceName, ZSerialPort + ':');

  ComFile := CreateFile(DeviceName,
                        GENERIC_READ or GENERIC_WRITE,
                        0, Nil,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL, 0);

  if (ComFile = INVALID_HANDLE_VALUE) then
  begin
    Result := False;
    Exit;
  end;  

  if not SetupComm(ComFile, RxBufferSize, TxBufferSize) then
  begin
    Result := False;
    Exit;
  end;

  if not GetCommState(ComFile, DCB) then
  begin
    Result := False;
    Exit;
  end;  


  //Config := 'baud=19200 parity=n data=8 stop=1' + #0;
  Config := 'baud=' + IntToStr(ZSerialBaud) + ' parity=n data=8 stop=1'#0;

  if not BuildCommDCB(@Config[1], DCB) then
  begin
    Result := False;
    Exit;
  end;

  if not SetCommState(ComFile, DCB) then
  begin
    Result := False;
    Exit;
  end;  

  with CommTimeouts do
  begin
    ReadIntervalTimeout := 0;
    ReadTotalTimeoutMultiplier := 0;
    ReadTotalTimeoutConstant := 100;  //300
    WriteTotalTimeoutMultiplier := 0;
    WriteTotalTimeoutConstant := 100; //300
  end;

  if not SetCommTimeouts(ComFile, CommTimeouts) then
  begin
    Result := False;
  end;
end;
function TCServer.SendPacketSerial(Packet: String): String;
Var
   BytesWritten: Cardinal;
begin
  MainFm.aIndyBuffer.Add('--> ' + Packet);
  Packet := Chr(2) + Packet + #13#10;
  if not WriteFile (ComFile, Packet[1], Length(Packet), BytesWritten, Nil) then
  begin
    Result := emptyStr;
  end else
  begin
    Result := ReadPacketSerial;
  end;
end;

procedure TCServer.CloseDeviceSerial;
begin
  try
    CloseHandle(ComFile);
  except
    on E: Exception do
    begin
      //MainFm.aIndyBuffer.Add('Error closing serial connection');
      //do error stuff here
    end;
  end;
end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.