void FileTransProtocol_SendNextPacket(object sender, EventArgs e) { ShowTextReprot(string.Format("开始传输第{0}包数据", packetNo)); packetNo++; fileIndex += PacketLen; if (packetNo == 1) { fileIndex = 0; } int readBytes = ReadPacketFromFile(fileIndex, PacketBuff, PacketLen); if (readBytes <= 0) { FileTransProtocol?.Stop(); } else { if (readBytes < PacketLen) { for (int i = readBytes; i < PacketLen; i++) { PacketBuff[i] = 0x1A; } } FileTransProtocol?.SendPacket(new PacketEventArgs(packetNo, PacketBuff)); } }
void FileTransProtocol_StartSend(object sender, EventArgs e) { PacketBuff = new byte[PacketLen]; if (_FileTransMode == FileTransmitMode.Xmodem || _FileTransMode == FileTransmitMode.Xmodem_1K) { packetNo = 1; if (ReadPacketFromFile(fileIndex, PacketBuff, PacketLen) <= 0) { FileTransProtocol.Stop(); } else { FileTransProtocol.SendPacket(new PacketEventArgs(packetNo, PacketBuff)); } startTime = DateTime.Now; } else if (_FileTransMode == FileTransmitMode.Ymodem || _FileTransMode == FileTransmitMode.Ymodem_1K) { packetNo = 0; FileInfo fileInfo = new FileInfo(txtFile.Text); byte[] fileNameBytes = System.Text.ASCIIEncoding.Default.GetBytes(fileInfo.Name); int index = 0; Array.Copy(fileNameBytes, 0, PacketBuff, 0, fileNameBytes.Length); index += fileNameBytes.Length; PacketBuff[index] = 0; index++; byte[] fileSizeBytes = System.Text.ASCIIEncoding.Default.GetBytes(fileInfo.Length.ToString()); Array.Copy(fileSizeBytes, 0, PacketBuff, index, fileSizeBytes.Length); FileTransProtocol.SendPacket(new PacketEventArgs(0, PacketBuff)); fileIndex = 0; packetNo = 0; //fileInfo.Name; startTime = DateTime.Now; } ShowTextReprot(string.Format("开始发送数据")); }