• 大小: 100KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-31
  • 语言: C#
  • 标签: DLT645-2007  

资源简介

本人实战项目用C#编程读取多块电表,按照时序读取,解读电力协议报文,自动统计数据,转换成浮点数据。

资源截图

代码片段和文件信息

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;

namespace DBDBCJ
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        bool isOpen = false;

        int stepNo = 0;

        private void Form1_Load(object sender EventArgs e)
        {
            sp.PortName = “COM5“;
            sp.BaudRate = 1200;
            sp.DataBits = 8;
            sp.StopBits = StopBits.One;
            sp.Parity = Parity.Even;
            sp.ReadBufferSize = 1024;
            sp.ReadTimeout = -1;
            sp.RtsEnable = true;
            sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
            try
            {
                sp.Open();
                isOpen = true;

            }
            catch (Exception)
            {
                MessageBox.Show(“请检查COM1串口“ “错误提示“);
            }
            if (isOpen)
            {
                read1();
            }
            else
            {
                MessageBox.Show(“请检查程序“ “错误提示“);
            }


        }

        private void Form1_FormClosing(object sender EventArgs e)
        {

            try
            {
                sp.Close();
            }
            catch (Exception)
            {
                MessageBox.Show(“关闭COM1串口出错“ “错误提示“);
            }

        }

        private void read1()
        {
            sp.DiscardInBuffer();
            stepNo = 1;
            timer9.Enabled = false;
            timer1.Enabled = true;
            byte[] array = { 0xFE 0xFE 0x68 0x88 0x71 0x05 0x45 0x00 0x00 0x68 0x01 0x02 0x43 0xC3 0x1C 0x16 };
            try
            {
                sp.Write(array 0 array.Length);
            }
            catch (Exception)
            {
                MessageBox.Show(“发送数据时发生错误“ “错误提示“);
                return;
            }
        }

        private void read2()
        {
            sp.DiscardInBuffer();
            stepNo = 2;
            timer1.Enabled = false;
            timer2.Enabled = true;
            byte[] array = { 0xFE 0xFE 0x68 0x87 0x71 0x05 0x45 0x00 0x00 0x68 0x01 0x02 0x43 0xC3 0x1B 0x16 };
            try
            {
                sp.Write(array 0 array.Length);
            }
            catch (Exception)
            {
                MessageBox.Show(“发送数据时发生错误“ “错误提示“);
                return;
            }
        }

        private void read3()
        {
            sp.DiscardInBuffer();
            stepNo = 3;
            timer2.Enabled = false;
            timer3.Enabled = true;
            byte[] array = { 0xFE 0xFE 0x68 0x87 0x71 0x05 0x45 0x00 0x00 0x68 0x01 0x02 0x43 0xC3 0x3B 0x16 };
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-29 11:45  DBDBCJ\
     目录           0  2017-09-29 11:45  DBDBCJ\DBDBCJ\
     文件        3671  2017-09-29 14:17  DBDBCJ\DBDBCJ\DBDBCJ.csproj
     文件       23695  2017-09-29 17:21  DBDBCJ\DBDBCJ\Form1.Designer.cs
     文件       11870  2017-09-30 17:39  DBDBCJ\DBDBCJ\Form1.cs
     文件      109534  2017-09-29 17:21  DBDBCJ\DBDBCJ\Form1.resx
     文件         487  2017-09-29 11:45  DBDBCJ\DBDBCJ\Program.cs
     目录           0  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\
     文件        1344  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\AssemblyInfo.cs
     文件        2860  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\Resources.Designer.cs
     文件        5612  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\Resources.resx
     文件        1089  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\Settings.Designer.cs
     文件         249  2017-09-29 11:45  DBDBCJ\DBDBCJ\Properties\Settings.settings
     目录           0  2017-09-29 11:45  DBDBCJ\DBDBCJ\bin\
     目录           0  2017-09-29 15:41  DBDBCJ\DBDBCJ\bin\Debug\
     文件       87552  2017-09-29 17:21  DBDBCJ\DBDBCJ\bin\Debug\DBDBCJ.exe
     文件       38400  2017-09-29 17:21  DBDBCJ\DBDBCJ\bin\Debug\DBDBCJ.pdb
     文件       11600  2017-10-04 10:42  DBDBCJ\DBDBCJ\bin\Debug\DBDBCJ.vshost.exe
     文件         490  2010-03-17 22:39  DBDBCJ\DBDBCJ\bin\Debug\DBDBCJ.vshost.exe.manifest
     目录           0  2017-09-29 11:45  DBDBCJ\DBDBCJ\obj\
     目录           0  2017-09-29 11:45  DBDBCJ\DBDBCJ\obj\x86\
     目录           0  2017-09-30 17:31  DBDBCJ\DBDBCJ\obj\x86\Debug\
     文件       68212  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\DBDBCJ.Form1.resources
     文件         180  2017-09-29 14:17  DBDBCJ\DBDBCJ\obj\x86\Debug\DBDBCJ.Properties.Resources.resources
     文件         835  2017-10-04 10:42  DBDBCJ\DBDBCJ\obj\x86\Debug\DBDBCJ.csproj.FileListAbsolute.txt
     文件       87552  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\DBDBCJ.exe
     文件       38400  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\DBDBCJ.pdb
     文件        4440  2017-09-30 17:31  DBDBCJ\DBDBCJ\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6268  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         648  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\GenerateResource.read.1.tlog
     文件         718  2017-09-29 17:21  DBDBCJ\DBDBCJ\obj\x86\Debug\GenerateResource.write.1.tlog
............此处省略3个文件信息

评论

共有 条评论

相关资源