Recent

Author Topic: [SOLVED] Trouble getting command line output on WinCE  (Read 15172 times)

AaronPower

  • New member
  • *
  • Posts: 5
[SOLVED] Trouble getting command line output on WinCE
« on: June 18, 2013, 04:56:00 am »
Hi,

I have been trying to write a simple command line only application for a Win CE device. After having some initial trouble with the compilation, I re-read all the forum posts I could find on setting up this environment.

To ensure I was working in a clean environment, I grabbed an old laptop, wiped it and installed a fresh version of Windows 7 32bit. After all the standard updates were complete I installed the latest release of Lazarus and the ARM for Win32 cross compiler (lazarus-1.0.10-fpc-2.6.2-win32.exe and lazarus-1.0.10-fpc-2.6.2-cross-arm-wince-win32.exe).

I then created a new "Console Application" and wrote a simple "Hello World" type app. For a first test I set the Code Generation to Win32 / i386, compiled and ran the program successfully on the laptop. It ran without errors and produced some basic text on the command line, then finished. I copied the exe over to the Win CE device and got a "Cannot execute" error, as expected.

After changing the code generation to WinCE and ARM processor, and setting the LCLWidgetType to wince, I re-compiled the application. Now when I tried to run it on the laptop I get a "not a valid Win32 application" error, as expected.

I then copied this new exe over to the WinCE device and run it, it executes without reporting any errors, but it does not produce any output in the command console.

It would appear that the cross compiler is working correctly in so far as it is creating a valid ARM based executable file, but I can't seem to get any output.

The test application I am using just uses simple
Code: [Select]
writeln('Hello'); code - I am not (yet) trying to call any specific units. I have tried with the LCLWidgetType set and without it (I would have thought being console only, it probably wouldn't use the LCL widgets anyway), but it does not make any difference.

The WinCE device is from DLOG http://www.dlog.com/en/products/7-industrial-computer/dlog-xmt-57/xmt-57-description/ and reports its OS as Windows CE 6.0 R3. When I first open the command prompt it reports as being "Pocket CMD v 6.00".

Is there something simple I am missing here?
« Last Edit: June 20, 2013, 03:01:39 am by AaronPower »

AaronPower

  • New member
  • *
  • Posts: 5
Re: Trouble getting command line output on WinCE
« Reply #1 on: June 18, 2013, 06:54:42 am »
A small update... I found a previous wiki post that talked about debug logging to a text file using the LCLProc unit http://wiki.freepascal.org/WinCE_Programming_Tips.

Using this technique I can confirm that the version of the test app compiled for ARM WinCE runs and correctly produces the log file, but still does not provide any output on the command line / console.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Trouble getting command line output on WinCE
« Reply #2 on: June 18, 2013, 07:27:15 am »
Bit of a strange question perhaps but I thought WinCE had no console at all!?!?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

AaronPower

  • New member
  • *
  • Posts: 5
Re: Trouble getting command line output on WinCE
« Reply #3 on: June 18, 2013, 08:22:02 am »
I think it is an optional component. This is an industrial embedded PC rather than a phone. I don't think they include the console in many phones or small PDA's, but in this case we actually have a telnet server on the Windows CE device that allows us to login to them remotely. As such it needs some sort of console, which as stated below, is provided by "Pocket CMD v 6.00".

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Trouble getting command line output on WinCE
« Reply #4 on: June 18, 2013, 08:43:26 am »
Hmmm... hope FPC knows that Pocket CMD is the actual console given - as you also said -  it's not present in consumer devices.

Might take some WinCE knowledgeable guys to answer that one.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

AaronPower

  • New member
  • *
  • Posts: 5
Re: Trouble getting command line output on WinCE
« Reply #5 on: June 19, 2013, 02:06:34 am »
It is like the Lazarus application has the standard output redirected to NULL. Is there an alternate form of "writeln" that will output to a given stream, and is there a way of obtaining the window handle for the current running process.

Sorry, this is my first attempt at writing in Lazarus. I kind of know what I would like to try to test it further, but not sure how to go about it.

Thanks.

AaronPower

  • New member
  • *
  • Posts: 5
Re: Trouble getting command line output on WinCE
« Reply #6 on: June 19, 2013, 09:02:01 am »
After lots more searching, I managed to stumble across a post in the PDA and Smart Phone forum (http://www.lazarus.freepascal.org/index.php?topic=2486.10;wap2) that talked about getting output working for a simple Hello World app on Smart Phones.

The trick ended up being to add a compiler directive for "apptype console". My code now looks like:-
Code: [Select]
program FileSizeCheck;

{$mode objfpc}{$H+}
{$apptype console}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp, LCLProc
  { you can add units after this };

type

  { TFileSizeCheck }

  TFileSizeCheck = class(TCustomApplication)
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHelp; virtual;
  end;

{ TFileSizeCheck }

procedure TFileSizeCheck.DoRun;
var
  ErrorMsg: String;
begin
  // quick check parameters
  ErrorMsg:=CheckOptions('h','help');
  if ErrorMsg<>'' then begin
    ShowException(Exception.Create(ErrorMsg));
    Terminate;
    Exit;
  end;

  // parse parameters
  if HasOption('h','help') then begin
    WriteHelp;
    Terminate;
    Exit;
  end;

  { add your program here }
  DbgAppendToFile(ExtractFilePath(ParamStr(0)) + '1.log', 'Hello World');
  writeln('Hello World');

  // stop program loop
  Terminate;
end;

constructor TFileSizeCheck.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;

destructor TFileSizeCheck.Destroy;
begin
  inherited Destroy;
end;

procedure TFileSizeCheck.WriteHelp;
begin
  { add your help code here }
  writeln('Usage: ',ExeName,' -h');
end;

var
  Application: TFileSizeCheck;
begin
  Application:=TFileSizeCheck.Create(nil);
  Application.Run;
  Application.Free;
end.

This simple change now allows my application to produce output on the command line. Frustrating, but I figured it would be something simple in the end.

As an aside, how do I mark this thread as "Solved"? Is just manually adjusting the title, or is there a special tick box somewhere? Thanks.
« Last Edit: June 19, 2013, 09:05:45 am by AaronPower »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Trouble getting command line output on WinCE
« Reply #7 on: June 19, 2013, 01:10:17 pm »
Manually writing [SOLVED] in the subject of the first post will work.

Glad you got it working.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified