By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,786 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Read data from serial port .. ?

P: 1
hello guys ..

i want to perform pc to pc chatting via null modem cable.. i managed to write and sent data to serial port but how to write loops to read data from serial port ? i'm using visual c++ 2005 express editon .. below is my code ..


#pragma endregion

public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

String^ msg;
msg = textBox2->Text;
textBox1->Text = textBox1->Text + "PC 1 : " + msg + Char(13) + Char(10);

serialport1->Write( msg + Char(13) + Char(10));
textBox2->Text = "";
}

private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
serialport1->Open();
}

private: System::Void Form1_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {
serialport1->Close();
}

private: System::Void serialport1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) {


int reg1;
String^ reg2;


do {
reg1 = serialport1->ReadChar();
reg2 = reg2 + Char(reg1);
} while (reg1 != 13);

textBox1->Text = textBox1->Text + "PC 2 : " + reg2 + Char(13) + Char(10);

}
Mar 30 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.