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 communication....

Status
Not open for further replies.

isaisa

Programmer
May 14, 2002
97
IN
Hi...
I am trying to send the data [sequence of bytes] through COM1 port to the modem. My logic on the receiving side deals with counting the characters received.

For example:
On the Sender side : I want to send 10 characters byte by byte. My Sender will send "10" as length string with say "$" as a delimiter and then send the 10 characters.
On the Receiver side : The program will receive "10" first, will convert it to integer 10 and will store it in a variable say int len. Then the program will start receiving the actual data till 10 characters are received.

I am using the blocking function of windows. So the receiving program will wait till the input buffer receives the nect byte.

My problem is that i am loosing data sometimes. So my counter on the receiving side does not matches to 10 in the above case. It always keep short of the bytes that are lost because of some reason. In this case my program keep on waiting for time till the bytes is received in the input buffer or for infinite time if no character is received.

I need a way to come out of this situation. Please help.

I thought of using threads but again the thread will consume the CPU time and may lead to the loss of data.

Also suggest if i am using a wrong approach in sending and receiving data between two external modems.

Thanks for help in advance.

Sanjay
 
I assume the 10 characters follow after each other quickly. So you can set a short receive timeout before the number of expected characters arrive. If this timeout expires, send some code of transmission error to the sender and redo the whole thing.
Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top