Hi
I am doing a messaging application using Visual C++ window form application.
Sometimes I can't receive a whole message from the sender. If i type short sentence like "123456", it can be shown properly. But, if i type a quite long sentence like "12345678912345 6789", it can't shown a correct message, can't show exactly the whole message.
here is my code:
I am doing a messaging application using Visual C++ window form application.
Sometimes I can't receive a whole message from the sender. If i type short sentence like "123456", it can be shown properly. But, if i type a quite long sentence like "12345678912345 6789", it can't shown a correct message, can't show exactly the whole message.
here is my code:
Code:
//transmission:
String^ message;
String^ message1;
String^ name = this->serialPort1->PortName;
// grab text and store in send buffer
message = this->richTextBox2->Text;
// write to serial
if(this->serialPort1->IsOpen)
this->serialPort1->WriteLine(message);
this->serialPort1->DiscardOutBuffer();
this -> serialPort1 -> DiscardInBuffer();
}
//Receving code:
demessage = " ";
ciphertext = " ";
try
{
ciphertext = this->serialPort1->ReadExisting();
this -> Invoke (gcnew System::EventHandler(this, &Form1::DisplayText));
}
catch(TimeoutException^)
{
MessageBox::Show("Timeout Exception");
}
private: System::Void DisplayText (System::Object^ s, System::EventArgs^ e)
{
this -> richTextBox1 -> Text = String::Empty;
this->richTextBox1->AppendText(ciphertext);
}
Comment