コード例 #1
0
        void FileTransProtocol_StartSend(object sender, EventArgs e)
        {
            packetNo = 0;

            FileInfo fileInfo = new FileInfo(textBoxFilePath.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("开始发送数据"));
        }
コード例 #2
0
ファイル: FormFileSend.cs プロジェクト: yxddxs/SerialDebug
        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("开始发送数据"));
        }