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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Serial Communication

Status
Not open for further replies.

spooky7

Technical User
Apr 19, 2002
3
GR
Hi,Iam new to programming in Visual C++.I am trying tobuild a programm which sends string to serial port.I have managed to open and configure the serial port.A friend of mine wrote a code for me which send integers to serial port.Below is this code.

int CMC35ProjectDlg::Send(BYTE data)
{
///////////
//Begin
//////////

//Send Data to serial Port

DWORD dwBytes=0;
BYTE d=data;
int ret=d;
BYTE* sbuf=&d;
BOOL stest=WriteFile(hcom,sbuf,1,&dwBytes,NULL);

if ((stest&&dwBytes)==FALSE)
{
MessageBox("Connection between your PC and MC35 device connot be establish.\nPlease try again later.\nCheck the serail cabel.\n).",
"Error!",MB_OK | MB_ICONSTOP);
ret=-1;

}
return ret;

//////
//End
//////

}

Do you have any idea how to wrtie a function which sends strings to serial port?

Please help.

Thank you in advance

X - The truth is out there.
 
Send(char *szBuf)
{
...
WriteFile(hcom, szBuf,strlen(szBuf),,&dwBytes,NULL);
...
}
 
Jeffray ,
Thank you for your help.I managed to write a function which sends string to serial.The code I wrote is below.


int CMC35ProjectDlg::Send(CString szBuf)

{
///////////
//Begin
//////////

//Send Data to serial Port

DWORD dwBytes=0;
// BYTE d=data;
// int ret=d;
int ret;
// BYTE* sbuf=&d;
BOOL stest=WriteFile(hcom,szBuf,strlen(szBuf),&dwBytes,NULL);

if ((stest&&dwBytes)==FALSE)
{
MessageBox("Connection between your PC and MC35 device connot be establish.\nPlease try again later.\nCheck the serail cabel.\n(ËÜèïò êáôÜ ôçí åêôÝëåóç ôçò óõíÜñôçóçò send).",
"Error!",MB_OK | MB_ICONSTOP);
ret=-1;

}
return ret;

//////
//End
//////
}

Thank you !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top