/// <summary> /// Writes an individual event to the data file /// </summary> public void WriteEvent(MMazeEvent e, string sound_file_name = "") { if (_writer != null) { string event_name = MMazeEventNamesConverter.ConvertToDescription(e.EventType); //Change the event name to the sound file name if this is a sound event if (e.EventType == MMazeEventNames.SoundCue) { event_name = sound_file_name; } string output_text = e.EventTime.ToFileTime().ToString() + "\t" + event_name; _writer.WriteLine(output_text); } }
/// <summary> /// Read incoming data from the microcontroller stream /// </summary> public MMazeEvent ReadStream() { if (MicrocontrollerStream != null && MicrocontrollerStream.CanRead) { //Create a 64-byte buffer to read data from the microcontroller Byte[] arr = new Byte[64]; //Read data from the stream try { int bytes_read = MicrocontrollerStream.Read(arr, 0, arr.Length); //Byte 2 should indicate what kind of data is coming in byte data_type = arr[2]; if (data_type == 'S') { //Byte 3 indicates the kind of event that occurred MMazeEventNames e = MMazeEventNamesConverter.ConvertShortDescriptionToMMazeEventType(Convert.ToChar(arr[3])); //Return the new event that we have read in return(new MMazeEvent(DateTime.Now, e)); } else if (data_type == 'D') { //What is the D command? } else if (data_type == 'J') { //What is the J commmand? } } catch (TimeoutException e) { return(new MMazeEvent() { EventType = MMazeEventNames.Undefined }); } } //Return null in the case that no event was read from the stream return(null); }