예제 #1
0
파일: YModem.cs 프로젝트: yancyn/BumbleeBee
 private void sendEndOftransmision()
 {
     sp.Write(new byte[] { (byte)0x04 }, 0, 1);
     Packet endpacket = new Packet();
     endpacket.isend = true;
     endpacket.longpacket = false;
     endpacket.packetnum = 0;
     endpacket.data = new byte[128];
     endpacket.createPacket();
     sp.Write(endpacket.packet, 0, endpacket.packet.Length);
 }
예제 #2
0
파일: YModem.cs 프로젝트: yancyn/BumbleeBee
        public void SendBinaryFile(byte[] bytes, string filename)
        {
            readbinary = true;
            //sp.Write("AT+pBINARYUPLOAD");
            //sendNewLine();
            //waitfor('C');
            ushort packetnum = 0;

            Packet initpacket = new Packet();
            initpacket.isinit = true;
            initpacket.packetnum = packetnum;
            initpacket.filename = filename;
            initpacket.filelength = bytes.Length;
            initpacket.longpacket = (filename.Length > 125) ? true : false;
            initpacket.createPacket();
            sp.Write(initpacket.packet, 0, initpacket.packet.Length);
            //Thread.Sleep(ONE_MOMENT);

            //waitforack();
            //waitfor('C');

            MemoryStream ms = new MemoryStream(bytes);
            byte[] temparr = new byte[1024];
            Packet sendPacket;
            long numpack = Math.Abs(((long)ms.Length) / ((long)1024));

            //long leftover = ms.Length % 1024;
            BinaryReader br = new BinaryReader(ms);
            while (ms.Position != ms.Length)
            {
                //progressUpdate(packetnum, Convert.ToInt32(numpack));
                _waitforack = false;
                packetnum++;
                temparr = br.ReadBytes(1024);
                sendPacket = new Packet();
                sendPacket.packetnum = packetnum;
                sendPacket.longpacket = true;
                sendPacket.isinit = false;
                sendPacket.data = temparr;
                sendPacket.createPacket();
                sp.Write(sendPacket.packet, 0, sendPacket.packet.Length);
                //Thread.Sleep(ONE_MOMENT);
                //waitforack();
            }

            Thread.Sleep(8000);
            sendEndOftransmision();

            //waitforack();
            readbinary = false;
            //waitforline();
            sp.Close();
        }