Bluetooth device Connection in c# winform application without any dll for windows 7

For establish connection with another device in bluetooth we need to add that device in our OS .To do that in programmatically we have to write below code.

the code for add device is simple


void adddevice()
        {
            try
            {  //add device n os
Process p=Process.Start("E:\\Windows\\System32\\DevicePairingWizard.exe");//here write ur own windows drive
               while (true)
                {
                    if (p.HasExited) //determine if process end
                       break;
                }
                //generate busy com ort list

                List tList = new List();
               listBox1.Items.Clear();
             foreach (string s in SerialPort.GetPortNames())
                {
                 tList.Add(s);
                }
                tList.Sort();
          listBox1.Items.Add("NO PORT");
          listBox1.Items.AddRange(tList.ToArray());
         listBox1.SelectedIndex = 0;
 richTextBox1.Text = richTextBox1.Text + Environment.NewLine + "COMPORT GENERATED";
            }
         catch (Exception ee)
     {             if(DialogResult.Retry== MessageBox.Show("CANT FIND UR ADDED DEVICE..", "Problem occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
                adddevice();
            }
        }

Now for remove u can run just another process
Process p = Process.Start("E:\\Windows\\System32\\control.exe ");

before connection u have to select ur required port, only user can know which port are using the device. u have to select that port from here.

for connection there are simple code like

    bool connectbluetooth()
        {
            try
            {
                if (listBox1.SelectedIndex != 0)
                {
                    scom = listBox1.SelectedItem.ToString();
                    port = new SerialPort(scom, 9600, Parity.None, 8, StopBits.One);
                     port.Open();
  richTextBox1.Text = richTextBox1.Text + Environment.NewLine + "CONNECTION OPEN SUCCESSFUL"; ;
                    return true;
                }
                else
                    MessageBox.Show("Please select com port","Missing port",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return false;
            }
            catch (Exception a)
            {
                if (DialogResult.Retry == MessageBox.Show(a.Message, "problem occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning))
                    connectbluetooth();
                else
                return false;
                return false;
            }
          }

now for sending data there are very simple function like i used here

 bool send(string text) {
           try
           {
        port.WriteTimeout = 10000;//define how much time wait for send data
                port.Write(text);
     return true;
            }
            catch(Exception a)
            {
                if (DialogResult.Retry == MessageBox.Show(a.Message, "Problem occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning))
                    send(text);
                else
                    return false;
                return false;
            }
        }

the receiver will get this data in his hyper terminal. next i will show how to send files and also receive.
full sourcecode can download from here

 
and to see the hardware part bluetooth modulation check here
 

Advertisements

About kishor datta gupta

Graduate Research Assistant at University of Memphis Software Engineer at Silicon Orchard LTD. Former Research Assistant at Lamar University Former Software Engineer at Samsung R&D Institute Bangladesh Studies Ph.D. Computer Science at University of Memphis Studied Masters of Science in Computer Sciences at Lamar University Studied BSC in CSE at Khulna University of Engineering and Technology Studied HSC (completed) at Chittagang college 04-06 Studied High school at ST. Placid's High School'04 Studied Junior Secondary School at Saint Mary's School Lives in Memphis, Tennessee
This entry was posted in C#, Winform app and tagged , , , , , , , , . Bookmark the permalink.

37 Responses to Bluetooth device Connection in c# winform application without any dll for windows 7

  1. yogita says:

    If I want to use this code on windows xp then can i need dll files & which dll files.

  2. Karlis says:

    Hello!
    I’ am trying to download source, but link is not working, maybe You can write new link? Really need this utility, Thank You 🙂

  3. abhay says:

    Hello!
    I’ am trying to download source, but link is not working,plz send source code to mail abhay221@gmail.com its very important for my last year project plz send it urgent bcoz my project submission date is near so plz send it thanks

  4. abhay says:

    Hello!
    I’ am trying to download source, but link is not working,

  5. koxi Tu says:

    Hello!
    I’m a beginner and trying to use C # link Bluetooth.
    Really need the code, but source code can’t download, plz send source code to mail
    koxi716@gmail.com.
    Thank you very much!!

  6. Chipa Voot says:

    Hi,

    Please send the source code @ chipavoot@gmail.com I am unable to download the source code. It seems your code is very helpful. I m finding something like what you did …..it will be really a superb help for me if you send the full source code at my email address…….

    Thanks in advance.

    Chipa

  7. Angel Ricardo says:

    Hello!
    I’m a also beginner and trying to use C # link Bluetooth.
    Really need the code, but source code can’t download, please send source code to mail
    angelricardoh@gmail.com.
    Thanks.

  8. got really perfect post thanks all

    ppc agency

  9. cachi says:

    Hello! source code can’t download, please send source code to mail~
    clover026@gmail.com
    Thanks.

  10. David~La says:

    Hey, I cant download the source code too… please mail to s20528255@live.nmmu.ac.za

  11. Burak says:

    Hello, project link is broken,please renew link.

  12. erkan says:

    plz send me code on my mail erkan.dirikcan@gmail.com

  13. Nihat says:

    plz can you send your project code on my mail nihat.tunali@ege.edu.tr

  14. steven says:

    Hello,
    Kudos for the app , was really nyc
    it all worked out well in winforms, wen it comes to wpf, in the listbox iam getting “string[]array”instead og “COM1”
    can any one help,pls
    regards
    steve

  15. aumsomnath777 says:

    Thanks for the great post. Can you please mail me your source code ( some firewall issue in my company) . It will be awesome. aumsomnath777@gmail.com.

  16. lun says:

    Hello~~ please send source code to mail ~ Thanks.
    lun6146@gmail.com

  17. Codus says:

    Hello,
    please can you mail me your source code. (chindji@gmail.com)
    Download link is not more available
    Thanks.

  18. dinesh says:

    please can you mail me your source code.
    my Email id is : dp.midsun@gmail.com
    Download link is not more available

  19. Anonymous says:

    please can you mail me your source code.
    my Email id is : chfran@hotmail.com
    Download link is not more available

  20. SiHan says:

    please can you mail me your source code.
    my Email id is : eat04162415@gmail.com

  21. waleedarif says:

    Plzzz can you send me the source code .!!! i will be very thankfull

  22. Yusuf says:

    Hello!
    I’ am trying to download source, but link is not working,plz send source code to daaci5@yahoo.com
    thnks

  23. Yusuf says:

    Hell how to define scon object and port object

  24. Anonymous says:

    plz send me code souha.rawin@gmail.com
    thks

  25. inds says:

    plz. send me the full source code indz_dups@yahoo.com. we highly needed it for our project.
    tnx.

  26. Bhawna Raghuvanshi says:

    hello,
    please send the full source code to raghuvanshi.bhawna29@gmail.com,I realy need this. It seems very helpful.I am unable to download due to link is not working.

  27. Jasper says:

    Hi,

    I’m also interested in the source code.
    Please send the full source code to jasper.poppe@kahosl.be

    Thanks in advance!

  28. Alex says:

    Can you send me the code by mail, link is dead…
    adn19871@live.com.mx

    Thanks for your effort.

  29. nizar says:

    Can you send me the code by mail, link is dead…
    anizar@walla.com
    thanx

  30. Anonymous says:

    Can you send me the code by mail, link is dead
    vove85@hanmail.net
    thank you

  31. Tong says:

    Can you send me the code by mail, link is dead
    tongtang2528@hotmail.com
    thank you

  32. Anonymous says:

    Hello,

    Its a really nice blog for me but i cannot download the file, please let me know how i can download it OR you can also send it to my email address milan.your12@gmail.com . I am looking forward to hear from you.

    Thank you in advance,
    milan

  33. scaria says:

    As far i read about your project it was good.
    plz can you send your project code on my mail scanalkara@gmail.com

  34. Nathali A.S says:

    Hello,
    can you send me your source code? my email is: love_nas24@hotmail.com
    thank you!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s