private void ParseInquiryQueue() { PTJ_Configuration board_config = new PTJ_Configuration(); char[] GetConfigCharSeparators = new char[] { ' ', '\r' }; List<InquiryResult> BT_device = new List<InquiryResult>(); while (UART_MSG.Count > 0) { string str = UART_MSG.Dequeue(); string[] words = str.Split(GetConfigCharSeparators, StringSplitOptions.RemoveEmptyEntries); if (words.Length >= 4) { if(words[0]== "INQUIRY") { BT_device.Add(new InquiryResult(words[1], words[2], words[3])); } } } IEnumerable<string> All_BT_Address = BT_device.Select(x => x.bt_addr).Distinct(); foreach(string addr in All_BT_Address) { Serial_WriteStringWithPause("name " + addr + "\x0d"); Clear_ReadLine_Timeout_Flag(); Start_Read_OneLine_Queue(); while ((Check_Read_OneLine_Done() == false) && (Get_ReadLine_Timeout_Flag() == false)) // Loop until either Timeout occurs or get one line { Application.DoEvents(); // let other process goes on } if (UART_MSG.Count > 0) { AppendSerialMessageLog(UART_MSG.Dequeue() + '\x0d'); } } }
private void ParseConfigQueue() { PTJ_Configuration board_config = new PTJ_Configuration(); char[] GetConfigCharSeparators = new char[] { '=', '\r' }; while (UART_MSG.Count>0) { string str = UART_MSG.Dequeue(); string[] words = str.Split(GetConfigCharSeparators, StringSplitOptions.RemoveEmptyEntries); if (words.Length >= 2) { // Combine other splitting word,if any, into one parameter for (int index=2; index<words.Length; index++) { words[1] += words[index]; } AppendSerialMessageLog(words[0] + "/" + words[1] + '\x0d'); // Use "string content" as "property name" --> easy for extension and coding System.Reflection.PropertyInfo prop = typeof(PTJ_Configuration).GetProperty(words[0].ToLower()); prop.SetValue(board_config, words[1], null); // the following code is only for reference //object value = prop.GetValue(yourInstance, null); //prop.SetValue(yourInstance, "value", null); } } //AppendSerialMessageLog("FIN.\r"); }