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

Create a new Image Recipe

Proteus Finance IDO results

How to Use Fairwinds Insights to Identify Kubernetes Cluster Misconfiguration

The best cloud storage out there

Simple Steps to host a Website/Web-App in AWS with SSL/TLS enabled! [Complete Guide]

Multi-level Cloud formation Templates — AWS

We Have A Discord Server!

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

API key security using Git Hub.

Doing away with passwords in ASP.NET

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

Publish a .NET Console App to Chocolatey using GitHub Actions