Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Serial Com Port



Permlink Replies: 9 - Last Post: Jan 30, 2018 5:11 AM Last Post By: Ted Lyngmo Threads: [ Previous | Next ]
Dan Ambrose

Posts: 87
Registered: 12/11/03
Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2016 7:22 AM
Hello,

I have a 10 year old serial communications program that was made with an old version of C++ builder and the 3rd party async pro add on tool kit. I want to update the program with the latest version of C++ builder but cant because it was written in a very old version of Delphi. The package build files are old and it is full of so many bugs. Id like to stop using this ancient tool kit. So I can update the project to the latest C++ builder and subsequently stop keeping an old version installed. I'm only using it to open up a com port at 19200 baud and then send and receive data .... I can write replacement code in win32. Before I did that I thought I would post a message here. Other than the direct WIN32 API ... Is there any non blocking serial APIs for C++ builder? Are there any classes / forms / library routines with C++ builder that do any serial IO ? I need a form that will ask the user for a comp port number and display all the available comports , then I need a C++ class that will give me non blocking get and put character api

If not then its no beg deal. I can spend the time making a wrapper class that uses win32 code and then form to let user choose a comport from list of ones installed etc etc

Any tips or feedback would be appreciated

Dan
David Millington

Posts: 257
Registered: 5/29/05
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2016 7:57 AM   in response to: Dan Ambrose in response to: Dan Ambrose
On 2016-02-19 15:22:39 +0000, Dan Ambrose said:
I have a 10 year old serial communications program that was made with
an old version of C++ builder and the 3rd party async pro add on tool
kit. I want to update the program with the latest version of C++
builder but cant because it was written in a very old version of
Delphi. The package build files are old and it is full of so many bugs.
Id like to stop using this ancient tool kit. So I can update the
project to the latest C++ builder and subsequently stop keeping an old
version installed. I'm only u
sing it to open up a com port at 19200 baud and then send and receive
data .... I can write replacement code in win32. Before I did that I
thought I would post a message here. Other than the direct WIN32 API
... Is there any non blocking serial APIs for C++ builder? Are there
any classes / forms / library routines with C++ builder that do any
serial IO ? I need a form that will ask the user for a comp port
number and display all the available comports , then I need a C++ class
that will give me non b
locking get and put character api

I'm a bit confused there, sorry. You have a C++Builder app but it was
written using an old version of Delphi?

Do you mean the COM port library you're using was written in an old
version of Delphi and the unit was included in the C++Builder project?

If so, it should be fairly easy to find a newer version or a new
replacement version of the library, which will work with a modern
version. I strongly doubt you need to write your own code, fun though
it might be :)
David Millington

Posts: 257
Registered: 5/29/05
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2016 8:02 AM   in response to: David Millington in response to: David Millington
By the way, is it the old TurbowPower Async Pro component?

If so, it's been open-sourced and updated and works fine in new
versions. You can find it on github here:
https://github.com/TurboPack/AsyncPro
Dan Ambrose

Posts: 87
Registered: 12/11/03
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2016 9:28 AM   in response to: David Millington in response to: David Millington
David Millington wrote:
By the way, is it the old TurbowPower Async Pro component?

If so, it's been open-sourced and updated and works fine in new
versions. You can find it on github here:
https://github.com/TurboPack/AsyncPro

Please excuse me. I made a huge mistake in the format of my post. I do not want to use TurbowPower Async Pro Please base all further communication not using it. Move on. Tell me, Does C++ builder have any basic com port wrapper classes that wrap around win 32 ? That are within the last 5 releases ? If no then I will write my own win32 code.

Dan
R Schneider

Posts: 2
Registered: 2/15/05
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 21, 2016 1:02 PM   in response to: Dan Ambrose in response to: Dan Ambrose
Dan Ambrose wrote:
David Millington wrote:
By the way, is it the old TurbowPower Async Pro component?

If so, it's been open-sourced and updated and works fine in new
versions. You can find it on github here:
https://github.com/TurboPack/AsyncPro

Please excuse me. I made a huge mistake in the format of my post. I do not want to use TurbowPower Async Pro Please base all further communication not using it. Move on. Tell me, Does C++ builder have any basic com port wrapper classes that wrap around win 32 ? That are within the last 5 releases ? If no then I will write my own win32 code.

