示例#1
0
 private void SendPacket(byte[] packet)
 {
     lastPacket = packet;
     retries    = 0;
     DataLink.SendPacket(packet);
     timer.Start();
 }
示例#2
0
        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            var i = 0;

            while (_serialPort.BytesToRead > 1)
            {
                i++;
                var byteBuffer = new byte[4];
                _serialPort.Read(byteBuffer, 0, 2);
                var dec = DeCycle(byteBuffer);
                DataLink.RecievePacket(dec);
            }
        }
示例#3
0
        private void ResendPacket(object sender, EventArgs e)
        {
            if (retries++ < maxRetries)
            {
                DataLink.SendPacket(lastPacket);
                return;
            }

            if (lastPacket[0] == (byte)MessageType.FileReceivedOk ||
                lastPacket[0] == (byte)MessageType.FileReceived ||
                lastPacket[0] == (byte)MessageType.Disconnect ||
                lastPacket[0] == (byte)MessageType.DisconnectOk)
            {
                timer.Stop();
                return;
            }

            CloseButton.IsEnabled      = true;
            FileBox.IsEnabled          = true;
            DirectoryBox.IsEnabled     = true;
            DisconnectButton.IsEnabled = true;
            if (fileStream != null)
            {
                fileStream.Close();
            }

            if (sending == true && fileStream.Position == 0)
            {
                StatusText.Text = "Физическое соединение открыто.";
                MessageBox.Show("Принимающая сторона не готова к логическому соединению.");
            }
            else
            {
                SendPacket(new byte[] { (byte)MessageType.Disconnect });
                StatusText.Text = "Логическое соединение потеряно.";
                MessageBox.Show("Логическое соединение потеряно.");
            }
            sending = null;
        }