• 大小: 2.72MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-09-12
  • 语言: C#
  • 标签: c#  

资源简介

c# 串口通信源代码c# 串口通信源代码c# 串口通信源代码

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;

namespace SComm
{
    public  class Com
    {
        private SerialPort sport;
       /// 
        /// 设置发送缓冲区大小
       /// 

        public int outBufferSize
        {
            set
            {
                sport.WriteBufferSize = value;
            }
        }
        /// 
        /// 设置接收缓冲区大小
        /// 

        public int inBufferSize
        {
            set
            {
                sport.ReadBufferSize = value;
            }
        }

        public Com()
        {
            sport = new SerialPort();
        }
        /// 
        /// 初始化
        /// 

        /// 端口名称
        /// 波特率
        /// 校验方式
        public Com(string portNameint rateParity parity)
        {
            sport = new SerialPort(portNamerateparity);   
        }

        public bool InitCom()
        {
            if (sport.IsOpen)
                return true;
            else
            {
                try
                {
                    sport.Open(); 
                    return true;
                }
                catch (Exception e)
                {
                    return false;

                }
            }
        }

        public void Close()
        {
            if (sport.IsOpen)
                sport.Close();
        }
        /// 
        /// 串口设置并打开
        /// 

        /// 
        /// 
        /// 
        /// 
        public bool InitCom(string portName int rate Parity parity)
        {
            if (sport.IsOpen)
                sport.Close();
            sport.BaudRate = rate;
            sport.PortName = portName;
            sport.Parity = parity;

            try
            {
                sport.Open();
                return true;
            }
            catch (Exception e)
            {
                return false;

            }
        }
      /// 
      /// 发送字节
      /// 

      /// 要发送的字节
      /// 发送字节的数量
      /// 
        public bool write(byte[] writeBytesint count)
        {
            if (InitCom())
            {
                try
                {
                    sport.Write(writeBytes 0 count);
                    return true;
                }
                catch (Exception e)
                {

                    return false;
                }
            }
            return false;
        }
        /// 
        /// 发送字符串
        /// 

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

     文件    1048576  2010-01-22 18:00  SCommnet\Database\MEMO_Data.MDF

     文件    1048576  2010-01-22 18:00  SCommnet\Database\MEMO_Log.LDF

     文件        270  2010-01-22 10:42  SCommnet\SComm\App.config

     文件      10678  2010-01-18 14:54  SCommnet\SComm\bin\Debug\app.publish\Application Files\SComm_1_0_0_1\Resource Files\Toolbar.bmp.deploy

     文件      52654  2010-01-18 14:47  SCommnet\SComm\bin\Debug\app.publish\Application Files\SComm_1_0_0_1\Resource Files\未标题-10.bmp.deploy

     文件     921654  2010-01-18 14:21  SCommnet\SComm\bin\Debug\app.publish\Application Files\SComm_1_0_0_1\Resource Files\顺泰图标.bmp.deploy

     文件    1005056  2010-01-20 12:26  SCommnet\SComm\bin\Debug\app.publish\Application Files\SComm_1_0_0_1\SComm.exe.deploy

     文件       8435  2010-01-20 12:26  SCommnet\SComm\bin\Debug\app.publish\Application Files\SComm_1_0_0_1\SComm.exe.manifest

     文件       5364  2010-01-20 12:26  SCommnet\SComm\bin\Debug\app.publish\SComm.application

     文件     461824  2010-01-20 12:26  SCommnet\SComm\bin\Debug\app.publish\setup.exe

     文件       1555  2010-01-22 17:42  SCommnet\SComm\bin\Debug\SComm.application

     文件    1011712  2010-01-22 17:41  SCommnet\SComm\bin\Debug\SComm.exe

     文件        270  2010-01-22 10:42  SCommnet\SComm\bin\Debug\SComm.exe.config

     文件       6487  2010-01-22 17:42  SCommnet\SComm\bin\Debug\SComm.exe.manifest

     文件      62976  2010-01-22 17:41  SCommnet\SComm\bin\Debug\SComm.pdb

     文件      14328  2010-01-20 08:42  SCommnet\SComm\bin\Debug\SComm.vshost.exe

     文件        490  2007-07-21 01:33  SCommnet\SComm\bin\Debug\SComm.vshost.exe.manifest

     文件      14848  2010-01-22 11:00  SCommnet\SComm\bin\Debug\Shuntai.dll

     文件      46592  2010-01-22 11:00  SCommnet\SComm\bin\Debug\Shuntai.pdb

     文件       6390  2010-01-22 16:42  SCommnet\SComm\Com.cs

     文件       1056  2010-01-21 14:59  SCommnet\SComm\ComFile.cs

     文件       5457  2010-01-20 11:19  SCommnet\SComm\CommWithARM.cs

     文件       7708  2010-01-22 17:41  SCommnet\SComm\DataForm.cs

     文件      18228  2010-01-22 17:41  SCommnet\SComm\DataForm.Designer.cs

     文件       6224  2010-01-22 17:41  SCommnet\SComm\DataForm.resx

     文件        939  2010-01-22 14:38  SCommnet\SComm\MainFrm.cs

     文件       6370  2010-01-22 14:38  SCommnet\SComm\MainFrm.Designer.cs

     文件       6010  2010-01-22 14:38  SCommnet\SComm\MainFrm.resx

     文件       3764  2010-01-22 11:00  SCommnet\SComm\obj\Debug\ResolveAssemblyReference.cache

     文件       1555  2010-01-22 17:42  SCommnet\SComm\obj\Debug\SComm.application

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

评论

共有 条评论