Solved

Borland C++ MSComm

Posted on 2007-03-19
8
1,225 Views
Last Modified: 2013-11-17
hello experts,

i'm trying to get the MSComm control to work in borland c++ (5)

but i can't figure out how to cast from an OleVariant to an AnsiString.
i tried to add the MSComm input to a Memo, but that didnt work:
        Memo1->Text+= Com1->Input;

how can i add the text or bytes from the Com1->Input to a string, or even better a byte array?


thanks,

Mark
0
Comment
Question by:Mark_FreeSoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 18749158
Actually, MSComm is some badly documented control that I wouldn't use if I had the choice. The VARIANT in questio is most likely of VT_BSTR, so you should be able to read OLE strings (BSTRs) from it.

As an alternative, take a look at http://msdn2.microsoft.com/en-us/library/ms810467.aspx ("Serial Communications in Win32") which describes all aspects of dealing with serial comm the API way and comes with plenty of sample code that you can use with Borland also. It isn't that hard, and definitely easier than using MSComm.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 18749183
See also http://www.tetraedre.com/advanced/serial.php - that contains a class (also for Borland) that can

Tserial()       Object creation
~Tserial()       Object destruction
int connect (char *port_arg, int rate_arg, serial_parity parity_arg)       Serial port setup and start of connection

    * port_arg : "COM1", "COM2", ...
    * rate_arg : 19200, 9600, ...
    * parity_arg : spNONE, spODD, spEVEN

Returns 0 if no error occured

void sendChar (char c)       Send a char on the serial line. Blocks until it is sent

void sendArray (char *buffer, int len)       Send an array of char on the serial line. Blocks until it is sent

char getChar (void)       Returns the next char from the input buffer. Blocks if no data is available

int getArray (char *buffer, int len)       Returns an array from the input buffer.
Blocks until (some) data are available. The returned parameter indicates how many bytes have been read

int getNbrOfBytes (void)       Returns the number of bytes waiting in the input buffer

void disconnect (void)       Disconnect the serial port
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 18749733


thank you so much for the fast answers!


gonna try it out tomorrow when i'm at my work again.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:Kent Olsen
ID: 18749946

Hi Mark,

MSComm is not a Borland class.  In fact, I don't believe that Borland provides a class for handling serial communications with their CPPBuilder 5.x product.

Since you're already going outside of the Borland libraries, consider taking the more direct approach.  The
Win32 API CreateFile and the Win32 communications functions are probably the best choice from within CPPB.
The Microsoft WinSDK help files should provide detailed instructions for configuring the serial port for your needs.


Good Luck,
Kent
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 18758821
>>Com1->Input
if this is a buffer of some kind then it should work IF the component (Com1) is working...
Anyway this has to work:
Memo1->Lines->Add(Com1->Input);
One suggestion:
The TComPort component from http://www.winsoft.sk
Easy to use and never failed me. I'm working with it for many years now...
Comercial but with trial period, along with full source code...

George Tokas.
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 18759059


jkr,

the link you gave http://www.tetraedre.com/advanced/serial.php
links to the old version
the multithreaded version is a better one to link to,
i'm using it and it works perfect!



gtokas,

since it's not for private use, and there is virtually no budget, paying for somthing that can be done free is not an option



mark
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 18760112
$35 is too much??
Try the component and see first.
George Tokas.
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 18775067

jkr,

i used another serial component from the same publisher ( event driven),
and it works perfectly.

thanks!!


motivation for points assignment:

although it was not a direct answer to my question,
jkr provided a whole new way to accomplish what i wanted to archieve (serial communication)

the serial2 component from the same developer is a better one, it is event driven (and multithreaded)
and thus doesnt block your program from running while waiting for serial input

link to the multithreaded component:
http://www.tetraedre.com/advanced/serial2.php
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question