As a newbie to lazarus I had bit of a heavy lift to get comports working
for winCE if there is a better way then maybe someone could add their expertise
Background
MSDN WinCE3.0 API has the detailed info on the calls Ex SetupComm
plus the predefined structures EX DCB or COMMTIMEOUTS
Here is a skeleton for accessing a comport
1) the basic set up
uses
Classes,Windows,WinCEint, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Menus;
const
MAXSIZE=1024;
MAXTIMERCYCLES=30;
type
PCHAR16=array [0..MAXSIZE] of Widechar;
PCHAR8=array[0..MAXSIZE] of char;
public
{ public declarations }
end;
var
Form1: TForm1;
MyCommhandle: Thandle;
MyCommDCB:TDCB;
MyCommtimeout:TCOMMTIMEOUTS;
MyCommPort:PWideChar;
MyInbuffsize,MyOutbuffsize:DWORD;
MyBytesTrans:DWORD;
MyCount:DWORD;
MyBuffer:PCHAR8;
Success:Boolean;
2) the calls to set up the commport file ex Com1
MyCommPort:='COM1:'; //// don't forget the colon
MyCommhandle:=INVALID_HANDLE_VALUE;
MyCommhandle:=CreateFileW(Pwchar(MyCommPort),GENERIC_READ or GENERIC_WRITE,0,nil,
OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
Assuming MyCommhandle<> INVALID_HANDLE_VALUE you can proceed to step3
3)
Myinbuffsize:=1024;
Myoutbuffsize:=1024;
Success:=SetupComm(MyCommhandle,MyInbuffsize,MyOutbuffsize);
assuming succes proceed to step4
4)
now retrieve the current ports DCB ( this is needed to get MycommDCB fully populated
Success:=GetCommState(MyCommhandle,MyCommDCB);
assuming success proceed to step5
5)
MyCommDCB.BaudRate:=4800; //// ex of setting baud rate other values in the DCB can also be assigned
Success:=SetCommState(MyCommhandle,MyCommFDCB);
assuming success proceed to step6
6) MyCommtimeout.ReadIntervalTimeout:=MAXDWORD;
MyCommtimeout.ReadTotalTimeoutMultiplier:=100;
MyCommtimeout.ReadTotalTimeoutConstant:=100;
MyCommtimeout.WriteTotalTimeoutMultiplier:=MAXDWORD;
MyCommtimeout.WriteTotalTimeoutConstant:=100;
Success:=SetCommTimeouts(MyCommhandle,MyCommtimeout);
assuming success proceed to step7
7) Now for read write
Success:=readFile(MyCommhandle,MyBuffer,MyCount,MyBytesTrans,nil);
Success:=WriteFile(MyCommhandle,MyBuffer,MyCount,MyBytesTrans,nil);
Mybuffer is where you want to send or receive data and Mycount is the bytes you want
MyBytesTrans is what the interface actually did transfer
CloseHandle(MyCommhandle)