Hi,
I am new in Delphi.
I wrote a Windows application with plain C and native API a few years ago,one function of the application is that it reads data
string from four serial commports, and it is defined in a thread. I want to know how to do the same thing in Delphi, mainly it covers two issues, create a thread and call Windows API.
For my cass, how can I translater following C code to Delphi
(1) Create handle to commport, like
HANDLE hCom1 = CreateFile ("COM1", ENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,NULL)
(2) Create a thread
HANDLE hReadThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)ReadThreadProc, NULL, 0, &id)
(3) Create thread function, it can reads commport,
DWORD ReadThreadProc (LPDWORD lpdwParam1)
{
...
while (bReading)
{
// read the bytes
if (ReadFile(hCom1, inbuff, nToRead, &nBytesRead, NULL))
if (nBytesRead)
ProcessSensorReadBytes(inbuff, nBytesRead);
}
.....
}
Thanks in advance
Daniel