Example #1
0
        private void SendDataButton_Click(object sender, EventArgs e)
        {
            string dataToSend = DataToSendTextBox.Text;

            if (WiFlyClient != null && WiFlyClient.Client != null && WiFlyClient.Connected && !string.IsNullOrEmpty(dataToSend))
            {
                try
                {
                    NetworkStream stream = WiFlyClient.GetStream();
                    ClearResults();

                    AppendToResults(string.Format("Sending WiFly command: {0}", dataToSend));
                    byte[] dataToSendWriteBuffer = ASCIIEncoding.ASCII.GetBytes(dataToSend);
                    stream.Write(dataToSendWriteBuffer, 0, dataToSendWriteBuffer.Length);
                    Thread.Sleep(100);
                    ReadFromWiFly(stream);
                }
                catch (IOException ex)
                {
                    AppendToResults(ex.ToString());
                    ConnectStatusTextBox.Text = Wifi.NotConnected;
                    return;
                }
            }
        }
Example #2
0
 private void DisconnectDeviceButton_Click(object sender, EventArgs e)
 {
     if (WiFlyClient != null && WiFlyClient.Connected)
     {
         WiFlyClient.Close();
         ClearResults();
         ConnectStatusTextBox.Text = Wifi.NotConnected;
     }
 }
Example #3
0
        private void RunCommandButton_Click(object sender, EventArgs e)
        {
            string commandToRun = CommandToRunTextBox.Text;

            if (WiFlyClient != null && WiFlyClient.Client != null && WiFlyClient.Connected && !string.IsNullOrEmpty(commandToRun))
            {
                try
                {
                    NetworkStream stream = WiFlyClient.GetStream();
                    ClearResults();

                    // Enter command mode.
                    string enterCommandMode = "$$$";
                    AppendToResults(string.Format("Sending WiFly command: {0}", enterCommandMode));
                    byte[] enterCommandModeWriteBuffer = ASCIIEncoding.ASCII.GetBytes(enterCommandMode);
                    stream.Write(enterCommandModeWriteBuffer, 0, enterCommandModeWriteBuffer.Length);
                    Thread.Sleep(500);
                    ReadFromWiFly(stream);

                    AppendToResults(string.Format("Sending WiFly command: {0}", commandToRun));
                    commandToRun += Environment.NewLine;
                    byte[] commandWriteBuffer = ASCIIEncoding.ASCII.GetBytes(commandToRun);
                    stream.Write(commandWriteBuffer, 0, commandWriteBuffer.Length);
                    Thread.Sleep(500);
                    ReadFromWiFly(stream);

                    // Exit command mode.
                    string exitCommandMode = "exit" + Environment.NewLine;
                    AppendToResults(string.Format("Sending WiFly command: {0}", exitCommandMode));
                    byte[] exitCommandModeWriteBuffer = ASCIIEncoding.ASCII.GetBytes(exitCommandMode);
                    stream.Write(exitCommandModeWriteBuffer, 0, exitCommandModeWriteBuffer.Length);
                    Thread.Sleep(500);
                    ReadFromWiFly(stream);
                }
                catch (IOException ex)
                {
                    AppendToResults(ex.ToString());
                    ConnectStatusTextBox.Text = Wifi.NotConnected;
                    return;
                }
            }
        }