Lazarus

Programming => Operating Systems => Windows CE => Topic started by: ChrsO on September 25, 2012, 06:23:45 am

Title: [SOLVED] WinCE 6.0 Serial Communication Help
Post by: ChrsO on September 25, 2012, 06:23:45 am
Hi,
I am trying to write to a serial port from a Windows CE 6.0 device (Motorola MC3100). I have searched the forums and tried a few solutions but had no luck getting them to work.

Windows 7 64bit
lazarus-1.0-fpc-2.6.0-win32
lazarus-1.0-fpc-2.6.0-cross-arm-wince-win32
Prolific USB-to-Serial Comm Port Adapter
Motorola MC3100 running Windows CE 6.0

So far I have tried:
http://80.123.225.56/index.php?topic=9619.0 (http://80.123.225.56/index.php?topic=9619.0) but received an 'Access Violation' error when I execute OpenPort.

Code: [Select]
uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Win32CESerialCom;
...
var
  frmMain: TfrmMain;
  uploadString: String;
  Serial1: TWin32CESerialCom;   
...
procedure TfrmMain.btnUploadClick(Sender: TObject);
begin
  Serial1.OpenPort('COM5',19200,8,1,1);
end;       

I have also looked into MiniLib http://www.lazarus.freepascal.org/index.php/topic,6492.0.html (http://www.lazarus.freepascal.org/index.php/topic,6492.0.html) but the link was dead \ could find the relevant files.

Also, as pointed out in that thread
Quote
Synaser and 5pdo do not support for winCE platform.

relevant thread http://www.lazarus.freepascal.org/index.php?topic=6489.0 (http://www.lazarus.freepascal.org/index.php?topic=6489.0) says:
Quote
    "I have recieved reply form Synapse project
    'It is because I never try to compile it for WinCE, and current IFDEFs not identifying this platform correctly.'
    '> That means I can not use synaser under windows mobile system in PDA or> Smartphone?
    ---Yes. It means - nobody ported Synaser to this platform yet.'"


Again http://www.lazarus.freepascal.org/index.php?topic=6485.0 (http://www.lazarus.freepascal.org/index.php?topic=6485.0) - I received the same error "Can't find unit termio used by synaser" as this guy.

Any help at all greatly appreciated.
Title: Re: WinCE 6.0 Serial Communication Help
Post by: BigChimp on September 25, 2012, 08:11:00 am
I would try fiddling with the compiler defines (see the other thread) and see if that helps.

Obviously, the code does not run the Windows32 code as it's looking for the Unix termio library.
I'll reply to the other thread with a suggestion (don't have wince device myself so no idea if that works or is sufficent)
Title: Re: WinCE 6.0 Serial Communication Help
Post by: dago71 on September 26, 2012, 04:45:48 pm
you can found miniComm here:
http://sourceforge.net/p/minilib/code/505/tree/trunk/comm/source/

svn checkout svn://svn.code.sf.net/p/minilib/code/trunk minilib-code

BTW, i don't understand your setup... you have the Prolific USB-To-Serial USB side attached to the MC3100? Or it is the serial port side?
Check Windows CE Control Panel if there is a COM5 Serial Port.
Title: Re: WinCE 6.0 Serial Communication Help
Post by: ChrsO on October 05, 2012, 07:21:20 am
Thanks for your replies. I did get it working. I am a newbie so can't really explain it all, but here is the code anyway:
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Windows, pqconnection, LResources;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    PQConnection1: TPQConnection;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    function  OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
    procedure SendString(str:String);
  end;

var Form1: TForm1;
    cc:TCOMMCONFIG;
    Connected:Boolean;

implementation
{$R *.lfm}
var F: TextFile;
var hComm: THandle;
str: String;
lrc: LongWord;
{ TForm1 }

function  TForm1.OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
var cc:TCOMMCONFIG;
    SWide:WideString;
    Port:LPCWSTR;
begin
SWide:=ComPort;
Port:=PWideChar(SWide);
result:='';
if Connected then exit;
hComm:=CreateFile(Port, GENERIC_READ or GENERIC_WRITE,0, nil,OPEN_EXISTING,0,0);
if (hComm = INVALID_HANDLE_VALUE) then begin ShowMessage('Fail to Open');  exit; end;
GetCommState(hComm,cc.dcb);
cc.dcb.BaudRate:=BaudRate;
cc.dcb.ByteSize:=ByteSize;
cc.dcb.Parity:=Parity;
cc.dcb.StopBits:=StopBits;
if not SetCommState(hComm, cc.dcb) then begin  result:='SetCommState Error!';  CloseHandle(hComm);  exit; end;
Connected:=True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
OpenPort('COM1:',9600,8,0,0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
SendString('ABCDEFG');
end;

procedure TForm1.SendString(str:String);
var lrc:LongWord;
begin
if (hComm=0) then exit;
try
if not PurgeComm(hComm, PURGE_TXABORT or PURGE_TXCLEAR) then
raise Exception.Create('Unable to purge com: '); except  Exit; end;
WriteFile(hComm,str[1],Length(str), lrc, nil);
end;

end.

Quote
i don't understand your setup... you have the Prolific USB-To-Serial USB side attached to the MC3100? Or it is the serial port side?

I am using the Prolific USB-To-Serial Connector to connect the scanners (from which i am sending data) serial cable to my PC (which is receiving the data), which doesn't have a serial port. I was concerned it could be causing the issue (and in fact still am, I haven't tested it; only tested on another machine with a 'proper' serial port)
TinyPortal © 2005-2018