Recent

Author Topic: WinCe comport access  (Read 14011 times)

picstart

  • Full Member
  • ***
  • Posts: 236
WinCe comport access
« 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)

donalejo

  • Newbie
  • Posts: 6
Re: WinCe comport access
« Reply #1 on: February 08, 2018, 06:33:25 pm »
Thanks, Question


How do I show the data in a label?

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: WinCe comport access
« Reply #2 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).
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

 

TinyPortal © 2005-2018