BleuIO

BleuIO

  • Get Started
  • Buy Now
  • Manual
  • AT Commands
  • Help

›Scripts & Tutorials

Manual

  • How it works
  • How to use
  • Verbose Mode
  • Known Issues
  • Troubleshooting

Firmware Updates

    BleuIO Pro (SSD025)

    • Firmware Updates
    • Release History

    BleuIO (SSD005)

    • Firmware Updates
    • Release History of BleuIO (SSD005)

AT-Commands

  • List of AT Commands

BleuIO Libraries

  • JavaScript Library
  • Python Library

Scripts & Tutorials

  • Python: iBeacon
  • Python: Eddystone Beacon
  • Python: Scan
  • Python: Scan and Store
  • Python: SPS Script
  • Python: File transfer Script
  • Python: Repeater Script
  • Javascript: Google chrome.serial Beacon
  • C# Console App Example
  • C# WFA Example

Script using libraries

    Python library > v1.2.0

    • Custom Services example using Python library
    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library

    Python library < v1.2.0

    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library
    • SPS example using Python library
    • Security Example using Python library

    JS library

    • Eddystone example using Javascript library
    • IBeacon example using Javascript library
    • Scan example using Javascript library
    • Security Example using Javascript library
    • Get Device Distance

Projects

    Arduino

    • Arduino Example

    Beaglebone

    • Beaglebone Example

    Raspberry Pi

    • Raspberry PI into Beacon
    • Raspberry PI home automation

    Raspberry PI Pico

    • BleuIO integration (Part1)
    • BleuIO integration (Part2)
    • BleuIO integration (Part3)

    Renesas RA4M2

    • Signal Strength Monitoring
    • Real-Time CO2 monitor
    • Monitoring Air Quality

    STM32 Nucleo-144

    • Nucleo-144 board example
    • Smart Bulb Example

    M5Stack's CoreMP135

    • M5Stack's CoreMP135 board example

Build Your Own Firmware

  • Build Your Own Firmware
  • Advertising Example

More

  • Links
Order Now

BleuIO

$19.99

Buy Now

C# Console Application example

Introduction

In this example we are going to create a simple C# console application to communicate with BleuIO using SerialPort. This script can be used to create Bluetooth Low Energy application using C# with BleuIO.

Let’s start

As a first step lets create a new project in visual studio and select C# console application from the list.C# BLE connection

Choose a suitable name for your project and paste the following code to Program.cs file.

The source code is available at github.

https://github.com/smart-sensor-devices-ab/bluetooth_low_energy_csharp

using System;
using System.IO.Ports;
using System.Text;

namespace SerialPortExample
{
    class SerialPortProgram
    {
        static SerialPort _port;
        static void Main(string[] args)
        {
            string portName;
            portName = SetPortName();
            _port = new SerialPort(portName,57600, Parity.None, 8, StopBits.One);
            // Instatiate this class
            SerialPortProgram serialPortProgram = new SerialPortProgram();
        }

        private SerialPortProgram()
        {
            _port.DataReceived += new
              SerialDataReceivedEventHandler(port_DataReceived);
            OpenMyPort();
            Console.WriteLine("Type q to exit.");
            bool continueLoop = true;
            string inputCmd;

            while (continueLoop)
            {
                inputCmd = Console.ReadLine();

                if (inputCmd == "q")
                {
                    continueLoop = false;
                    break;
                }
                else
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(inputCmd);
                    var inputByte = new byte[] { 13 };
                    bytes = bytes.Concat(inputByte).ToArray();
                    _port.Write(bytes, 0, bytes.Length);
                }
            }
        }

        private void port_DataReceived(object sender,
          SerialDataReceivedEventArgs e)
        {
            // Show all the incoming data in the port's buffer
            Console.WriteLine(_port.ReadExisting());
        }

        //Open selected COM port
        private static void OpenMyPort()
        {
            try
            {
                _port.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error opening my port: {0}", ex.Message);
                Environment.Exit(0);
            }
        }

        // Display Port values and prompt user to enter a port.
        public static string SetPortName()
        {
            string portName;

            Console.WriteLine("Available Ports:");
            foreach (string s in SerialPort.GetPortNames())
            {
                Console.WriteLine("   {0}", s);
            }

            Console.Write("Enter COM port value (ex: COM18): ");
            portName = Console.ReadLine();
            return portName;
        }

    }
}

For this script a BleuIO dongle connected to the computer.

When we run the application, it suggests all the available ports on the computer and asks to write the com port number where the BleuIO is connected.

Once we write the correct port number, it starts communicating with BleuIO via SerialPort.

The response of AT commands from the BleuIO will be shown on the screen.

Find the list of available AT commands at BleuIO getting started guide. https://www.bleuio.com/getting_started/docs/commands/

The application will terminate with control+c or type 'q'.

← Javascript: Google chrome.serial BeaconC# WFA Example →
  • Introduction

Support Request

If you have any queries or technical questions, please don't hesitate to send us a message. We will reply within 24 hours.

Message Sent!

Docs
ManualAT CommandsHelp
Community
YouTubeLinkedInFacebook
More
BleuIOSmart Sensor DevicesGitHub
Sales & Support
support@bleuio.comsales@bleuio.com
Copyright © 2025 BleuIO. A product of Smart Sensor Devices