Reputation: 519
I'm trying to write winforms that reads data from Arduino board. CLR application does not permit threads, so I have to solve this problem with a listener. How can I trigger Listener when a data is available at the port, by using WaitCommEvent
My code is like example2 on this site
Upvotes: 0
Views: 480
Reputation: 1082
Use the DataReceived of your COM Port. User ReadLine method in your com port, example :
private:
System::Void comPort1_DataReceived(System::Object ^sender, System::IO::Ports::SerialDataReceivedEventArgs ^e)
{
System^ data = comPort1->ReadLine();
this->Invoke(gcnew EventHandler(processData));
}
System::Void processData(System::Object ^sender, System::EventArgs ^e)
{
// data receive
}
Using .Net, read this tutorial : http://www.c-sharpcorner.com/uploadfile/eclipsed4utoo/communicating-with-serial-port-in-C-Sharp/.
Upvotes: 1