🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6992

Re: Serial Port general reading/writing questions

#6992
From: Bob Gonder
Date: Mon, 21 Mar 2005 21:48
67 lines
3132 bytes
Vladimir Stefanovic wrote:


>What do you think I should keed in config

Everything.

> and what hardcoded?

Nothing.


>2) About sending data. If I have TStringList which contains
>AT commands, how should I technically send them /pseudo/:
>
>   a) // Port is opened all the time
>      CreateFile(); // Opens port at server start/resume
>      for ( int i=0; i<ATCommands->Count; i++ )
>         WriteSomeBufferToSpecifiedComPort( ATCommands[i] );
>      CloseHandle(); // Close port at server stop/pause
>
>   b) // Port is opened for sending a whole list, and then closes
>      CreateFile(); // Open port at start of sending a serie
>      for ( int i=0; i<ATCommands->Count; i++ )
>         WriteSomeBufferToSpecifiedComPort( ATCommands[i] );
>      CloseHandle(); // Close port when a serie is sent

That's the same code as (a)


>   c) // Port is opened for sending a single item only
>      for ( int i=0; i<ATCommands->Count; i++ )
>      {
>         CreateFile(); // Opens port
>         WriteSomeBufferToSpecifiedComPort( ATCommands[i] );
>         CloseHandle(); // Closes port
>      }

Might be desirable if you are using multiple threads, or changing
configurations, otherwise, not likely the best.


>3) When writing data (WriteFile) to COM port, how the device
>knows that is has received the whole package of data (one item
>'AT command' from stringlist), and what is the second, etc?
>Maybe the '\0' is the terminator?

All AT commands are terminated with a carrage return ( '\n' ).
	"ATs0=1\n"


>Does this code can be used for a loop?
>   for ( int i=0; i<ATCommands->Count; i++ )
>      WriteABuffer( ATCommands[i].c_str(), ATCommands[i].Length() );

No, because you aren't checking the return value.
Nor do you ever wait for completion.
Nor do you set up an event that gets triggered when the write
completes.
In other words. you completely ignore all of the benefits of
overlapped i/o.

>5) For my case are 'overlapped' or 'non-overlapped' solutions better?

Since you don't use any of the overlapped features, the code you
showed would be very much simpler and clearer if you just used
non-overlapped i/o to begin with.
Technical Details
Message-ID: <47fu31dkadum3itjg5a89fanbcukk1v3os@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <423ed88d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b842bafb98039a75
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Serial Port general reading/writing questions 
Date: Mon, 21 Mar 2005 13:48:56 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <47fu31dkadum3itjg5a89fanbcukk1v3os@4ax.com>
References: <423ed88d@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.147.145
X-Trace: newsgroups.borland.com 1111441731 67.77.147.145 (21 Mar 2005 13:48:51 -0800)
Lines: 70
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail