i would like to implement a rather simple function, that outputs the byte array of a serial port, e.g.
byte[] o = readAllDataFromSerialPort();
Implementing the actual serial port functions is done. I use the serial port to receive some data and process the data through the event DataReceived.
sp = new SerialPort(portname, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
sp.Handshake = Handshake.None;
sp.DataReceived += new SerialDataReceivedEventHandler(serialDataReceived);
I check the received data for an "message end"-package in order to then close the serial port, so sth. like
if (data = "UA") sp.Close()
So basically what I would like to do is wait for the closure, before giving back the data, so that on the top level view the program doesn't progress, until the data has arrived. However I cannot wrap my head around as to how I implement this "waiting" in an effective and elegant way, as I'm relying on events for my data. Any hints or clues or examples would be much appreciated.