• 大小: 8.95MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-22
  • 语言: C#
  • 标签: c#  

资源简介

用C#编写的串口调试助手,可以实现数据收发、字节格式转换等简单功能。

资源截图

代码片段和文件信息

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.Ports; //串口命名空间
using System.Threading;

namespace SSComm
{
    public partial class Form1 : Form
    {
        SerialPort sp = new SerialPort();  //创建串口全局变量
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            statusLabel1.Text = ““;//状态条初始化
            //设置窗口大小
            this.MaximizeBox = false;//隐藏最大化按钮
            this.MaximumSize = this.Size;//固定窗口尺寸最大为当前尺寸
            this.MinimumSize = this.Size;//固定窗口尺寸最小为当前尺寸
            tbxReceivedData.Focus();//默认将光标放在发送文本框上
            rbtReceviedAscii.Select();//默认选择ASCII字符显示
            rbtSendAscii.Select();//默认选择ASCII字符显示
            CheckPort();//检测可用串口

            //初始化波特率
            cbxBaud.Items.Clear();
            cbxBaud.Items.Add(“1200“);
            cbxBaud.Items.Add(“2400“);
            cbxBaud.Items.Add(“4800“);
            cbxBaud.Items.Add(“9600“);
            cbxBaud.Items.Add(“12800“);
            cbxBaud.Items.Add(“19200“);
            cbxBaud.Items.Add(“25600“);
            cbxBaud.Items.Add(“115200“);
            cbxBaud.SelectedIndex = 3;

            //初始化校验位
            cbxParity.Items.Clear();
            cbxParity.Items.Add(“无“);
            cbxParity.Items.Add(“奇校验“);
            cbxParity.Items.Add(“偶校验“);
            cbxParity.SelectedIndex = 0;

            //初始化停止位
            cbxStopBits.Items.Clear();
            cbxStopBits.Items.Add(“1“);
            cbxStopBits.Items.Add(“1.5“);
            cbxStopBits.Items.Add(“2“);
            cbxStopBits.SelectedIndex = 0;

            //初始化数据位
            cbxDataBits.Items.Clear();
            cbxDataBits.Items.Add(“7“);
            cbxDataBits.Items.Add(“8“);
            cbxDataBits.SelectedIndex = 1;
            statusLabel1.Text = ““;//修改状态条内容

            tbxSendData.Text = “$00I\r\n“;

        }

        //检测当前可用串口函数
        private void CheckPort()
        {
            cbxPort.Items.Clear();
            bool haveCom = false;
            string[] serialPorts = SerialPort.GetPortNames();
            if (serialPorts == null)
            {
                haveCom = false;  //无可用串口
            }
            else
            {
                foreach (string port in serialPorts)
                {
                    bool exist = false;
                    try
                    {
                        SerialPort sp = new SerialPort(port);
                        sp.Open();
                        sp.Close();
                        exist = true;
                    }
                    catch (Exception)
                    {
                        exist = false;
                    }
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     52736  2018-11-17 11:34  SSComm\.vs\SSComm\v14\.suo

     文件        189  2018-10-24 22:39  SSComm\SSComm\App.config

     文件     174592  2018-10-30 14:26  SSComm\SSComm\bin\Debug\de\DevExpress.Data.v15.2.resources.dll

     文件       8192  2018-10-30 14:26  SSComm\SSComm\bin\Debug\de\DevExpress.Printing.v15.2.Core.resources.dll

     文件       6144  2018-10-30 14:26  SSComm\SSComm\bin\Debug\de\DevExpress.Sparkline.v15.2.Core.resources.dll

     文件      20480  2018-10-30 14:26  SSComm\SSComm\bin\Debug\de\DevExpress.Utils.v15.2.resources.dll

     文件      99840  2018-10-30 14:26  SSComm\SSComm\bin\Debug\de\DevExpress.XtraEditors.v15.2.resources.dll

     文件    5259264  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Data.v15.2.dll

     文件    1129260  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Data.v15.2.xml

     文件    3771904  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Printing.v15.2.Core.dll

     文件    1257127  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Printing.v15.2.Core.xml

     文件      72704  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Sparkline.v15.2.Core.dll

     文件      25581  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Sparkline.v15.2.Core.xml

     文件    8399872  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Utils.v15.2.dll

     文件     716166  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.Utils.v15.2.xml

     文件    4819456  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.XtraEditors.v15.2.dll

     文件    2178005  2018-10-30 14:26  SSComm\SSComm\bin\Debug\DevExpress.XtraEditors.v15.2.xml

     文件     176640  2018-10-30 14:26  SSComm\SSComm\bin\Debug\es\DevExpress.Data.v15.2.resources.dll

     文件       8192  2018-10-30 14:26  SSComm\SSComm\bin\Debug\es\DevExpress.Printing.v15.2.Core.resources.dll

     文件       8192  2018-10-30 14:26  SSComm\SSComm\bin\Debug\es\DevExpress.Sparkline.v15.2.Core.resources.dll

     文件      20480  2018-10-30 14:26  SSComm\SSComm\bin\Debug\es\DevExpress.Utils.v15.2.resources.dll

     文件      77312  2018-10-30 14:26  SSComm\SSComm\bin\Debug\es\DevExpress.XtraEditors.v15.2.resources.dll

     文件     188416  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ja\DevExpress.Data.v15.2.resources.dll

     文件       8192  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ja\DevExpress.Printing.v15.2.Core.resources.dll

     文件       5120  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ja\DevExpress.Sparkline.v15.2.Core.resources.dll

     文件      27136  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ja\DevExpress.Utils.v15.2.resources.dll

     文件     116736  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ja\DevExpress.XtraEditors.v15.2.resources.dll

     文件     200192  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ru\DevExpress.Data.v15.2.resources.dll

     文件       8704  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ru\DevExpress.Printing.v15.2.Core.resources.dll

     文件       8704  2018-10-30 14:26  SSComm\SSComm\bin\Debug\ru\DevExpress.Sparkline.v15.2.Core.resources.dll

............此处省略52个文件信息

评论

共有 条评论