private void DisplayValue(string sVal) { try { ushort v = ushort.Parse(sVal); if (v < 0 || v > maxPhotoVal) { return; } SensorData data = new SensorData(DateTime.Now, v); photoDatas.Add(data); InsertDataToDB(data); TxtSensorCount.Text = photoDatas.Count.ToString(); PgbPhotoRegistor.Value = v; LblPhotoRegistor.Text = v.ToString(); string item = $"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}\t{v}"; RtbLog.AppendText($"{item}\n"); RtbLog.ScrollToCaret(); ChtSensorValues.Series[0].Points.Add(v); ChtSensorValues.ChartAreas[0].AxisX.Minimum = 0; ChtSensorValues.ChartAreas[0].AxisX.Maximum = (photoDatas.Count >= xCount) ? photoDatas.Count : xCount; if (photoDatas.Count > xCount) { ChtSensorValues.ChartAreas[0].AxisX.ScaleView.Zoom( photoDatas.Count - xCount, photoDatas.Count); } else { ChtSensorValues.ChartAreas[0].AxisX.ScaleView.Zoom(0, xCount); } if (IsSimulation == false) { BtnPortValue.Text = $"{serial.PortName}\n{sVal}"; } else { BtnPortValue.Text = $"{sVal}"; } } catch (Exception ex) { RtbLog.AppendText($"Error : {ex.Message}\n"); RtbLog.ScrollToCaret(); } }
private void LoopPublish() { while (true) { SensorInfo value = SensorFaker.Generate(); CurrValue = JsonConvert.SerializeObject(value, Formatting.Indented); BrokerClient.Publish("home/device/data", Encoding.Default.GetBytes(CurrValue)); this.Invoke(new Action(() => { RtbLog.AppendText($"Published: {CurrValue}\n"); RtbLog.ScrollToCaret(); })); Thread.Sleep(1000); } }