Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:44:16+00:00 2026-06-11T21:44:16+00:00

I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus

  • 0

I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus FPC to compile it.

After 3 weeks work I reluctantly post here in the hope someone can suggest why I am getting garbled output from the serial port.

The code I am using is posted below. This is the standard code I have found from several places.

The OpenPort works OK.

When I send the string using SendString(‘ABCDEF’) I get garbled input to the PC Serial port such as:

4[#131][#26][#0][#0][#0][#0] (the bracketed data indicates that it is a non-printable character ASCII Code)

Obviously it is connecting to the port OK AND it is sending the correct no of characters (7).

I have tried all combinations of Baud Rate, Data Bits, Parity and Stop Bits without any joy. Also tried changing cable, on a different PC etc.

Could it be I need to set something else in the DCB?

Any help or suggestions would be GREATLY appreciated.

unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, 
Windows, LResources;

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

private
{ private declarations }
public
{ public declarations }
end;

var
Form1: TForm1;

cc:TCOMMCONFIG;
Connected:Boolean;

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

{ TForm1 }  
function  
OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;

var
cc:TCOMMCONFIG;
SWide:WideString;
Port:LPCWSTR;

begin
SWide:=ComPort;
Port:=PWideChar(SWide);
result:='';
if (1=1) then begin
Connected:=False;
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;
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,Length(str), lrc, nil);
end;

end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:44:17+00:00Added an answer on June 11, 2026 at 9:44 pm

    Found the answer to this.

    WriteFile(hComm,str,Length(str), lrc, nil);

    The “str” parameter was in fact a pointer to the string, not the string itself

    Changing it to this works.

    WriteFile(hComm,str[1],Length(str), lrc, nil);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm programming for an embedded device with a NVIDIA Tegra 2 running Windows Embedded
while programming for windows phone 7, I created a listbox and using DataTemplate which
I'm new to CE programming and I have a Marvel device PXA270 with Windows
I have to create an application using a Datalogic mobile device that uses Windows
I learned windows programming using Visual C++, and the Win32 API. Nowadays, it seems
I'm moving from windows programming (By windows programming I mean using Windows API )
I'm programming a Windows local service using C++ and WinAPIs. From within that service
I'm new in programming windows phone 7 but get really tired cuz i spend
In windows programming, how can we find out the number of partitions and the
I have been doing some x86 programming in Windows with NASM and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.