Lazarus

Programming => Operating Systems => Windows CE => Topic started by: picstart on June 21, 2009, 07:28:45 pm

Title: WinCe comport access
Post by: picstart on June 21, 2009, 07:28:45 pm
 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
8)
   CloseHandle(MyCommhandle)
Title: Re: WinCe comport access
Post by: donalejo on February 08, 2018, 06:33:25 pm
Thanks, Question


How do I show the data in a label?
Title: Re: WinCe comport access
Post by: Ñuño_Martínez on February 09, 2018, 01:32:44 pm
Thanks, Question


How do I show the data in a label?

Using TLabel's "Caption" property.  Just assign the value to it (as STRING, of course).
TinyPortal © 2005-2018