Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Serial Port Communication in Windows XP with C++

Posted on 2007-12-03
10
Medium Priority
?
6,001 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

670 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