• 大小: 0.42M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-23
  • 语言: C#
  • 标签: YModem  

资源简介

Ymodem窗体应用程序

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyApp
{
    public class CRC
    {
        #region  CRC16
        /// 
        /// CRC16计算方法
        /// 

        /// 
        /// 
        public static byte[] CRC16(byte[] data)
        {
            int len = data.Length;
            if (len > 0)
            {
                ushort crc = 0xFFFF;  //预置 1 个 16 位的CRC寄存器

                for (int i = 0; i < len; i++)
                {
                    crc = (ushort)(crc ^ (data[i]));
                    for (int j = 0; j < 8; j++)
                    {
                        crc = (crc & 1) != 0 ? (ushort)((crc >> 1) ^ 0xA001) : (ushort)(crc >> 1);
                    }
                }
                byte high = (byte)((crc & 0xFF00) >> 8);  //高位置
                byte low = (byte)(crc & 0x00FF);         //低位置

                return new byte[] { high low };
            }
            return new byte[] { 0 0 };
        }
        #endregion


        #region  ToCRC16
        //UTF8编码
        public static string ToCRC16(string content)
        {
            return ToCRC16(content Encoding.UTF8);
        }

        public static string ToCRC16(string content bool isReverse)
        {
            return ToCRC16(content Encoding.UTF8 isReverse);
        }

        public static string ToCRC16(string content Encoding encoding)
        {
            return ByteToString(CRC16(encoding.GetBytes(content)) true);
        }

        public static string ToCRC16(string content Encoding encoding bool isReverse)
        {
            return ByteToString(CRC16(encoding.GetBytes(content)) isReverse);
        }

        public static string ToCRC16(byte[] data)
        {
            return ByteToString(CRC16(data) true);
        }

        public static string ToCRC16(byte[] data bool isReverse)
        {
            return ByteToString(CRC16(data) isReverse);
        }
        #endregion

        #region  ToModbusCRC16
        public static string ToModbusCRC16(string s)
        {
            return ToModbusCRC16(s true);
        }

        /// 
        /// modbus的CRC校验位,16进制校验
        /// 

        /// 输入的字符串
        /// true为低字节在前,false为高字节在前
        /// 
        public static string ToModbusCRC16(string s bool isReverse)
        {
            return ByteToString(CRC16(StringToHexByte(s)) isReverse);
        }

        public static string ToModbusCRC16(byte[] data)
        {
            return ToModbusCRC16(data true);
        }

        public static string ToModbusCRC16(byte[] data bool isReverse)
        {
            return ByteToString(CRC16(data) isReverse);
        }
        #endregion

        #re

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-12-25 14:57  Ymodem\
     目录           0  2020-12-25 14:57  Ymodem\MyApp\
     目录           0  2020-12-25 14:57  Ymodem\MyApp\.vs\
     目录           0  2020-12-25 14:57  Ymodem\MyApp\.vs\MyApp\
     目录           0  2020-12-25 22:41  Ymodem\MyApp\.vs\MyApp\v15\
     文件       74240  2021-01-26 16:24  Ymodem\MyApp\.vs\MyApp\v15\.suo
     文件      262144  2020-12-25 22:41  Ymodem\MyApp\.vs\MyApp\v15\Browse.VC.db
     目录           0  2020-12-25 15:58  Ymodem\MyApp\.vs\MyApp\v15\ipch\
     目录           0  2020-12-25 16:49  Ymodem\MyApp\.vs\MyApp\v15\ipch\AutoPCH\
     目录           0  2020-12-25 16:07  Ymodem\MyApp\.vs\MyApp\v15\ipch\AutoPCH\1b83828a746127b1\
     文件      327680  2020-12-25 16:16  Ymodem\MyApp\.vs\MyApp\v15\ipch\AutoPCH\1b83828a746127b1\COMMON.ipch
     目录           0  2020-12-25 16:49  Ymodem\MyApp\.vs\MyApp\v15\ipch\AutoPCH\80dcbe32c157775f\
     文件      327680  2020-12-25 16:49  Ymodem\MyApp\.vs\MyApp\v15\ipch\AutoPCH\80dcbe32c157775f\COMMON.ipch
     目录           0  2020-12-25 14:57  Ymodem\MyApp\.vs\MyApp\v15\Server\
     目录           0  2020-12-25 14:57  Ymodem\MyApp\.vs\MyApp\v15\Server\sqlite3\
     文件           0  2020-12-23 14:04  Ymodem\MyApp\.vs\MyApp\v15\Server\sqlite3\db.lock
     文件      622592  2020-12-30 01:18  Ymodem\MyApp\.vs\MyApp\v15\Server\sqlite3\storage.ide
     文件       32768  2021-01-26 15:47  Ymodem\MyApp\.vs\MyApp\v15\Server\sqlite3\storage.ide-shm
     文件     4140632  2021-01-20 15:49  Ymodem\MyApp\.vs\MyApp\v15\Server\sqlite3\storage.ide-wal
     目录           0  2020-12-30 23:27  Ymodem\MyApp\MyApp\
     文件         187  2020-12-23 14:03  Ymodem\MyApp\MyApp\App.config
     目录           0  2020-12-25 18:15  Ymodem\MyApp\MyApp\bin\
     目录           0  2020-12-25 14:57  Ymodem\MyApp\MyApp\bin\Debug\
     文件       28672  2020-12-31 20:09  Ymodem\MyApp\MyApp\bin\Debug\MyApp.exe
     文件         187  2020-12-23 14:03  Ymodem\MyApp\MyApp\bin\Debug\MyApp.exe.config
     文件       65024  2020-12-31 20:09  Ymodem\MyApp\MyApp\bin\Debug\MyApp.pdb
     目录           0  2020-12-25 18:15  Ymodem\MyApp\MyApp\bin\Release\
     文件        6982  2020-12-26 13:17  Ymodem\MyApp\MyApp\CRC.cs
     文件       34633  2020-12-30 23:27  Ymodem\MyApp\MyApp\Form1.cs
     文件       24457  2020-12-30 23:27  Ymodem\MyApp\MyApp\Form1.Designer.cs
     文件        6415  2020-12-30 23:27  Ymodem\MyApp\MyApp\Form1.resx
............此处省略28个文件信息

评论

共有 条评论