For Each service In services.Services Dim chars As GattCharacteristicsResult = Await service.GetCharacteristicsAsync() For Each c In chars.Characteristics If c.Uuid.ToString() = "0000ffe1-0000-1000-8000-00805f9b34fb" Then ' Custom service Dim writer As New DataWriter() writer.WriteString("Hello BLE!") Await c.WriteValueAsync(writer.DetachBuffer()) End If Next Next End Function "But beware – you’ll need to run this on Windows 10+, and your app must be packaged or have with Bluetooth capability." Chapter 3 – The Unexpected Hero User: LegacyCoder interrupts: "Why overcomplicate? Just use Virtual COM Port drivers. Pair your Bluetooth device – Windows creates a new COM port. Then use good old SerialPort from .NET:" Imports System.IO.Ports Public Sub SendViaComPort(comPort As String, data As String) Using sp As New SerialPort(comPort, 9600, Parity.None, 8, StopBits.One) sp.Open() sp.WriteLine(data) sp.Close() End Using End Sub
Imports InTheHand.Net.Bluetooth Imports InTheHand.Net.Sockets Public Function FindBluetoothDevice(deviceName As String) As BluetoothDeviceInfo Dim client As New BluetoothClient() Dim devices As BluetoothDeviceInfo() = client.DiscoverDevices(255) vb net bluetooth vbforums
Dim stream As NetworkStream = client.GetStream() Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(message & vbCrLf) stream.Write(data, 0, data.Length) stream.Close() client.Close() End Sub User: BT_Frustrated replies: "Thanks, but my device uses BLE (Bluetooth Low Energy) – not classic Bluetooth!" SerialPortSavior responds: "Ah, different beast. For BLE in VB.NET, you’ll need Windows.Devices.Bluetooth (UWP APIs) – but you can call them from WinForms with a little trick:" Imports Windows.Devices.Bluetooth Imports Windows.Devices.Bluetooth.GenericAttributeProfile Imports System.Threading.Tasks Public Async Function ConnectToBLE(deviceId As String) As Task Dim device As BluetoothLEDevice = Await BluetoothLEDevice.FromIdAsync(deviceId) Dim services As GattDeviceServicesResult = Await device.GetGattServicesAsync() For Each service In services
Public Sub SendData(device As BluetoothDeviceInfo, message As String) Dim ep As New BluetoothEndPoint(device.DeviceAddress, BluetoothService.SerialPort) Dim client As New BluetoothClient() client.Connect(ep) Then use good old SerialPort from
Public Class BluetoothHelper Public Shared Sub SendString(targetDeviceName As String, message As String) Try ' Method 1: Try COM ports first For Each com In My.Computer.Ports.SerialPortNames Using sp As New SerialPort(com, 9600) sp.Open() sp.WriteLine(message) sp.Close() Return End Using Next ' Method 2: Fallback to 32feet.NET Dim device = FindBluetoothDevice(targetDeviceName) If device IsNot Nothing Then SendData(device, message) End If Catch ex As Exception MessageBox.Show("Bluetooth failed: " & ex.Message) End Try End Sub End Class CodeNewbie_42 marks the thread as SOLVED and writes: "Turns out, the answer was hiding in plain sight. Bluetooth in VB.NET isn't hard – it's just serial communication with a different handshake . Thank you, VBForums. May your posts remain forever unarchived." Thread closed. 37,284 views. 9 helpful votes. Want me to turn this into a full downloadable VB.NET project or explain any specific Bluetooth scenario (e.g., receiving data, multiple connections, pairing without user dialog)?
' In Package Manager Console: ' Install-Package InTheHand.Net.Personal