Solved

Serial Port Communication

Posted on 2002-05-22
8
1,078 Views
Last Modified: 2013-11-20
Hello,

Project: Create a dialog app to receive serial port input from a microcontroller and display in your GUI.

The Dialog app is created and ready for incorporation of  communication methods.

So,
What is the easiest way to communicate over the serial port using MFC? I have found various classes online and am aware that ActiveX may be a solution but I dont know which to go for / what the benefits of each are.

One ability I will need is to ignore a significant portion of the incoming messages. They will be in the form of several text numbers which I will process, but I only need them at set intervals of a 1/2 second or so.

I'll need guidance in the form of online documentation or code presented here also.

Thanks to everyone.
0
Comment
Question by:jkelly061597
[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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7028084
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwbgen/html/msdn_serial.asp ("Serial Communications in Win32") - this is the IMHO most comprehensive article on this issue, and it comes with sample code.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7028089
BTW - you might want to check these out, also:

http://www.codeguru.com/network/serial.shtml ("CSerial - A C++ Class for Serial Communications")

http://www.codeguru.com/network/serialport.shtml ("A communication class for serial port")
0
 
LVL 3

Expert Comment

by:Crius
ID: 7028122
Reusing the VCTERM code from the MSDN library would be one of the easiest ways of using MFC to handle comport communications.

The code to either use or ignore incoming strings/values is up to your own switch statements or code, and not actually part of the MFC code/ActiveX/COM control.

Most of the classes in the sample program you won't actually need, but you will need to look at the CMainFrame for samples of how to use the CommCtrl, and you will need to add in the CCommCtrl COM object.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
Mazen earned 200 total points
ID: 7030014
Hi,
 I found the ActiveX "Microsoft Communcations Control" very useful . So i suggest that you use it.
Here is the code for it:
When you first add the ActiveX for your application, first add a variable to it and let be of type control.

Then double click on the icon that shows on your dialog, this will ask you to add a function. Select ok for this function. This function will be called whenever  a character is found at the serial port.
In initdailog put the following code:
{
m_Comm.SetCommPort(1); // or any other port
m_Comm.SetSettings("4800,n,8,1"); // you can change the baud rate
m_Comm.SetPortOpen(TRUE);
}
And in the Fuction created add this:
{
COleVariant myVar;
myVar = m_Comm.GetInput();
CString Inputdata( myVar.bstrVal );
mystring+= Inputdata; // this string has the input data, you can manipulate it

}


to add the activex for your application click on :
project -> Add to Project -> Components and Controls
Choose "Registered ActiveX Controls"


As Crius has mentioned before , you have to add the code for ignoring some data.

Regards

Mazen
0
 

Author Comment

by:jkelly061597
ID: 7065948
Thanks all, I ended up using straight active x as my solution
0
 

Expert Comment

by:gaohuanzx
ID: 7873776
Can u give me a specific answer, where to add the activex. do u mean build a new project and then add the project to my own application?
0
 

Expert Comment

by:gaohuanzx
ID: 7873854
Can u give me a specific answer, where to add the activex. do u mean build a new project and then add the project to my own application?
0
 
LVL 1

Expert Comment

by:Mazen
ID: 7875859
Hi gaohuanzx,
  If you look at the menu of VC++ program, you will see the word  "project".(you know, next to :file - edit ...)
Click on it and then click "Add to Project -> Components and Controls".
Your application has to be dialog based inorder to be able to add this activex.
If you need any more help, just ask.
Best Regards,
  Mazen
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 137
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 123
sumDigits challenge 9 178
NotAlone Challenge 20 93
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

734 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