Author Topic: How do you use the Serial Port flush method??  (Read 14021 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
How do you use the Serial Port flush method??
« on: January 20, 2012, 07:37:28 am »
Hi All,
Trying to bomb proof a bit of software in C# and am trying to ensure the buffer is not holding any nasty's I have done a:
myComPort.DiscardOutBuffer();
When opening the port but am now looking to flush the buffer before a command is sent. Is
myComPort.DiscardOutBuffer(); the correct way as I have seen
mention of a Flush command on MSDN is this seen as the better way or is DiscardOut the way to go?

Glenn

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How do you use the Serial Port flush method??
« Reply #1 on: January 20, 2012, 10:43:18 am »
It depends on what you want:

SerialPort.DiscardOutBuffer Method
Discards data from the serial driver's transmit buffer.

SerialPort.Flush Method
Sends any data waiting in the send buffer of this SerialPort and clears the buffer.

Jan