read temperature
button1, button2, richtexbox1, serialport1,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace serialCom
{
public partial class Form1 : Form
{
string datain;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM5"; //通信端口
serialPort1.BaudRate = 4800; //设置波特率
serialPort1.Open();//打开串口
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
datain = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
//定义返回数据函数
private void DisplayText(object sender, EventArgs e)
{
richTextBox1.Text = datain;
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
Close();
}
}
}
*************************************************************************
2.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
namespace sw
{
public partial class Form1 : Form
{
Queue<string> dataQueue = new Queue<string>(100);
int num =10;
string datain;
Boolean flag = true;
public Form1()
{
InitializeComponent();
serialInt();
InitChart();
}
private void button1_Click(object sender, EventArgs e)
{
serialSetInt();
this.timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
if (flag == true)
{
this.timer1.Stop();
serialPort1.Close();
flag = false;
button2.Text = "继续测量";
}
else
{
this.timer1.Start();
serialPort1.Open();
flag = true;
button2.Text = "暂停测量";
}
}
private void button4_Click(object sender, EventArgs e)
{
this.timer1.Stop();
Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.chart1.Series[0].Points.Clear();
updateQueue();
for (int i = 0; i < dataQueue.Count; i++)
{
this.chart1.Series[0].Points.AddXY(i, dataQueue.ElementAt(i));
}
}
private void updateQueue()
{
if (dataQueue.Count > 90)
{
//先出列
for (int i = 0; i < num; i++)
{
dataQueue.Dequeue();
}
}
for (int i = 0; i < num; i++)
{
dataQueue.Enqueue(datain);
}
this.chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(dataQueue.Max()) + 5;
//this.chart1.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(dataQueue.Min()) +5;
}
private void serialSetInt()
{
serialPort1.PortName = comboBox1.Text;
serialPort1.Open();
serialPort1.BaudRate = int.Parse(comboBox2.Text);
}
private void serialInt()
{
string[] portList = System.IO.Ports.SerialPort.GetPortNames();
for (int i = 0; i < portList.Length; ++i)
{
string name = portList[i];
comboBox1.Items.Add(name);
}
string[] BaudRateList = { "1200","2400", "4800", "9600","19200","38400","57600","115200" };
for (int i = 0; i < BaudRateList.Length; i++)
{
comboBox2.Items.Add(BaudRateList[i]);
}
}
private void InitChart()
{
//定义图表区域
this.chart1.ChartAreas.Clear();
ChartArea chartArea1 = new ChartArea( );
this.chart1.ChartAreas.Add(chartArea1);
//定义存储和显示点的容器
this.chart1.Series.Clear();
Series series1 = new Series( );
this.chart1.Series.Add(series1);
//设置图表显示样式
this.chart1.ChartAreas[0].AxisY.Minimum = 260;
this.chart1.ChartAreas[0].AxisY.Maximum =360;
this.chart1.ChartAreas[0].AxisX.Interval = 5;
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart1.Series[0].Color = Color.Red;
this.chart1.Series[0].ChartType = SeriesChartType.Line;
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
datain= serialPort1.ReadExisting();
}
}
}
***********************************************************************
3.
read temperature的更多相关文章
- [LeetCode] Rising Temperature 上升温度
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- BZOJ2276: [Poi2011]Temperature
2276: [Poi2011]Temperature Time Limit: 20 Sec Memory Limit: 32 MBSubmit: 293 Solved: 117[Submit][S ...
- leetcode-Rising Temperature
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- Application to find the maximum temperature in the weather dataset
import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop. ...
- Leetcode 197. Rising Temperature
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- Temperature hdu 3477
Temperature Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- [SQL]LeetCode197. 上升的温度 | Rising Temperature
SQL架构 Create table If Not Exists Weather (Id int, RecordDate date, Temperature int) Truncate table W ...
- Raspberry pi connect temperature and humidity to onenet (移动云平台)
工具 树莓派3 modelB 一个 dht11温湿度传感器一个 onenet平台 安装好requests库的python(一定要安装好不然代码不能正确运行,可以参考我的另一篇博文点击打开链接) 树莓 ...
- STM32 F4 ADC DMA Temperature Sensor
STM32 F4 ADC DMA Temperature Sensor Goal: detecting temperature variations using a temperature senso ...
- [SQL]197. Rising Temperature
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
随机推荐
- pandas 常用清洗数据(三)排序,去重
1.排序 DataFrame 按照Index排序 Series.order()进行排序,而DataFrame则用sort或者sort_index或者sort_values 2.去重, dt = dt. ...
- eclipse jvm配置
Eclipse设置JVM参数:->Run Configurations ->VM arguments,如下:
- java集合: ArrayList源码浅析
ArrayList 是一个动态数组,线程不安全 ,允许元素为null. ArrayList的数据结构是数组,查询比较方便. ArrayList类的接口 public class ArrayList&l ...
- leetcode 数组类型题
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h& ...
- 使用ffmpeg解码 需要注意的内存泄漏问题
说说项目中遇到的两点失误: 1. AVFrame结构,av_frame_alloc申请内存,av_frame_free释放内存.容易混淆的是av_frame_unref,它的作用是释放音视频数据资源, ...
- Allowing GPU memory growth
By default, TensorFlow maps nearly all of the GPU memory of all GPUs (subject to CUDA_VISIBLE_DEVICE ...
- minSdk(API 26) > deviceSdk(API 19)解决方式
运行项目时出现“minSdk(API 26) > deviceSdk(API 19)”的提示,因为我用的是手机是sdk(API19)的,而项目要求是最低版本是minSdk(API 26),在我的 ...
- PHP20-challenge10
今天咩,说一个关于php的题目,里面主要主要牵扯到截断的知识点,这让我多了解了一些机制. 1.截断 截断,简单来说就是16进制的00,代表空.其实,那些输出语句函数就是凭借语句后面这个我们看不 ...
- Meta-Analysis
meta-analysis是用统计的概念与方法,去收集.整理与分析之前学者专家针对某个主题所做的众多实证研究,希望能够找出该问题或所关切的变量之间的明确关系模式,可弥补传统的Review Articl ...
- PHP-自动加载原理分析
说起PHP的自动加载,很多同学可能都会想到各种框架的自动加载功能,PHP规范中的PSR0和PSR4原则,Composer的自动加载功能等等,这些都为我们的开发提供了很大的方便. 那么PHP自动加载的前 ...