Solved

Borland C++ MSComm

Posted on 2007-03-19
8
1,211 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

757 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

20 Experts available now in Live!

Get 1:1 Help Now