A
A
AlexSer2018-08-21 13:43:53
C++ / C#
AlexSer, 2018-08-21 13:43:53

How to continuously read data on Serial Port?

Are there any experts in Visual studio C++ windows application?
How to organize continuous execution of a function?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {	
  this->serialPort1->PortName = this->ComboboxComs->Text;
  this->serialPort1->BaudRate = 9600;
  this->serialPort1->Open();
  this->richTextBox1->Text = "Соединение установлено";
  this->progressBar1->Value = 100;
  this->label2->Text = "Соединен";
  this->button1->Enabled = false;
  
  while (this->serialPort1->IsOpen)
  {
    this->richTextBox1->Text = this->serialPort1->ReadLine();
  }
}

Thus, it reads only once the data of the COM port, how to organize it to read the data constantly, while there is a connection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-08-21
@res2001

Apparently it is necessary that this->serialPort1->IsOpen be constantly true, or change the condition in while().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question