• 大小: 19KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: C#  Com  串口  DLL  

资源简介

串口通信DLL,包括了串口数据发送,数据接收,数据接收等待... 该工程是一个实际应用于通信设备程序中的部分组件。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;

using System.IO.Ports;
using System.IO;
using System.Windows.Forms;


namespace Com
{
    public class ClsCom
    {

        public  SerialPort Com;

        //初始化
        private void InitialCom()
        {
            //测试串口
            getCom();
        }

        #region  串口设置
        public void setCom(string[] ComStr)
        {   
            File.WriteAllLines(Application.StartupPath + “\\com.glux“ ComStr);
        }
        public string [] getCom()
        {
            if (File.Exists(Application.StartupPath + “\\com.glux“))
            {
                string[] ComStr = File.ReadAllLines(Application.StartupPath + “\\com.glux“);
                Com = new SerialPort(ComStr[0] Convert.ToInt32(ComStr[1]) Parity.None Convert.ToInt16(ComStr[2]) StopBits.One);
                return ComStr;
            }

            else
            {
               
                Com = new SerialPort(“com1“ 19200 Parity.None 8 StopBits.One);
                String[] ComStr = new string[5] { “com1“ “19200“ “8“ “无校验(NONE)“ “none“ };
                File.WriteAllLines(Application.StartupPath + “\\com.glux“ ComStr); //创建该文件
                return ComStr;
            }  
        }
        #endregion 

        #region  数据位调整
        public void setDataBit(string  ComStr)
        {
            string[] CC = new string[1] { ComStr };

            File.WriteAllLines(Application.StartupPath + “\\Correction.glux“ CC);
        }
        public string  getDataBit()
        {
            if (File.Exists(Application.StartupPath + “\\Correction.glux“))
            {
                string[] ComStr = File.ReadAllLines(Application.StartupPath + “\\Correction.glux“);
                
                return ComStr[0];
            }

            else
            {

                String[] ComStr = new string[1] { “65536“ };
                File.WriteAllLines(Application.StartupPath + “\\Correction.glux“ ComStr); //创建该文件s
                return ComStr[0];
            }
        }
        #endregion

        #region 串口操作

        //打开串口
        public bool OpenCom()
        {
            InitialCom();

            try
            {
                if (!Com.IsOpen)
                {
                    Com.Open();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        //关闭串口
        public bool CloseCom()
        {
            try
            {
                if (Com.IsOpen)
                {
                    Com.Close();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        //获取串口返回的数据,有时间限制
        public bool ReadGetComTime(byte data)
        {
            

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

     文件      20480  2010-03-09 13:39  Com\Com\bin\Debug\Com.dll

     文件      19968  2010-03-09 13:39  Com\Com\bin\Debug\Com.pdb

     文件       7319  2010-03-09 13:39  Com\Com\ClsCom.cs

     文件       1993  2010-01-26 14:11  Com\Com\Com.csproj

     文件        118  2010-03-09 13:39  Com\Com\obj\Com.csproj.FileList.txt

     文件      20480  2010-03-09 13:39  Com\Com\obj\Debug\Com.dll

     文件      19968  2010-03-09 13:39  Com\Com\obj\Debug\Com.pdb

     文件       1301  2010-01-18 11:53  Com\Com\Properties\AssemblyInfo.cs

     文件        898  2010-01-18 11:53  Com\Com.sln

    ..A..H.     10240  2010-03-09 13:40  Com\Com.suo

     目录          0  2010-01-18 11:53  Com\Com\obj\Debug\Refactor

     目录          0  2010-01-18 11:53  Com\Com\obj\Debug\TempPE

     目录          0  2010-03-09 13:39  Com\Com\bin\Debug

     目录          0  2010-03-09 13:39  Com\Com\obj\Debug

     目录          0  2010-01-18 11:53  Com\Com\bin

     目录          0  2010-03-09 13:39  Com\Com\obj

     目录          0  2010-01-18 11:53  Com\Com\Properties

     目录          0  2010-03-09 13:39  Com\Com

     目录          0  2010-01-18 11:53  Com

----------- ---------  ---------- -----  ----

               102765                    19


评论

共有 条评论