A
A
A2D22015-11-25 23:19:10
C++ / C#
A2D2, 2015-11-25 23:19:10

C++ how to assign value to one variable while changing another?

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e)
{
 if(this->serialPort1->IsOpen){
 try{
 this->label2->Text=this->serialPort1->ReadLine();
 }

1) This piece of code reads data from the serial port on each press, but how to make the data output on each change?
2) How to assign this value to another variable?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-11-25
@vilgeforce

You need to read the data as soon as it arrives. The above approach, to put it mildly, is not suitable. Which data variable do you want to assign? The port does not guarantee that everything sent "in one go" will also be received in one piece.

D
dordzhiev, 2015-11-26
@dordzhiev

Catch the DataReceived event and read the data in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question