必要に迫られないとWindows用のデスクトップアプリを作らないのでなかなかC#が上達しませんね。
マイコンとPCのやり取りにはシリアル通信が欠かせません。シリアルポートを複数使う事があったので
[C#] SerialPort クラスによる、仮想 COM ポート アクセス in C#
を参考にしてGUIアプリを作ってみました。
SerialPortProcessor クラスののReciveData()からFrom1.DataReceivedHandlerを呼び出すと指定のtextboxに入力できないのですが、いろいろサンプルを見ていたところそのままスレッドから別フォームに入力できているサンプルがあってそれをマネをして作ってもうまくできませんでした。 結局デリゲート使うしかないように思って何とか動くようになりました。
public void ReciveData() { if (myPort == null) { return; } do { try { int rbyte = myPort.BytesToRead; byte[] buffer = new byte[rbyte]; int read = 0; while (read < rbyte) { int length = myPort.Read(buffer, read, rbyte - read); read += length; } if (rbyte > 0) { mainThreadForm.Invoke(DataReceived, new SerialPortEventArgs(buffer)); } } catch (InvalidOperationException ex) { } } while (myPort.IsOpen); }