{"id":130,"date":"2022-01-10T14:34:01","date_gmt":"2022-01-10T14:34:01","guid":{"rendered":"https:\/\/www.bleuio.com\/blog\/?p=130"},"modified":"2022-07-01T10:36:45","modified_gmt":"2022-07-01T10:36:45","slug":"c-desktop-application-to-connect-to-ble-devices-using-bleuio","status":"publish","type":"post","link":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/","title":{"rendered":"C# desktop application to connect to BLE devices using BleuIO"},"content":{"rendered":"\n<p><strong>Bluetooth Low Energy (BLE)<\/strong>&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is really interesting to create desktop application using C# that connects to the devices around the house and manage them.<\/p>\n\n\n\n<p>In this example we are going to create a simple C# windows form application to communicate with BleuIO using SerialPort. This script can be used to create Bluetooth Low Energy application using C# with BleuIO.<\/p>\n\n\n\n<p><strong>Let\u2019s start<\/strong><\/p>\n\n\n\n<p>As a first step lets create a new project in visual studio and select C# windows form application from the list.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/smartsensordevices.com\/wp-content\/uploads\/2022\/01\/windows-form-app-1024x202.jpg\" alt=\"\" class=\"wp-image-1434\"\/><\/figure>\n\n\n\n<p>Choose a suitable name for your project.<\/p>\n\n\n\n<p>Once the project is created, we will see a blank form screen where we will add buttons and labels to communicate with BleuIO graphically.<\/p>\n\n\n\n<p>We will have buttons that connects and disconnects from BleuIO. An input field that takes AT commands from the user and sends it to BleuIO using SerialPort. And a text area will display the response from BleuIO to the screen.<\/p>\n\n\n\n<p>The form will look like this<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/smartsensordevices.com\/wp-content\/uploads\/2022\/01\/ble-application-c.jpg\" alt=\"\" class=\"wp-image-1435\"\/><\/figure>\n\n\n\n<p>The .cs file associated to this will have the following code.<\/p>\n\n\n\n<p>Source code is available at https:\/\/github.com\/smart-sensor-devices-ab\/bluetooth_low_energy_csharp_WFA.git<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.IO.Ports;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\n\nnamespace WindowsFormsApp1\n{\n    \n    public partial class Form1 : Form\n    {\n        SerialPort mySerialPort = new SerialPort(\"COM18\", 57600, Parity.None, 8, StopBits.One);\n        public Form1()\n        {\n            InitializeComponent();            \n            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(mySerialPort_DataReceived);\n            mySerialPort.Open();\n\n        }\n\n        private void button1_Click(object sender, EventArgs e)\n        {\n            \n            \n            lbl_test.Text = \"Connected\";\n        }\n        \n        \/\/print response from the dongle\n        private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)\n        {\n            SerialPort sp = (SerialPort)sender;\n            string s = sp.ReadExisting();\n            output_data.Invoke(new EventHandler(delegate { output_data.Text +=  s + \"\\r\\n\"; })); \n\n            \/\/lbl_output.Invoke(this.myDelegate, new Object&#91;] { s });\n        }\n\n\n        private void tb_cmd_TextChanged(object sender, EventArgs e)\n        {\n            \n        }\n\n        private void submit_cmd_Click(object sender, EventArgs e)\n        {\n            output_data.Text = \"\";\n            byte&#91;] bytes = Encoding.UTF8.GetBytes(tb_cmd.Text);\n            var inputByte = new byte&#91;] { 13 };\n            bytes = bytes.Concat(inputByte).ToArray();\n            mySerialPort.Write(bytes, 0, bytes.Length);           \n        }\n\n        private void btn_disconnect_Click(object sender, EventArgs e)\n        {\n            mySerialPort.Close();\n            Environment.Exit(0);\n        }\n\n        private void Form1_Load(object sender, EventArgs e)\n        {\n\n        }\n\n        private void btn_stop_Click(object sender, EventArgs e)\n        {\n            byte&#91;] bytes = Encoding.UTF8.GetBytes(\"\\u0003\");\n            var inputByte = new byte&#91;] { 13 };\n            bytes = bytes.Concat(inputByte).ToArray();\n            mySerialPort.Write(bytes, 0, bytes.Length);\n        }\n\n        private void output_data_TextChanged(object sender, EventArgs e)\n        {\n\n        }\n\n        private void pictureBox1_Click(object sender, EventArgs e)\n        {\n\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>As you can notice I wrote COM18 to connect to serial port because BleuIO device on my computer is connected to COM18.<\/p>\n\n\n\n<p>You can check your COM port from device manager.<\/p>\n\n\n\n<p>Lets run the project and click on connect button.<\/p>\n\n\n\n<p>Once we are connected to BleuIO, we will be able to write AT commands using the input filed.<\/p>\n\n\n\n<p>List of AT commands are available at https:\/\/www.bleuio.com\/getting_started\/docs\/commands\/<\/p>\n\n\n\n<p>There is a stop button that write control+c to dongle and cancels current execution.<\/p>\n\n\n\n<p>Here is a demo of this sample app.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"C# desktop application to connect to BLE device using BleuIO\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/eXJJXSXjzHI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":131,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,2],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bleuio","category-bleuio-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"og:description\" content=\"Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/\" \/>\n<meta property=\"og:site_name\" content=\"BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-10T14:34:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T10:36:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"666\" \/>\n\t<meta property=\"og:image:height\" content=\"387\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"BleuIO\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/\"},\"author\":{\"name\":\"BleuIO\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"headline\":\"C# desktop application to connect to BLE devices using BleuIO\",\"datePublished\":\"2022-01-10T14:34:01+00:00\",\"dateModified\":\"2022-07-01T10:36:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/\"},\"wordCount\":353,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-desktop-application-bluetooth.jpg\",\"articleSection\":[\"BleuIO\",\"BleuIO tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/\",\"name\":\"C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-desktop-application-bluetooth.jpg\",\"datePublished\":\"2022-01-10T14:34:01+00:00\",\"dateModified\":\"2022-07-01T10:36:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-desktop-application-bluetooth.jpg\",\"contentUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-desktop-application-bluetooth.jpg\",\"width\":666,\"height\":387,\"caption\":\"C# desktop application to connect to BLE devices\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# desktop application to connect to BLE devices using BleuIO\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\",\"name\":\"BleuIO - Create Bluetooth Low Energy application\",\"description\":\"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\",\"name\":\"BleuIO\",\"sameAs\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/author\\\/biadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/","og_locale":"en_US","og_type":"article","og_title":"C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application","og_description":"Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]","og_url":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/","og_site_name":"BleuIO - Create Bluetooth Low Energy application","article_published_time":"2022-01-10T14:34:01+00:00","article_modified_time":"2022-07-01T10:36:45+00:00","og_image":[{"width":666,"height":387,"url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg","type":"image\/jpeg"}],"author":"BleuIO","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#article","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/"},"author":{"name":"BleuIO","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"headline":"C# desktop application to connect to BLE devices using BleuIO","datePublished":"2022-01-10T14:34:01+00:00","dateModified":"2022-07-01T10:36:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/"},"wordCount":353,"commentCount":0,"image":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg","articleSection":["BleuIO","BleuIO tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/","url":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/","name":"C# desktop application to connect to BLE devices using BleuIO - BleuIO - Create Bluetooth Low Energy application","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#primaryimage"},"image":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg","datePublished":"2022-01-10T14:34:01+00:00","dateModified":"2022-07-01T10:36:45+00:00","author":{"@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"breadcrumb":{"@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#primaryimage","url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg","contentUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-desktop-application-bluetooth.jpg","width":666,"height":387,"caption":"C# desktop application to connect to BLE devices"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bleuio.com\/blog\/c-desktop-application-to-connect-to-ble-devices-using-bleuio\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bleuio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"C# desktop application to connect to BLE devices using BleuIO"}]},{"@type":"WebSite","@id":"https:\/\/www.bleuio.com\/blog\/#website","url":"https:\/\/www.bleuio.com\/blog\/","name":"BleuIO - Create Bluetooth Low Energy application","description":"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bleuio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80","name":"BleuIO","sameAs":["https:\/\/www.bleuio.com\/blog"],"url":"https:\/\/www.bleuio.com\/blog\/author\/biadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":1,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions\/132"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media\/131"}],"wp:attachment":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}