public void CloseSerialPort() { serialPort.DiscardInBuffer(); //バッファに蓄積されたデータを全て破棄 if (serialPort.IsOpen) { serialPort.Close(); } }