Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using MSCOMM within VC++

Status
Not open for further replies.

chris2001a

Programmer
Oct 8, 2001
5
GB
Hi,

I've been trying, for a few days now, to use the MSCOMM OLE control to use the serial port on my PC. I'm trying to get&send data from one port to another one.
I have 2 Edit Boxes and 2 MSCOMM (one for each port).
Both COM have the same settings. Now to test it, I use the hyperterminal and turn a com port off.
What I don't understand is how I can receive the data and print them in the edit box(it seems it only sends them...). Also I notice that the data in the edit box are sent a bit late. I mean I have to press 2 keys to see the first one appearing in the hyperterminal.

I'd appreciate if some could send me docs, info or even code to do such thing in Visual C++.

Thanks,

Chris.
 
Chris -

Have you looked at MSDN's VCTerm example? I found it to be a good starting point.

Briefly, assuming you do not poll for data on the serial port, you will need to add a 'OnCommEvent' function with the appropriate 'Event Sink Map'. Inside of the 'oncommevent' function, after reading the data you will need to 'UpdateData(false)'.

Hope this helps you.
 
kedrew,

Ok, I'll try to find this example. (I would appreciate if you could give me alink though
happy.gif
)

I have the OnCommEvent() on both port, I'm not quite sure when it gets called. I have placed a TRACE() to see when it gets call and nothing! Well except when the connection is made not when transferring or getting data...
I know I can send data (from COM1) to a hyperterminal set on COM2 ('cos I see them on the hyperterminal). But it doesn't work the other way around...

BTW, I just found out my edit box problem which was due to the UpdateData() call I was doing.

Thanks,
Chris.
 
Chris -

Just do a search for VCTerm on 'msdn.microsoft.com' or the MSDN CD set. I'd give you the URL, but I cannot easily pull the link out of the site.

You may be missing one setup item to enable the event to trigger, at least that's what I can make out of my comments that were probably copied from VCTerm. m_commctrl is the name of the control.

Code:
// Set RThreshold property to 1. The default RThreshold value (0)
// causes the OnComm event to NOT fire when a character is detected
// in the serial port.
m_commctrl.SetRThreshold(1);

Let me know if you are still having difficulties after finding the example and I will get you a stripped down example.


 
Yeah, that was the one and my very simple app is now running.

Thanks kedrew.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top