需要帮助以获得seriell端口的实时图表 [英] Need help for a real time graph for seriell port
本文介绍了需要帮助以获得seriell端口的实时图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i需要实时情节帮助。
我找不到有什么问题。
什么是忘记?
Hello
i Need help for a realtime plot.
What is wrong i dont found.
What is Forget?
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;
using System.IO.Ports;
using System.Management;
using System.Windows.Forms.DataVisualization.Charting;
namespace Graphs
{
public partial class Form1 : Form
{
private string data;
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit(); //Programm schliessen
}
private void button1_Click(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBox1.Items.Add(port);
}
}
string t;
private void button2_Click(object sender, EventArgs e)
{
t = comboBox1.Text.ToString();
sErial(t);
}
SerialPort sp;
void sErial(string Port_name)
{
sp = new SerialPort(Port_name, 9600, Parity.None, 8, StopBits.One);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string w = sp.ReadLine();
//string msg = sp.ReadExisting();
if (w != String.Empty)
{
Invoke(new Action(() => richTextBox1.AppendText(w)));
}
this.chart1.Series["Data1"].Points.AddXY(rt, data);
}
double rt = 0;
Boolean i = false;
private void timer1_Tick(object sender, EventArgs e)
{
rt = rt + 0.1;
}
}
}
谢谢
我尝试过:
我没有使用图表。
我是初学者
thanks
What I have tried:
I have no work with Charts .
I am beginner
推荐答案
首先:
您将变量'数据'作为值添加到图表中 - 所以:
第一个错误:'data'必须是数字变量,可能是整数或单个或双精度。 ..但不是一个字符串!!!
第二个错误:你在哪里分配'数据'(如果它是一个数字变量)?
您在方法'DataReceivedHandler'中使用sp.Readline获得了哪些数据?
您能看到RichTextbox中有意义的值吗?
At first :
you add your Variable 'data' as Value to the Chart - so :
1st mistake : 'data' must be a number-variable, perhaps Integer or Single or Double ... but not a string !!!
2nd mistake : where do you assign 'data' (if it is a number-variable) ?
What Kind of data do you receive with sp.Readline inside the method 'DataReceivedHandler' ?
Could you see values inside your RichTextbox which make sense ?
这篇关于需要帮助以获得seriell端口的实时图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文