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

Problem with Serial Port communication

Status
Not open for further replies.

blink182

Programmer
Sep 7, 2001
4
SG
i am trying to send/receive data between 2 computers connected by a serial cable using VC++. I make use of CreateFile,WriteFile and ReadFile to do this.I am able to write to the serial port but i have trouble reading the data from the serial port using another PC. The only data that i can get is garbage values with no meaning.Furthermore, it seems that the number of bytes read is greater than the number of bytes i had written.

Here is some sample code i used:

int SerialConnection::Send(const char* send_block, int length)
{
DWORD bytes_written;
for (int i=0;i<length;i++)
{
WriteFile(m_Port,send_block,length,&bytes_written,NULL);
send_block++;

if (bytes_written <1)
{
AfxMessageBox(&quot;Serial Port Error!!!&quot;);
break;
}

}
return bytes_written;
}

int SerialConnection::Receive(CString &recv_block)
{
DWORD bytes_read=0;
char buffer[1000];
CString b;

ReadFile(m_Port,buffer,999,&bytes_read,NULL);
buffer[bytes_read]=0;
recv_block=buffer;

return bytes_read;
}

I hope someone can give some pointers on why this is happening. Thanks Alot.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top