title: Sending AT Commands to Bluetooth Module Using C# via Bluetooth connection
body: <p>I need help on my codes.</p>
  
  <p>I need to send AT command to my bluetooth module(master) using c# via bluetooth connection
  with my laptop. </p>
  
  <p>This is the module im using <a href="http://www.rasmicro.com/Bluetooth/EGBT-045MS-046S%20Bluetooth%20Module%20Manual%20rev%201r0.pdf" rel="nofollow">Bluetooth Module</a></p>
  
  <p>This is the settings of my bluetooth module(master).</p>
  
  <pre><code>Baudrate = 9600
  Data bits = 8
  Parity = none
  Stop bits =1
  AT+ROLE = 0 (slave)
  AT+CMODE = 1
  PIN34 left unconnected. 
  </code></pre>
  
  <p>My goal is to set my PIO10 to logic high which is in pin 33.</p>
  
  <p>And this is my codes in C# (Microsoft Visual Studio 2012)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.IO.Ports;
  
  namespace BluetoothTest
  {
  public partial class Form1 : Form
  {
      BTSerial btserial;
      string string1;
      int data=0,cnt=0;
      bool isStr;
      public Form1()
      {
          InitializeComponent();
  
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          String[] port = SerialPort.GetPortNames();
          foreach (String p1 in port)
          {
              cbx_port.Items.Add(p1);
              comboBox1.Items.Add(p1);
          }
      }
  
      private void button2_Click(object sender, EventArgs e) //connect button
      {
          if (serialPort1.IsOpen)
          {
              serialPort1.Close();
              button2.Text = "Connect";
          }
          else
              try
              {
                  serialPort1.PortName = cbx_port.Text;
                  btserial = new BTSerial(serialPort1);
                  button2.Text = "Disconnect";
              }
              catch (Exception c)
              {
                  MessageBox.Show(c.Message);
              }           
      }
  
      private void btn_send_Click(object sender, EventArgs e) //send button
      {
          serialPort1.Write("AT+PIO=10,1"); //tried this 1st
          serialPort1.Write("AT+PIO=10,1\r"); //tried this 2nd
          serialPort1.Write("AT+PIO=10,1\r\n");//tried this 3rd
          serialPort1.WriteLine("AT+PIO=10,1"); //tried also
          serialPort1.WriteLine("AT+PIO=10,1\r"); //tried also
          serialPort1.WriteLine("AT+PIO=10,1\r\n"); //tried also
      }
    }
  }
  </code></pre>
  
  <p>Well there was no error on my c# codes but when i click the send button,
  my bluetooth module PIO10 wont set to high. Can you guys tell me what Im doing wrong here?
  My bluetooth module is already added to my laptop and i believe it is connected when i click the connect button. Thanks for reading.</p>