Calling the 32feet.net assembly from powershell.

Topics: Bluetooth - Microsoft
Oct 17, 2013 at 11:43 AM
Hello, i'm writing a script in powershell with the purpouse to connect to a bluetooth device over SPP serial and getting some data from a gps app. All that is done, but i cant find how to search for available services that the bluetooth device offers, and connect to them.
Then i found this neat package, so i have one question.
Is there any way to call this library from powershell ?

I want it to find the services a specific bluetooth device offers.
i want to find the SPP service, connect to it and assign a comport.

The rest is done in powershell, including connecting to the port and getting the data i want.

All the help would be appreciated :)

/Sebastian
Developer
Oct 17, 2013 at 6:56 PM
See 32feet.NET and shells

e.g.
PS C:\Users\alan\Documents> Add-Type -path ".\some path\InTheHand.Net.Personal.dll"
PS C:\Users\alan\Documents> $cli = New-Object InTheHand.Net.Sockets.BluetoothClient

PS C:\Users\alan\Documents> $cli.DiscoverDevicesInRange()
[...]
[...]
Oct 18, 2013 at 7:11 AM
Edited Oct 18, 2013 at 8:30 AM
Thanks.
That i get to work.
But how do i access the Bluetooth.Services from there ?


i have tried this instead
But i get this error message, and it loads only the "members" from .Sockes.BluetoothClient.
I want to be able to discover abailable Bluetooth services offered by a specific device. in this case a Serial SPP port. And connect to it so it gets a comport assigned.
I've managed to work out the rest of the script, like connecting to the port, getting the information i want, and send it to the clipboard :)
PS C:\Users\Sebastian> Add-Type -path "C:\Program Files (x86)\32feet.NET\NET\InTheHand.Net.Personal.dll" 
$cli = New-Object InTheHand.Net.Bluetooth.BluetoothService
$cli | Get-Member
New-Object : Constructor not found. Cannot find an appropriate constructor for type InTheHand.Net.Bluetooth.BluetoothService.
At line:2 char:8
+ $cli = New-Object InTheHand.Net.Bluetooth.BluetoothService
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
Developer
Oct 24, 2013 at 9:36 AM
I've hardly any experience with PowerShell but after a bit of googling, the following seems to be the solution.
$addr = [InTheHand.Net.BluetoothAddress]::Parse("00:11:22:33:44:55")
$dev = New-Object InTheHand.Net.Sockets.BluetoothDeviceInfo($addr)
$dev.SetServiceState([InTheHand.Net.Bluetooth.BluetoothService]::SerialPort, 1, 1)
Marked as answer by alanjmcf on 10/29/2013 at 3:52 PM