Solved

Borland C++ MSComm

Posted on 2007-03-19
8
1,218 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 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
 
LVL 45

Expert Comment

by:Kdo
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
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 the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now