Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Borland C++ MSComm

Posted on 2007-03-19
8
Medium Priority
?
1,265 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
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.

636 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