Exemplo n.º 1
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SerialPort comPort = new SerialPort(coms.Text, 115200, Parity.None, 8, StopBits.One);
            Xmodem     modem   = new Xmodem(comPort);

            loger.Content = "Sending file...";
            byte[] dataToSend = File.ReadAllBytes(path);
            await Task.Run(() => modem.Send(dataToSend));

            loger.Content = "File sent.";
            comPort.Close();
        }
Exemplo n.º 2
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SerialPort comPort = new SerialPort(coms.Text, 115200, Parity.None, 8, StopBits.One);
            Xmodem     modem   = new Xmodem(comPort);

            loger.Content = "Reading file...";
            MemoryStream receivedMemoryStream = new MemoryStream();
            await Task.Run(() => modem.Receive(receivedMemoryStream));

            byte[] dataReceived = receivedMemoryStream.ToArray();
            dataReceived = modem.TrimPaddingBytesFromEnd(dataReceived);  //koncowe bity do odjecia
            FileStream receivedFile = new FileStream(path, FileMode.CreateNew);

            receivedFile.Write(dataReceived, 0, dataReceived.Length);
            receivedFile.Close();
            loger.Content = "File received.";
            comPort.Close();
        }