C# desktop application to connect to BLE devices using BleuIO

using System;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{

public partial class Form1 : Form
{
SerialPort mySerialPort = new SerialPort("COM18", 57600, Parity.None, 8, StopBits.One);
public Form1()
{
InitializeComponent();
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(mySerialPort_DataReceived);
mySerialPort.Open();
} private void button1_Click(object sender, EventArgs e)
{


lbl_test.Text = "Connected";
}

//print response from the dongle
private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string s = sp.ReadExisting();
output_data.Invoke(new EventHandler(delegate { output_data.Text += s + "\r\n"; }));
//lbl_output.Invoke(this.myDelegate, new Object[] { s });
}
private void tb_cmd_TextChanged(object sender, EventArgs e)
{

}
private void submit_cmd_Click(object sender, EventArgs e)
{
output_data.Text = "";
byte[] bytes = Encoding.UTF8.GetBytes(tb_cmd.Text);
var inputByte = new byte[] { 13 };
bytes = bytes.Concat(inputByte).ToArray();
mySerialPort.Write(bytes, 0, bytes.Length);
}
private void btn_disconnect_Click(object sender, EventArgs e)
{
mySerialPort.Close();
Environment.Exit(0);
}
private void Form1_Load(object sender, EventArgs e)
{
} private void btn_stop_Click(object sender, EventArgs e)
{
byte[] bytes = Encoding.UTF8.GetBytes("\u0003");
var inputByte = new byte[] { 13 };
bytes = bytes.Concat(inputByte).ToArray();
mySerialPort.Write(bytes, 0, bytes.Length);
}
private void output_data_TextChanged(object sender, EventArgs e)
{
} private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}

--

--

--

The BleuIO is Bluetooth low energy solution that can be used to create new BLE 5.0 applications in the fastest and easiest way.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Love you alphaness computing

Object-Oriented Programming vs Functional Programming: The Battle of the Languages

How I managed to install [X]Ubuntu alongside Windows 10 on my new XPS 15

Build CI/CD for Spring Boot with Github Action

Why do I love Jenkins shared libraries?

Introduction to Programming

What is Web 3.0?

I can’t help you be productive — I literally just spent almost two hours clicking and refreshing…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
bleuio

bleuio

The BleuIO is Bluetooth low energy solution that can be used to create new BLE 5.0 applications in the fastest and easiest way.

More from Medium

C# Desktop application to get real-time BLE data from Air Quality Sensor

Set Background Color and Background Image for PowerPoint Slides in C#

How to debug a docker image.

Library of RD.xml files for NativeAOT