• 大小: 591KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-17
  • 语言: 其他
  • 标签:

资源简介

modubs实现对各种的智能设备的调试,比如温度,湿度,开关,02D,03D,04D参数

资源截图

代码片段和文件信息


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Controls;
using System.Threading;
using System.Windows.Documents;




namespace BXHSerialPort
{
    public partial class frmSerialPort : Form
    {
        private SerialPort ComDevice = new SerialPort();
        public frmSerialPort()
        {
            InitializeComponent();
            this.init();
        }
        public void init()
        {
            btnSend.Enabled = false;
            cbbComList.Items.AddRange(SerialPort.GetPortNames());
            if (cbbComList.Items.Count > 0)
            {
                cbbComList.SelectedIndex = 0;
            }
            cbbBaudRate.SelectedIndex = 5;
            //cbbBaudRate[5]= System.Drawing.Color.Red;
            cbbDataBits.SelectedIndex = 0;
            cbbParity.SelectedIndex = 0;
            cbbStopBits.SelectedIndex = 0;
            pictureBox1.BackgroundImage = Properties.Resources.red;

            ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
            panel3.Visible = false;
        }

        /// 
        /// 打开串口
        /// 

        /// 
        /// 
        /// 在没有打开设备后,不显示所有的控件,1不能点击,2不会出现
        private void btnOpen_Click(object sender EventArgs e)
        {
            panel3.Visible = true;
            if (cbbComList.Items.Count <= 0)
            {
                MessageBox.Show(“没有发现串口请检查线路!“);
                return;
            }

            if (ComDevice.IsOpen == false)
            {
                ComDevice.PortName = cbbComList.SelectedItem.ToString();
                ComDevice.BaudRate = Convert.ToInt32(cbbBaudRate.SelectedItem.ToString());
                ComDevice.Parity = (Parity)Convert.ToInt32(cbbParity.SelectedIndex.ToString());
                ComDevice.DataBits = Convert.ToInt32(cbbDataBits.SelectedItem.ToString());
                ComDevice.StopBits = (StopBits)Convert.ToInt32(cbbStopBits.SelectedItem.ToString());
                try
                {
                    ComDevice.Open();
                    btnSend.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                btnOpen.Text = “关闭串口“;
                pictureBox1.BackgroundImage = Properties.Resources.green;
            }
            else
            {
                try
                {
                    ComDevice.Close();
                    btnSend.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageB

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-26 18:00  BenXH\
     目录           0  2018-03-30 10:01  BenXH\BXHSerialPort\
     文件        4234  2018-03-30 10:19  BenXH\BXHSerialPort\BXHSerialPort.csproj
     文件         504  2018-03-30 14:55  BenXH\BXHSerialPort\Program.cs
     目录           0  2018-03-26 18:00  BenXH\BXHSerialPort\Properties\
     文件        1368  2017-03-25 14:05  BenXH\BXHSerialPort\Properties\AssemblyInfo.cs
     文件        3598  2017-03-25 15:22  BenXH\BXHSerialPort\Properties\Resources.Designer.cs
     文件        6433  2017-03-25 15:22  BenXH\BXHSerialPort\Properties\Resources.resx
     文件        1100  2017-03-25 14:05  BenXH\BXHSerialPort\Properties\Settings.Designer.cs
     文件         249  2017-03-25 14:05  BenXH\BXHSerialPort\Properties\Settings.settings
     目录           0  2018-03-26 18:00  BenXH\BXHSerialPort\Resources\
     文件        3115  2017-03-25 14:51  BenXH\BXHSerialPort\Resources\green.png
     文件        3131  2017-03-25 15:22  BenXH\BXHSerialPort\Resources\red.png
     文件        5647  2018-03-30 16:34  BenXH\BXHSerialPort\RingBufferManager.cs
     目录           0  2017-03-25 20:11  BenXH\BXHSerialPort\bin\
     目录           0  2018-04-02 17:22  BenXH\BXHSerialPort\bin\Debug\
     文件        4748  2018-04-02 17:22  BenXH\BXHSerialPort\bin\Debug\BXHSerialPort.xml
     文件      358912  2018-04-02 17:22  BenXH\BXHSerialPort\bin\Debug\BXHSerialPort.exe
     文件      790016  2018-04-02 17:22  BenXH\BXHSerialPort\bin\Debug\BXHSerialPort.pdb
     文件       22472  2018-04-03 18:30  BenXH\BXHSerialPort\bin\Debug\BXHSerialPort.vshost.exe
     文件         490  2010-03-17 22:39  BenXH\BXHSerialPort\bin\Debug\BXHSerialPort.vshost.exe.manifest
     文件       33973  2017-03-25 19:56  BenXH\运行截图\run.png
     文件      359987  2018-04-02 16:59  BenXH\BXHSerialPort\frmSerialPort.Designer.cs
     文件     1240033  2018-04-02 17:22  BenXH\BXHSerialPort\frmSerialPort.cs
     文件        5817  2018-04-02 16:59  BenXH\BXHSerialPort\frmSerialPort.resx
     目录           0  2017-03-25 20:11  BenXH\BXHSerialPort\obj\
     目录           0  2018-04-02 17:22  BenXH\BXHSerialPort\obj\Debug\
     文件        6745  2018-03-30 10:19  BenXH\BXHSerialPort\obj\Debug\BXHSerialPort.Properties.Resources.resources
     文件        6551  2018-04-03 18:30  BenXH\BXHSerialPort\obj\Debug\BXHSerialPort.csproj.FileListAbsolute.txt
     文件        1059  2018-04-02 17:01  BenXH\BXHSerialPort\obj\Debug\BXHSerialPort.csproj.GenerateResource.Cache
     文件        2365  2018-03-21 11:32  BenXH\BXHSerialPort\obj\Debug\BXHSerialPort.csprojResolveAssemblyReference.cache
............此处省略17个文件信息

评论

共有 条评论

相关资源