This question is inspired by both the question and answer found here: Passing a Command to a Comm Port Using C#'s SerialPort Class
The question itself answered a few problems I had but raised a few other questions for me. The answer in the demonstration is as follows:
var serialPort = new SerialPort("COM1", 9600);
serialPort.Write("UUT_SEND \"REMS\\n\" \n");
For basic serial port usage. Also make note of this: To get any responses you will have to hook the DataReceived event.
My questions are as follows. Do I have to use the DataReceived event or can I use serialPort.ReadLine? What's the exact function of serialPort.ReadLine? Also do I need to use serialPort.Open() and serialPort.Close() in my application?
SerialPortimplementsIDisposable, so you should either wrap its lifetime in ausingblock or have your containing class also implementIDisposableandDispose()it using the "disposable pattern". Note, then, your containing class should be in ausingblock, etc.