?
Solved

Borland C++ MSComm

Posted on 2007-03-19
8
Medium Priority
?
1,284 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
  • 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 46

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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

830 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