需要创建表格形式,这将从串行通信更新数据 [英] need to create tabular form which will update data from serial communication
问题描述
嗨
我是C#的初学者。
我需要为temp创建表,电压和电流以及此数据库将通过串行通信定期更新。
我的查询是,如何在C#窗口中创建表将动态更新数据的表单。我不想从任何数据库中提取数据。
请建议使用一些示例代码或控件?
谢谢
Hi
I am beginner to C#.
I need to create table for temp, voltage and current and this datab will be updating periodically by serial communication.
My query is, How to create a table in C# windows form which will update data dynamically. I do not want to extract data from any database.
Please suggest some sample code or controls to be used?
Thanks
推荐答案
你需要结合三个部分:
0)从串行通信中获取数据。如果您指的是RS232端口来读取数据,您可以使用 SerialPort课程 [ ^ ]。
1)您的数据模型。创建一个自定义类,其属性反映您要表示的数据。解码你从0)得到的东西并将数据输入你的模型。
一个简单的数据模型类:
You need to combine three parts:
0) Get the data from a serial communication. If you mean an RS232-port to read the data from, you can use the SerialPort class[^].
1) Your data model. Create a custom class with properties that reflect the data you want to represent. Decode what you got from 0) and feed the data into your model.
A simple data model class:
public class SingleDataPoint
{
public decimal Temperature { get; set; }
public decimal Voltage { get; set; }
public decimal Current { get; set; }
}
这个类没有逻辑。它只是用于存储一些值。创建一个实例
This class has no logic in it. It''s just for storing some values. Create an instance
SingleDataPoint oneSingleData = new SingleDataPoint();
并填入值
oneSingleData.Temperature = -273.15;
oneSingleData.Voltage = 42;
oneSingleData.Current = 0x0815;
如果您需要丢失这些数据点,请将它们保存在BindingList<SingleDataPoint> [ ^ ]以便以后轻松绑定到您的UI。
[/编辑]
2)显示数据。将您的模型绑定到 DataGridView [ ^ ]进行自动更新。
If you need losts of those data points, keep them in a BindingList<SingleDataPoint>[^] for later easy binding to your UI.
[/Edit]
2) Display the data. Bind your model to a DataGridView[^] for automatic updating.
这篇关于需要创建表格形式,这将从串行通信更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!