Reputation: 71
I am getting so mad at trying to find out a working example. YES, I am new to VB.Net. I was used with VB6, long way back. I just cannot get that thing to do what I want.
My project: I am totally tired of using Steam and other 3rd party apps that require pairing and very hard or long configurations to emulate an XBox controller from a non-Xinput controller. I baught a RegeMoudal Pro Controller and OF COURSE, Windows does NOT read any button entries and I need to use a third party app. The problem with the apps is that they require too much configuration. I just want to transfer the controller's input into a Windows detectable input, that's it.
So, since I cannot go in FASM to do such a complexe project without breaking my head everywhere, I chose to go with the easy way, old school. I spent 2 days just figuring out that I had to reference UWP and a bunch of other things. Now, I said to myself, if I only get AT LEAST the list of devices connected on Bluetooth, I'll be able to start somewhere but nope. No matter what I find, noone has any Visual Basic codes to use in a clean way asside from very complexe code I barely understand.
Can someone please help me AT LEAST find out HOW to list all devices on Bluetooth. I do not care if they are connected or not, I just want to list the devices.
Here is what I got. A simple form with 1 single button and 1 single Label. I know, this just has a bunch of errors.
Imports Windows.Devices.Bluetooth
Imports Windows.Devices.Enumeration
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
Dim odevices = New DevicePicker
Dim odev As DeviceInformation
Dim sdevices As String
sdevices = ""
LabRes.Text = "Searching devices..."
For Each odev In odevices
sdevices = sdevices & Chr(13) & odev.GetType.Name
Next
End Sub
End Class
I just cannot figure out how to make this simple task so a gentle help would be nice.
I got discouraged because Windows does NOT capture any input of my controller detected as a Bluetooth Pro Controller but a simple webpage does capture every single input so I am annoyed because I was waiting for this controller since a long time because the XBOX ONE controller had serious joystick issues and made me rage quit games because the joystick would give small taps backwards when releasing it so those Xbox controllers are now on my blacklist because even when Microsoft sent it back to me, it had the exact same issue so I got a refund.
Now, I want to create my own version of Pro Controller to Xbox Controller input app. And I am insisting, Visual Basic code, not C++ or C#. And this is for WINDOWS, not android or any other systems. And refering to Microsoft's website to help does not either help because they give no samples in Visual Basic and I just don't understand the language they are using to explain everything, I'm just a simple person, oh, and the samples that can be taken need to be downloaded as project. I just want a sample code available neatly and easily without downloading anything.
Upvotes: 0
Views: 5503
Reputation: 71
So, after fideling so much with VB and trying to search. I finally found out how to list Bluetooth devices in Visual Basic (VB.Net).
FIRST of all, you NEED 32Feet.Net. I ran into the NuGet problem. I have absolutely NO clue what that is. After searching, I found out that nuGet packages can simply be unzipped using 7zip or other similar app. So here are the steps you need to do to prepare Visual Basic aka VB.Net to work with Bluetooth devices.
NOW you will be able to use the bluetooth functions. Next, we need to import the functions so they can be available when you code so you need to put this line at the very beginning of your project:
Imports InTheHand.Net.Sockets
Now that this is done, you can list you bluetooth devices. I will explain how I did my sample window. I put 1 button, 1 label and 1 timer object. When changing a label following the mentionned solution above with "Application.DoEvents()" My label still did not change text. So I used an old VB6 trick with a timer. I simply disable a timer object and when clicking on the button, I enable this timer which performs the actions I want. 1 VERY and excessively IMPORTANT thing, once you have started your timer actions, immediately disable your timer before performing any tasks inside this timer or else your function will repeat at the speed of your timer ticks.
So this is my complete code which lists the names of the Bluetooth devices on y computer in Visual Basic (VB.Net).
Imports InTheHand.Net.Sockets
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
LabRes.Text = "Searching devices..."
TmrBTScan.Enabled = True
BouGetDev.Enabled = False
End Sub
Private Sub TmrBTScan_Tick(sender As Object, e As EventArgs) Handles TmrBTScan.Tick
Dim bt_client As BluetoothClient = New BluetoothClient()
Dim odevices As BluetoothDeviceInfo() = bt_client.DiscoverDevices().ToArray()
Dim odev As BluetoothDeviceInfo
Dim sdevices As String = ""
Dim schr = ""
TmrBTScan.Enabled = False
For Each odev In odevices
sdevices = sdevices & schr & odev.DeviceName
schr = Chr(10) & Chr(13)
Next
LabRes.Text = sdevices
BouGetDev.Enabled = True
End Sub
End Class
This should list the names of all the Bluetooth devices. At least, it worked on my end and I hope this can help others that are looking for very clear steps in what to download, what to install, what to get, where to navigate, which files and what lines to code. It really is hard to get full complete instructions so I hope this helps.
Thanks for those that helped me here. I had to do some deep search, but at least I can get started on my project now.
Upvotes: 2
Reputation: 111
First please fix this bug
The button_Click Event runs on the UI thread.
LabRes.Text = "Searching devices..."
the user will not see this text until the method finnished.
add this
LabRes.Text = "Searching devices..."
application.doevents()
It allows the UI to update while running code.
To get bluetooth devices in range
Private Sub SurroundingSub()
Dim client As BluetoothClient = New BluetoothClient()
Dim items As List(Of String) = New List(Of String)()
Dim devices As BluetoothDeviceInfo() = client.DiscoverDevicesInRange()
For Each d As BluetoothDeviceInfo In devices
items.Add(d.DeviceName)
Next
End Sub
Upvotes: 0