public async Task <bool> Start() { if (textBoxFilePath.Text == string.Empty) { return(false); } /* 启动OTA下载 */ bool bRet = await m_flowSensor.StartOTADownloadAsync(); if (!bRet) { return(false); } m_flowSensor.DataRecved += OnUartDataRecved; FileTransProtocol = new YModem(TransmitMode.Send, YModemType.YModem_1K, ReTryMax); FileTransProtocol.EndOfTransmit += FileTransProtocol_EndOfTransmit; FileTransProtocol.AbortTransmit += FileTransProtocol_AbortTransmit; FileTransProtocol.ReSendPacket += FileTransProtocol_ReSendPacket; FileTransProtocol.SendNextPacket += FileTransProtocol_SendNextPacket; FileTransProtocol.TransmitTimeOut += FileTransProtocol_TransmitTimeOut; FileTransProtocol.StartSend += FileTransProtocol_StartSend; FileTransProtocol.SendToUartEvent += FileTransProtocol_SendToUartEvent; packetNo = 1; fileIndex = 0; FileTransProtocol.Start(); if (StartTransmitFile != null) { StartTransmitFile(this, null); } return(true); }
public void Start() { if (txtFile.Text == string.Empty) { throw new Exception("未选择任何文件,请选择文件!"); } switch (_FileTransMode) { case FileTransmitMode.ASCII: FileTransProtocol = new BinarySend(Convert.ToInt32(numDelayTime.Value)); break; case FileTransmitMode.Binary: PacketLen = Convert.ToInt32(numPacketLen.Value); FileTransProtocol = new BinarySend(Convert.ToInt32(numDelayTime.Value)); break; case FileTransmitMode.Xmodem: // Xmodem FileTransProtocol = new XModem(TransmitMode.Send, XModemType.XModem, ReTryMax); PacketLen = 128; break; case FileTransmitMode.Xmodem_1K: // Xmodem-1k FileTransProtocol = new XModem(TransmitMode.Send, XModemType.XModem_1K, ReTryMax); PacketLen = 1024; break; case FileTransmitMode.Ymodem: FileTransProtocol = new YModem(TransmitMode.Send, YModemType.YModem, ReTryMax); PacketLen = 128; break; case FileTransmitMode.Ymodem_1K: FileTransProtocol = new YModem(TransmitMode.Send, YModemType.YModem_1K, ReTryMax); PacketLen = 1024; break; default: break; } if (FileTransProtocol != null) { FileTransProtocol.EndOfTransmit += new EventHandler(FileTransProtocol_EndOfTransmit); FileTransProtocol.AbortTransmit += new EventHandler(FileTransProtocol_AbortTransmit); FileTransProtocol.ReSendPacket += new EventHandler(FileTransProtocol_ReSendPacket); FileTransProtocol.SendNextPacket += new EventHandler(FileTransProtocol_SendNextPacket); FileTransProtocol.TransmitTimeOut += new EventHandler(FileTransProtocol_TransmitTimeOut); FileTransProtocol.StartSend += new EventHandler(FileTransProtocol_StartSend); FileTransProtocol.SendToUartEvent += new SendToUartEventHandler(FileTransProtocol_SendToUartEvent); } packetNo = 1; fileIndex = 0; FileTransProtocol.Start(); if (StartTransmitFile != null) { StartTransmitFile(this, null); } }