Hilp me please
I want to read data of RS232 and store it in Access Data base

Dani AI

Generated

Brief practical plan for : confirm the COM port and the exact byte format the device sends, read the serial stream reliably from Delphi, and write parsed records to Access using ADO. Advice from about checking port settings is on target; ’s note that existing components can save time is also useful — choose a maintained component if you prefer not to handle Windows API details.

Start-up checklist:

  • Verify the port number and data with a terminal app (check line endings, encoding, and whether the device sends continuous frames or discrete records).
  • Decide on approach: a ready-made Delphi serial component (fewer pitfalls) or low-level WinAPI (CreateFile/ReadFile) for custom control.
  • Always read serial data on a background thread or use asynchronous I/O; avoid blocking the UI and funnel DB writes through a single, synchronized writer to prevent collisions.

Minimal synchronous read example (blocking, suitable for a quick test):

uses Windows, SysUtils;

function ReadOnceFromCOM(const PortName: string): AnsiString;
var
  hCom: THandle;
  DCB: TDCB;
  Timeouts: TCommTimeouts;
  BytesRead: DWORD;
  Buffer: array[0..1023] of Byte;
begin
  hCom := CreateFile(PChar('\\.\' + PortName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);
  if hCom = INVALID_HANDLE_VALUE then
    raise Exception.Create('Cannot open ' + PortName);
  try
    FillChar(DCB, SizeOf(DCB), 0);
    DCB.DCBlength := SizeOf(DCB);
    GetCommState(hCom, DCB);
    DCB.BaudRate := CBR_9600; DCB.ByteSize := 8; DCB.Parity := NOPARITY; DCB.StopBits := ONESTOPBIT;
    SetCommState(hCom, DCB);
    FillChar(Timeouts, SizeOf(Timeouts), 0);
    Timeouts.ReadTotalTimeoutConstant := 200;
    SetCommTimeouts(hCom, Timeouts);
    if ReadFile(hCom, Buffer, SizeOf(Buffer), BytesRead, nil) then
      SetString(Result, PAnsiChar(@Buffer[0]), BytesRead)
    else
      Result := '';
  finally
    CloseHandle(hCom);
  end;
end;

Writing into Access (ADO): open a single TADOConnection (Jet for .mdb or ACE for .accdb) and execute parameterized INSERTs. Important: escape quotes or use parameters, and perform DB operations from one thread or via a synchronized queue so the Access engine isn’t hit concurrently. Common troubleshooting: wrong COM name (use "\.\COM10" style for ports > COM9), mismatched parity/baud, or incorrect null-modem wiring.

Recommended Answers

All 2 Replies

Hi

Com port communication must be handled as a file input outout. The process in simplified terms is
Assign a comport to a file
Open the file
read the data
process the data
close the file

Factors that must be considered are
Speed, parity, stop bits, x on x off hand shaking - become familiar with the purpose of these terms

Have a look at http://sheepdogguides.com/dt5f.htm, http://sheepdogsoftware.co.uk/plh1rs.htm,
http://www.arunet.co.uk/tkboyd/ele1sp.htm

I have used a package called Cport-3.10 for years. Now in D2007. I love it. It is easy to use. On hook only: there seems to be nobody supporting it anymore. Still it works very good.

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.