/// <summary> /// 回调函数 接收到串口发送的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void qSerialPort_Completed(object sender, string data) { try { FoodCommand foodCommand = Analysain.FromJson_foodCommand(data); /* if (foodCommand.conmmand.Equals("temp")) * { * //MessageBox.Show(data); * //this.ok1.Text = foodCommand.message.Substring(0, 2); * //this.ok2.Text = foodCommand.message.Substring(2, 2); * * Dispatcher.BeginInvoke((ThreadStart)delegate() * { * this.ok1.Text = foodCommand.message.Substring(0, 2); * this.ok2.Text = foodCommand.message.Substring(2, 2); * saveToCloud("Temperature", this.ok1.Text + " °C"); * saveToCloud2("Humidity", this.ok2.Text + " %"); * }); * }*/ if (foodCommand.conmmand.Equals("weight") && foodCommand.message.Substring(0, 1).Equals("-")) { //MessageBox.Show(foodCommand.message.Substring(1)); dealWith(Int32.Parse(foodCommand.message.Substring(1))); // MessageBox.Show(foodCommand.message); } } catch (Exception e) { } finally { } }
public void qSerialPort_Completed(object sender, string data) { // MessageBox.Show(data); this.Dispatcher.BeginInvoke(new Action(delegate { if (!text1.Text.Equals("Pass")) { text1.Text = " "; id = " "; lampBox1.Text = " "; lampBox.Text = " "; } try { FoodCommand foodCommand = Analysain.FromJson_foodCommand(data); if (foodCommand.conmmand.Equals("barcode") || foodCommand.conmmand.Equals("weight")) { if (foodCommand.conmmand.Equals("barcode")) { text1.Text = "Pass"; id = foodCommand.message; } if (foodCommand.conmmand.Equals("weight")) { lampBox.Text = foodCommand.message; } if (text1.Text != " " && lampBox.Text != " " && text1.Text.Equals("Pass")) { foreach (FoodMessage lists in list) { // MessageBox.Show(lists.foodName); if (lists.foodId.Equals(id)) { // MessageBox.Show(lists.foodName); lampBox1.Text = lists.foodName; FoodMessage food1 = new FoodMessage(lists.foodName, lampBox.Text, lists.foodId, lists.foodType, lists.day, lists.state); list2.Add(food1); SaveToCloud(lists.day.ToString(), lists.foodName, lampBox.Text, lists.foodType, lists.state); text1.Text = "Complete"; } } } } if (foodCommand.conmmand.Equals("weight")) { text.Text = foodCommand.message; // MessageBox.Show(text.Text); } } catch (Exception e) { } }), null); }