Home > Net > The order of the serial port receive events
The order of the serial port receive events
Time:09-25
I have a serial device to connect a serial port, as long as open the serial port, the device will continue to send real-time data to come over, if, in accordance with the following code, then I when I received the data value is 0 or 1, what is the program execution order, small white recently confuse the order of events, also please bosses to reassure
Private void Button3_Click_1 (object sender, EventArgs e) { Int I=0; Port. The method DataReceived +=port_DataReceived; Port. The open (); i++; }
Private void Button3_Click_1 (object sender, EventArgs e) { Int I=0; Port. The method DataReceived +=port_DataReceived; Port. The open (); i++; } This code, you are opening a serial port and bind a serial port receive events, each serial data to perform port_DataReceived here the code As you write code, you order a button3, after opening a serial port, at that time I=1, and I again is to define the button inside of you, is you no matter how many times I, I still=1 And serial events will be binding for many times, a serial port data, you can perform multiple port_DataReceived, see your button several times, port_DataReceived will be executed several times
CodePudding user response:
Can change to this
Int I=0; Private void Button3_Click_1 (object sender, EventArgs e) { Port. The method DataReceived +=port_DataReceived; Port. The open (); }