Solved

Serial Port Communication in Windows XP with C++

Posted on 2007-12-03
10
5,999 Views
Last Modified: 2012-06-21
I need to perform serial port communications in a program developed in C++.

The solutions should provide functions or methods to configure, open, read from, write to and close the serial port.

The computers I'm using run Windows XP. I'm using Visual C++ 6.0 for development, but, if possible, I'd like to have a generic solution that can be used with other C++ compilers.
0
Comment
Question by:gandhirs
[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
  • 6
  • 4
10 Comments
 
LVL 7

Accepted Solution

by:
lucky_james earned 250 total points
ID: 20395313
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 20395321
0
 

Author Comment

by:gandhirs
ID: 20395643
I tried the http://www.codeproject.com/system/SerialPortComm.asp

I downloaded the source code, but I don't know how to use it! The information on that page seems to explain how the class was implemented, but it doesn't explain how to use it.

I wrote this code but I receive an execution error: Debug error: DAMAGE: after Normal block (#46) at 0x004419F0.

I don't know what to put in the argument of the constructor of the class CSyncSerialComm

#include "SyncSerialComm.h"

void main()
{
      CSyncSerialComm serial("COM3");
      //serial.Open();
      //serial.Close();
}
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 7

Expert Comment

by:lucky_james
ID: 20397202
i am not able to access that site.....the sooner i will be able to access its code, i will be in a better position to tell you. I am facing some sort of connectivity problem. :(


>>I don't know what to put in the argument of the constructor of the class CSyncSerialComm

Meanwhile, you can look into the constructor and see where this argument is being used.


>>I wrote this code but I receive an execution error: Debug error: DAMAGE: after Normal block (#46) at 0x004419F0.

plz tell which statement is causing the error.
0
 

Author Comment

by:gandhirs
ID: 20397433
The code of the constructor seems to accept a string as argument:

CSyncSerialComm::CSyncSerialComm(const char *pszPortName)
      : m_hSerialComm(INVALID_HANDLE_VALUE)
{
      assert(pszPortName);

      m_pszPortName = new char[strlen(pszPortName)];
      strcpy(m_pszPortName, pszPortName);
}

The statement that causes the error is

CSyncSerialComm serial("COM3");

since the other statements are commented
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 20398450
>>I wrote this code but I receive an execution error: Debug error: DAMAGE: after Normal block (#46) at 0x004419F0.

http://elliottback.com/wp/archives/2004/10/23/damage-after-normal-block/

It says this can be a buffer overflow.

Can you check under which code of the constructor is this failing....

regards,
James
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 20398629
>>m_pszPortName = new char[strlen(pszPortName)];
would be better if :
m_pszPortName = new char[strlen(pszPortName) * sizeof(char)];

Hey, till now i was not able to  download the code from
http://www.codeproject.com/system/SerialPortComm.asp

but i saw the code at :
http://ontrak.net/mfc.htm

and it has the sample application code as well.

try to download the code from above link.(it is given on the link  "VISUAL C++ EXAMPLE" on the bottom of the page.)


Hope it helps.

James
0
 

Author Comment

by:gandhirs
ID: 20398813
m_pszPortName = new char[strlen(pszPortName) * sizeof(char)];

haven't eliminated the error. It makes sense since sizeof(char) is 1.

But you gave me an idea. I tried

m_pszPortName = new char[strlen(pszPortName) +1];

and the error disappeared
0
 

Author Comment

by:gandhirs
ID: 20398984
The code at :
http://ontrak.net/mfc.htm

is not adequate to my purposes because It uses MFC.
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 20399043
gud, :)
do let me know if you face any problem......


regards,
James
0

Featured Post

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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

630 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