资源简介
Xmodem 协议传输由接收程序和发送程序完成。先由接收程序发送协商字符,协商校验方式,协商通过之后发送程序就开始发送数据包,接收程序接收到完整的一个数据包之后, 按照协商的方式对数据包进行校验。校验通过之后发送确认字符,然后发送程序继续发送下一包;如果校验失败,则发送否认字符,发送程序重传此数据包。
Xmodem协议是由Ward Chritensen于70年代提出并实现的,传输数据单位为信息包。
Xmodem 协议一般支持128 字节的数据包,并且支持校验和、CRC 两种校验方式。
参考:
https://blog.csdn.net/qq61394323/article/details/77324156
https://blog.csdn.net/m0_37756916/article/details/76064727
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace RUDPSLib.XModem1
{
//Version 1.3
//This class is tested to be 100% compatibel to Microsoft(r) Hyperterminal 5.1
//XmodemTransmit: supports both CRC and checksum
//XModemReceive: only supports checksum
//Feel free to use/modify/copy/distribute this file
public class XModem
{
#region Events
private System.EventHandler PacketReceivedEvent;
public event System.EventHandler PacketReceived
{
add
{
PacketReceivedEvent = (System.EventHandler)System.Delegate.Combine(PacketReceivedEvent value);
}
remove
{
PacketReceivedEvent = (System.EventHandler)System.Delegate.Remove(PacketReceivedEvent value);
}
}
public delegate void PacketSentEventHandler(int TXStringSize);
private PacketSentEventHandler PacketSentEvent;
public event PacketSentEventHandler PacketSent
{
add
{
PacketSentEvent = (PacketSentEventHandler)System.Delegate.Combine(PacketSentEvent value);
}
remove
{
PacketSentEvent = (PacketSentEventHandler)System.Delegate.Remove(PacketSentEvent value);
}
}
#endregion
#region Members
private System.IO.Ports.SerialPort port = null;
private byte SOH = (byte)(0x01);
//header for 128byte-packets
private byte STX = (byte)(0x02);
//header for 1024byte-packets
private byte EOT = (byte)(0x04);
//end of transmission
private byte ACK = (byte)(0x06);
//acknowledge
private byte NAK = (byte)(0x15);
//negativ acknowledge
private byte CAN = (byte)(0x18);
///
/// cancel transfer
///
private byte CTRLZ = (byte)(0x1A);
//padding char to fill data blocks < buffer size
private byte C_pad = (byte)(0x43);
//start of a CRC request
private ushort MAXRETRANS = System.Convert.ToUInt16(25);
//1024 for XModem 1k + 3 head chars + 2 crc + nul
private byte[] xbuff = new byte[1029];
private int bufsz;
private int crc = 1;
private byte packetno = (byte)1;
private int i;
private int c;
private int len = 0;
private int retry;
#endregion
#region Constructor
public XModem(System.IO.Ports.SerialPort port)
{
if (!port.IsOpen)
port.Open();
this.port = port;
}
#endregion
#region Implementation
#region XModemReceive
//
//receive byte Array via XModem using either
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 16017 2018-07-05 14:27 XModem.cs
相关资源
- asp.net 站内邮件系统c#
- c#实现u盘操作程序,可进行对u盘的感
- Modbus串口通信
- 旅游网站毕业论文
- c#WinForm程序自动升级源码
- 《ArcGIS Engine+C#开发教程》
- c#文件自动备份程序
- 精美时钟()
- NTKO OFFICE 4.0.3.2--完美破解+WinformDemo[
- C#小型窗体项目-BMI计算器
- C#实现本机资源监控
- C#微秒级计时器
- c#+SQL server物资管理系统
- c#gps原代码
- C#绘图工具DrawTools2005
- C#界面分屏展示
- ArcGis Engine + C# + 最短路径算法
- c#实现录wav音频
- C#中主窗体Panel中加载其他多个窗体
- c#进销存管理系统源码
- C#上位机控制WiFi智能小车
- C_序列化和反序列化.pdf
- c#实战程序:图片配对游戏
- c#实战:利用c#开扫雷游戏代码
- 学生信息管理系统源代码 内含C#编写
- C# socket通信的服务器和客户端
- 用C#语言编写计算器
- GPSTXT文件C#读写分割管理
- C# Primer Plus(源码)
- 基于C#的TCP/IP协议客户端和服务器的代
评论
共有 条评论