Dan

Boost.Asio can be used with serial ports: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/overview.html
Goran Ekstrom

Posts: 149
Registered: 1/10/04
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2016 10:02 AM   in response to: Dan Ambrose in response to: Dan Ambrose
Dan Ambrose wrote:
Hello,
... I'm only using it to open up a com port at 19200 baud and then send and receive data .... I can write replacement code in win32...

Use WinAPI directly, it is not that hard once you get through the basics:

https://msdn.microsoft.com/en-us/library/ff802693.aspx
Dan Ambrose

Posts: 87
Registered: 12/11/03
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 12:44 PM   in response to: Goran Ekstrom in response to: Goran Ekstrom
That was a good reply and link you sent. I spent the last day writing an interface. It works great. Thanks...

Goran Ekstrom wrote:
Dan Ambrose wrote:
Hello,
... I'm only using it to open up a com port at 19200 baud and then send and receive data .... I can write replacement code in win32...

Use WinAPI directly, it is not that hard once you get through the basics:

https://msdn.microsoft.com/en-us/library/ff802693.aspx
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 12:03 PM   in response to: Dan Ambrose in response to: Dan Ambrose
Dan Ambrose wrote:

I have a 10 year old serial communications program that was made with an old version of C++ builder and the 3rd party async pro add on tool kit. I want to update the program with the latest version of C++ builder but cant because it was written in a very old version of Delphi. The package build files are old and it is full of so many bugs. Id like to stop using this ancient tool kit. So I can update the project to the latest C++ builder and subsequently stop keeping an old version installed. I'm only using it to open up a com port at 19200 baud and then send and receive data ....

I made a VCL component for BCB4 a long time ago that I just upgraded to RAD 2007 - which is still very old if you'd like to try it out you're welcome to give it a try. If I had a serial port and something to connect to it I would have redesigned the component quite a lot since the component is doing stuff with its worker thread that it shouldn't do and vice-a-verse and I can see by looking at it that there are some rare situations which could cause crashes - but I don't dare changing it without being able to test it.

It's not that much code so you could probably clean it up rather quickly:
http://lyncon.se/software/cppbuilder/MComPort_RAD2007.zip

Br,
Ted
kaloyan radev

Posts: 1
Registered: 2/15/18
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 15, 2018 3:06 AM   in response to: Ted Lyngmo in response to: Ted Lyngmo
hi, mate, i download this component, compile, and insert into my new project, but have not any info about how to use it. what is functions for reading, writing, flags and other info to use. can you make a simple example for most used functions and flags with this component. thanks in advance

i make a simple aplication with one combox and one buton"send" but i dont know what a function need to use and flags to use this component. here in forum can not post a picture, may be i am a new member
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: Serial Com Port
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 30, 2018 5:10 AM   in response to: kaloyan radev in response to: kaloyan radev
kaloyan radev wrote:
hi, mate, i download this component, compile, and insert into my new project, but have
not any info about how to use it. what is functions for reading, writing, flags and other
info to use. can you make a simple example for most used functions and flags with this
component. thanks in advance

i make a simple aplication with one combox and one buton"send" but i dont know what
a function need to use and flags to use this component. here in forum can not post a
picture, may be i am a new member

I really should have cleaned that code up before posting. :-)

Anyway, the idea is that you should drop the component on your form and then edit its properties. Example:
PortName  \\.\COM2
BaudRate  bd9600
ByteSize  bs8
Parity    paNo
StopBits  sb1_0

etc...

... and set the event handlers. Most events are direct translations of this: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363435(v=vs.85).aspx
Example, create an "OnRxchar" (EV_RXCHAR in the MSDN documentation) event handler to handle incomming characters.

In addition to the events described in the MSDN SetCommMask() documentation, these are available:

OnOpened - When the com port is successfully opened.
OnClosed When it's closed.

OnError - For misc. errors. Use GetLastError() to figure out what's happened.

Use the Open() method to open the com port and Close() to close it.

Use the
DWORD Write(LPVOID lpBuffer, DWORD nNumberOfBytesToWrite )
method to send data. It returns the number of bytes actaully sent.

Use the
DWORD Read( LPVOID lpBuffer, DWORD nNumberOfBytesToRead )
method to read data. It returns the number of bytes actaully read.

Br,
Ted

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02