I have a class that talks to a serial port and I want to mimic a Get function. The problem is, the serial port feeds in raw data which may or may not come. It also has to be processed and parsed. For example, if I want to get a Person object, the serial port class does this.
A method to send the request for a Person.
Something happens on the serial device... it might respond, it might not.
Bytes come in through an event handler that processes and parses all data, and eventually a Person object.
I want to wrap that all up into a "GetPerson" function but I'm having difficulty connecting steps in 1 and 3. Step 3 is a function that is always running and is more of a generic parser.
Can someone help me design/structure this?
Edit: Also I've tried using a class variable and checking via while statement as shown below but it doesn't check the variable during the while statement for whatever reason:
private Person person;
public Person GetPerson()
{
...
while (person == null) {}
return person;
}