资源简介
本程序采用C#实现能够读取电能表电表数据,电能表需具有485模块,通过485转232串口线和232转usb串口线与电脑相链接,安装相应的驱动程序,即可在电脑上读出电能表的数据。对嵌入式程序的设计,串口通讯等方面的编程具有重要意义。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Collections;
using System.IO;
using System.Text.Regularexpressions;
using System.Reflection;
using System.Threading;
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
int count = 0;//发送的次数
int sendcount = 0;
int getcount = 0;
public Form1()
{
InitializeComponent();
}
//串口界面初始化
private void Form1_Load(object sender EventArgs e)
{
//如果有配置 则读取配置文件
if (File.Exists(Application.StartupPath + @“\SerConfig.wjs“))
{
using (StreamReader sr = new StreamReader(Application.StartupPath + @“\SerConfig.wjs“ Encoding.UTF8))
{
comboBox1.SelectedItem = sr.ReadLine();
comboBox2.SelectedItem = sr.ReadLine();
comboBox3.SelectedItem = sr.ReadLine();
comboBox4.SelectedItem = sr.ReadLine();
comboBox5.SelectedItem = sr.ReadLine();
textBox4.Text = sr.ReadLine();
}
}
else
{
//初始化
comboBox1.SelectedIndex = 4;
comboBox2.SelectedIndex = 5;
comboBox3.SelectedIndex = 0;
comboBox4.SelectedIndex = 2;
comboBox5.SelectedIndex = 0;
}
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
// this.Text = this.Text + “V“ + version.Major + “.“ + version.Minor;
//扫描串口函数
SearchAndAddSerialToComboBox(serialPort1comboBox1);
}
//扫描端口函数
private void SearchAndAddSerialToComboBox(SerialPort MyPort ComboBox MyBox)
{
String Buffer;
MyBox.Items.Clear();//清空列表
for (int i = 1; i <= 10; i++)//测试每一个串口
{
try
{
Buffer = “COM“ + i.ToString();
MyPort.PortName = Buffer;//对端口赋值
MyPort.Open();
MyBox.Items.Add(Buffer);//添加到下拉列表里
MyPort.Close();
}
catch (Exception)//不能打开运行这里进入下个i
{
}
}
}
//设置串口名函数(当改变选中项时发生)
private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
{
if (serialPort1.IsOpen)
{
CloseSet();
serialPort1.PortName = comboBox1.Text;
OpenSet();
}
else
{
serialPort1.PortName = comboBox1.Text;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 77 2016-04-12 10:09 读电表(自编)\WindowsFormsApplication21\app.config
文件 70 2016-04-02 22:18 读电表(自编)\WindowsFormsApplication21\bin\Debug\SerConfig.wjs
文件 27648 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.dll
文件 77 2016-04-12 10:09 读电表(自编)\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.dll.config
文件 81408 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.pdb
文件 11600 2016-04-12 10:05 读电表(自编)\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe
文件 490 2010-03-17 22:39 读电表(自编)\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe.manifest
文件 16950 2016-01-16 12:27 读电表(自编)\WindowsFormsApplication21\Form1.cs
文件 31254 2016-01-06 17:22 读电表(自编)\WindowsFormsApplication21\Form1.Designer.cs
文件 6612 2016-01-06 17:22 读电表(自编)\WindowsFormsApplication21\Form1.resx
文件 645 2016-01-02 22:04 读电表(自编)\WindowsFormsApplication21\Form2.cs
文件 6847 2016-01-02 22:04 读电表(自编)\WindowsFormsApplication21\Form2.Designer.cs
文件 5817 2016-01-02 22:04 读电表(自编)\WindowsFormsApplication21\Form2.resx
文件 4440 2015-12-26 13:44 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6753 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 2834 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\GenerateResource.read.1.tlog
文件 7886 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\GenerateResource.write.1.tlog
文件 7897 2015-12-30 09:06 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\ResolveAssemblyReference.cache
文件 7702 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.csproj.FileListAbsolute.txt
文件 27648 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.dll
文件 180 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.Form1.resources
文件 180 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.Form2.resources
文件 81408 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.pdb
文件 180 2016-04-12 10:11 读电表(自编)\WindowsFormsApplication21\obj\x86\Debug\WindowsFormsApplication21.Properties.Resources.resources
文件 506 2015-12-24 10:11 读电表(自编)\WindowsFormsApplication21\Program.cs
文件 1398 2016-01-02 10:12 读电表(自编)\WindowsFormsApplication21\Properties\AssemblyInfo.cs
文件 2898 2015-12-24 10:11 读电表(自编)\WindowsFormsApplication21\Properties\Resources.Designer.cs
文件 5612 2015-12-24 10:11 读电表(自编)\WindowsFormsApplication21\Properties\Resources.resx
文件 1108 2015-12-24 10:11 读电表(自编)\WindowsFormsApplication21\Properties\Settings.Designer.cs
文件 249 2015-12-24 10:11 读电表(自编)\WindowsFormsApplication21\Properties\Settings.settings
............此处省略17个文件信息
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论