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的更多相关文章

  1. [LeetCode] Rising Temperature 上升温度

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  2. BZOJ2276: [Poi2011]Temperature

    2276: [Poi2011]Temperature Time Limit: 20 Sec  Memory Limit: 32 MBSubmit: 293  Solved: 117[Submit][S ...

  3. leetcode-Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  4. 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. ...

  5. Leetcode 197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  6. Temperature hdu 3477

    Temperature Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. [SQL]LeetCode197. 上升的温度 | Rising Temperature

    SQL架构 Create table If Not Exists Weather (Id int, RecordDate date, Temperature int) Truncate table W ...

  8. Raspberry pi connect temperature and humidity to onenet (移动云平台)

    工具 树莓派3 modelB 一个 dht11温湿度传感器一个  onenet平台 安装好requests库的python(一定要安装好不然代码不能正确运行,可以参考我的另一篇博文点击打开链接) 树莓 ...

  9. STM32 F4 ADC DMA Temperature Sensor

    STM32 F4 ADC DMA Temperature Sensor Goal: detecting temperature variations using a temperature senso ...

  10. [SQL]197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

随机推荐

  1. 解决SMARTFORMS文本编辑器不能打开

    在DEV打开SMARTFORMS文本编辑器时,出现如下错误 由于宏安全设置,无法找到宏或宏被禁用. 解决方法如下: 在DEV环境新建程序后输入如下代码执行即可. *&------------- ...

  2. hashcode() equals()

     介绍一. hashCode()方法和equal()方法的作用其实一样,在Java里都是用来对比两个对象是否相等一致,那么equal()既然已经能实现对比的功能了,为什么还要hashCode()呢? ...

  3. git 使用说明

    git使用的一些说明 关于新用户1. 到优居客群里下载git客户端2. 安装之后打开git bash3. 生成密钥,执行如下命令:    ssh-keygen -t rsa -C "你的邮箱 ...

  4. vue element-ui怎样提炼一个自己写的js当作公共js

    vue element-ui怎样提炼一个自己写的js当作公共js请教一下各位大神,我刚刚触摸vue element-ui几天,写的一个清晰检索的input框,现在需当作项目公共的部分,可遭需的html ...

  5. poj3104(二分)

    题目链接:http://poj.org/problem?id=3104 题意:有n件衣服,每一件含有a[i]单位的水,每分钟衣服可以自然蒸发1单位的水,也可以在烘干器上每分钟烘干k单位的水,问将所有衣 ...

  6. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛----随手记录帖

    这是跟学长学姐组队来打的最爽的一次比赛了,也可能是互相组队最后一次比赛了,南哥和楼学姐,省赛之后就退役了,祝他们能考研和面试都有happy ending! 虽然最后没有把F题的n^2约数的数学题写完, ...

  7. TOJ3955: NKU ACM足球赛(并查集+map+细节题)

    时间限制(普通/Java):5000MS/15000MS     内存限制:65536KByte 描述 NKU ACM最近要举行足球赛,作为此次赛事的负责人,Lee要对报名人员进行分队.分队要遵循如下 ...

  8. word 2016 加载 mathtype

    1.加载wold: 首先打开word,选择选项-------加载项------管理(A),选择word加载项,点击转到 这儿显示的是我已经添加过的所以显示的有. 2.点击添加,找到你的mathtype ...

  9. f5时间设置

    方法一:NTP(推荐) 注:修改ntp server后大约需要10分钟左右才能同步成功. 查看ntp状态: 方法二:手动修改

  10. EasyUI Dialog 对话框 关闭事件

    在  $('#×××').dialog('close');  执行后触发 $(function(){ $("#titledialos").dialog({ onClose: fun ...