I have two USB receivers for bar-code scanners connected to a raspberry pi3 (Windows IOT Core).
I can connect to them and list the USB Virtual COM devices and connect to them and receive data. But I can't differentiate between the two, the IDs are identical and the system is not providing Port numbers.
When I call Current.portnumber.ToString() the string is empty.
I am hoping to assign each device to a person and have them scan a bar-code for their username and would like to display which scanner is associated with which person (Such as Com5 = Bill Com6 = Dave) but just can't find a unique identifier for each virtual com
private async void ListAvailablePorts()
{
try
{
string aqs = SerialDevice.GetDeviceSelector();
var infos = await DeviceInformation.FindAllAsync(aqs);
foreach (var info in infos)
{
var serialDevice = await SerialDevice.FromIdAsync(info.Id);
DeviceInformation Current = info as DeviceInformation;
if (serialDevice != null && Current.Name == "USB Virtual COM")
{
listOfDevices.Add(Current);
ComList.Items.Add(Current.Name.ToString());
}
}
DeviceList.ItemsSource = listOfDevices;
ComList.SelectedIndex = -1;
DeviceList.SelectedIndex = -1;
}
catch (Exception ex)
{
txtUser.Text = ex.Message;
}
}
After additional scrutiny I found that the ID fields are different on a single digit within an 86 character string.
\\?\USB#VID_0416&PID_5011#5&3753427a&0&5#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
VS
\\?\USB#VID_0416&PID_5011#5&3753427a&0&2#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
Thanks
Related
I have an specific issue about the Bluetooth BLE API on Windows 10.
At the moment I'm programming a tool on C# (Visual Studio) which connects itself to a given BLE - Device. Currently the connection works perfect and I can read out the ServiceUUIDs and the CharacterUUIDs.
The main Problem is after I try to read the value of the Character its always returns me 00. I heard that implementing a notification will change that and I followed these instructions but they didn't help me.
(Here are the Specifications from bluetooth.com:)
My Code:
//connect to BluetoothDevice
var device = await BluetoothLEDevice.FromIdAsync(address);
//get UUID of Services
var services = await device.GetGattServicesAsync();
if (services != null)
{
foreach (var servicesID in services.Services)
{
//if there is a service thats same like the Battery Service
if (servicesID.Uuid.ToString() == BluetoothBLE.Constants.BATTERY_SERVICE)
{
//updateServiceList is like a console logging in my tool
updateServiceList($"Service: {servicesID.Uuid}");
var characteristics = await servicesID.GetCharacteristicsAsync();
foreach (var character in characteristics.Characteristics)
{
if (Constants.BATTERY_LEVEL == character.Uuid.ToString())
{
updateServiceList("C - UUID: "+ character.Uuid.ToString());
GattReadResult result = await character.ReadValueAsync();
if (result.Status == GattCommunicationStatus.Success)
{
var reader = DataReader.FromBuffer(result.Value);
byte[] input = new byte[reader.UnconsumedBufferLength];
reader.ReadBytes(input);
System.Diagnostics.Debug.WriteLine(BitConverter.ToString(input));
}
}
}
}
After Running my Code, the system logs 00. The characterUUID for battery level (0x2A19, from https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml) was read successfully but the value is strange..
I have a USB Hub of 10 USB slots connected to my USB Port. I want to get the USB device connected to the specific port. Example: Two USB's are connected at Slot 3 and Slot 7. So, I want a list which will show Slot 3 and Slot 7 have USB and rest slot are empty.
I have tried using WMI Query Win32_USBHub. But here I am only getting 6 device IDs and not 10. I am differentiating the ports using common VID for the Device ID.
But still even after getting the USB's connected to the specific port. I want to get their corresponding slot in which they are connected to USBHub.
I am not able to identify the slot in which the USB is connected and where the slot is empty.
ManagementObjectCollection collection;
var searcher = new ManagementObjectSearcher(#"Select * From Win32_USBHub");
collection = searcher.Get();
I would try to extract location information from the USB device (the same as in device manager)... I do not code in C# nor WMI but you should be able to obtain this kind of info with setupapi.h which is part of winapi (I think) I do it like this in C++/VCL:
#include <setupapi.h>
bool USBinfo()
{
int i,n;
AnsiString s,txt="";
DWORD dwSize,dwPropertyRegDataType;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
TCHAR szDesc[1024];
// List all connected USB devices
hDevInfo = SetupDiGetClassDevs(NULL, TEXT("USB"), NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);
if (hDevInfo == INVALID_HANDLE_VALUE) return false;
for (i=0;;i++)
{
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData)) break;
SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
s=szDesc; n=48; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" "; // this just set constant string size to allign the columns to n chars
SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_HARDWAREID,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
s=szDesc; if (s=="USB\\VID_????&PID_????REV_????")
{
// here you can do custom stuff for specific VID,PID just change the ???? in above line to your specific VID,PID,REV
}
s=szDesc; n=64; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" ";
SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_LOCATION_INFORMATION,&dwPropertyRegDataType, (BYTE*)szDesc,sizeof(szDesc),&dwSize);
s=szDesc; n=64; while (s.Length()<n) s+=" "; if (s.Length()>n) s=s.SubString(1,n); txt+=s+" ";
txt+="\r\n";
}
Main->mm_log->Lines->Add(txt); // this just output txt string to memo
return true;
}
Here output on my machine:
USB Root Hub USB\ROOT_HUB&VID1022&PID7807&REV0011 USB\ROOT_HUB&VID1022&PID7807&REV0011
USB Root Hub USB\ROOT_HUB&VID1022&PID7807&REV0011 USB\ROOT_HUB&VID1022&PID7807&REV0011
USB Root Hub USB\ROOT_HUB&VID1022&PID7809&REV0011 USB\ROOT_HUB&VID1022&PID7809&REV0011
USB Root Hub USB\ROOT_HUB20&VID1022&PID7808&REV0011 USB\ROOT_HUB20&VID1022&PID7808&REV0011
USB Root Hub USB\ROOT_HUB20&VID1022&PID7808&REV0011 USB\ROOT_HUB20&VID1022&PID7808&REV0011
USB Composite Device USB\VID_048D&PID_9006&REV_0200 Port_#0001.Hub_#0004
IT9135 BDA Device USB\VID_048D&PID_9006&REV_0200&MI_00 0000.0013.0002.001.000.000.000.000.000
USB Input Device USB\VID_048D&PID_9006&REV_0200&MI_01 0000.0013.0002.001.000.000.000.000.000
Canon LiDE 30 USB\VID_04A9&PID_220E&REV_0100 Port_#0005.Hub_#0001
American Power Conversion USB UPS USB\VID_051D&PID_0002&REV_0106 Port_#0001.Hub_#0001
USB Input Device USB\Vid_093A&Pid_2510&Rev_0100 USB Optical Mouse
USB Input Device USB\VID_413C&PID_2107&REV_0115 Port_#0002.Hub_#0001
As you can see the last column (3th) holds the info you want. Look inside setupapi.h for all the SPDRP_ defines you can use ... The only thing used from VCL is AnsiString so change it to any string type you have at your disposal.
This is not restricted to USB. If you want all the devices then change TEXT("USB") search parameter to NULL
hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);
static int GetPhysicalPort()
{
try
{
devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(#"Select * From Win32_PnPSignedDriver WHERE DeviceId LIKE 'USB\\VID%' AND Description = 'USB Mass Storage Device' "))
{
collection = searcher.Get();
searcher.Dispose();
}
foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceId"),
(string)device.GetPropertyValue("Description"),
(string)device.GetPropertyValue("Location")
));
}
collection.Dispose();
string LastAdded = devices[0].Location.Substring(6, 4);
Console.WriteLine(LastAdded);
return Convert.ToInt32(LastAdded);
}
catch (Exception e)
{
Console.WriteLine(e);
return 0;
}
}
class USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string Description, string location)
{
this.DeviceID = deviceID;
this.Desc = Description;
this.Location = location;
}
public string DeviceID { get;}
public string Desc { get;}
public string Location { get;}
}
I am using this Method to take the slot you are asking for. In fact I take the slot of the last plugged in USB due to the requirements I have. You can just debug and see the content of the class USBDeviceInfo and then use it for your own purpose.
I'm trying to rename a Bluetooth device from a Windows Phone 8 app. I know the AT commands to send to the device but i belive I connecto to the device somhow wrong.
I have an old PDA program that can rename my device, and that program is the source of my AT commands som I'm pretty sure they are correct.
If I start a Datalogger and rename my device from my PDA no data appears in the log, if I do the same from my phone I get all the commands in my Datalogger.
Here is how I connect to my device in my windows phone App:
public void Rename()
{
var info = GetPeerInfo();
/*
GetPeerInfo() gives me the PeerInformation of my device and it works as expected.
*/
if (info == null)
return;
socket = new StreamSocket();
Task.Run(async () => { await socket.ConnectAsync(info.HostName, "1"); }).Wait();
var dataWriter = new DataWriter(socket.OutputStream);
/*
Note
"to" is an internal class containg the new name of my bluetooth device, its bluetooth config etc.
"newLaneNumber" is an integer indicading a postfix to the new name
*/
UpdateDisplayName(dataWriter, to, newLaneNumber);
Task.Run(async () => { await dataWriter.StoreAsync(); }).Wait();
socket.Dispose();
socket = null;
return;
}
This is the method sending the AT commands
private void UpdateDisplayName_Other(DataWriter dataWriter, InspectionTester newDisplayname, int newLaneNumber)
{
//Login
Thread.Sleep(6000);
dataWriter.WriteString("///");
Thread.Sleep(6000);
var bluetoothDefault = new string[]
{
"AT*AGLC=0,1",
"AT*AGCM=2,1",
"AT*AGDM=3,1",
"AT*AGPM=2,1", // pairable (not pairable: "AT*AGPM=1,1")
"AT*AGFP="+'"'+"0"+'"'+",1",
"AT*AGSM=1,1",
"AT*ADDSP=0,1",
"AT*AGMSP=1,1",
"AT*ADDCP=255,1",
"AT*ADNRP=0,1",
"AT*AMSIT=1,1",
"AT*AMET=5000,5000,1",
"AT*AMLP=0,0,1",
"AT*AMMP=255,1",
"AT*AMWFM=1,6,1",
"AT*AMPM=1,1",
"AT*ACCB=1,1",
"AT*AMDS=1,1,1",
"AT*AMWS=0,0,0,0,0,1"
};
var tmpString = string.Empty;
foreach (var element in bluetoothDefault)
{
tmpString = element + "\r";
dataWriter.WriteString(tmpString);
Thread.Sleep(100);
}
//Name
tmpString = "AT*AGLN=\"" + to.BluetoothName + newLaneNumber.ToString("D2") + "\",1\r";
dataWriter.WriteString(tmpString);
Thread.Sleep(100);
//Baudrate
tmpString = "AT*AMRS=" + to.BluetoothConfig + "\r";
dataWriter.WriteString(tmpString);
//Logout
tmpString = "AT*AMWS=0,0,0,0,1,0\r";
dataWriter.WriteString(tmpString);
}
Some where I'm doing something wrong, I belive I connect the wrong way but I can't find any information about how else to do it.
Here is a log taken from an update attempt from the phone :
///AT*AGLC=0,1
AT*AGCM=2,1
AT*AGDM=3,1
AT*AGPM=2,1
AT*AGFP="0",1
AT*AGSM=1,1
AT*ADDSP=0,1
AT*AGMSP=1,1
AT*ADDCP=255,1
AT*ADNRP=0,1
AT*AMSIT=1,1
AT*AMET=5000,5000,1
AT*AMLP=0,0,1
AT*AMMP=255,1
AT*AMWFM=1,6,1
AT*AMPM=1,1
AT*ACCB=1,1
AT*AMDS=1,1,1
AT*AMWS=0,0,0,0,0,1
AT*AGLN="BMGTMGA1-01",1
AT*AMRS=5,1,2,2,2,1,1
AT*AMWS=0,0,0,0,1,0
If you need some more information please say so.
1point: most of the device don,t support the rename. Some of them just support it by saving the infomation in the RAM ,not the flash or EEPROM .
I'm attempting to write a C# library which looks at all available USB serial ports on a Raspberry Pi so that I can enumerate, identify and communicate with a set of Arduinos connected to the Pi via a USB hub.
I am able to make this work on my windows machine (several Arduinos connected to my desktop computer) and have even been able to make it work on my Pi however, I am struggling to understand how to generalize the fix.
If I attempt to run the program by itself on the Pi, I am able to open the serial port and send data however, I cannot receive anything from the Arduinos: I get timeout exceptions. I understand that Mono's implementation of SerialPort is limited and I must use SerialPort.ReadByte() instead of Readline() and the data received events (my solution is based on code from HowToSystemIOPorts). My Serial port enumeration is using a method outlined in another stack exchange response here.
My timeout is currently set to 4 seconds, which is several orders of magnitude longer than I expect to receive the message.
After a lot of googling, I came across mention of using minicom to initialize the serial port here, which to my surprise allowed me to receive data from the Arduino. The biggest drawback is that I need to initialize the port using minicom and leave the process opening each time I boot the Pi. I also can't seem to figure out how to make this work with multiple Arduinos.
Here is what I have tried so far:
Updated the Pi firmware and software to their latest versions
Attempted to use both an Arduino MEGA 2560 R3 and Arduino UNO
Changed the owner of the tty* ports (ttyACM0 and ttyUSB0 in this case) to both my user and group
Successfully configured the port via minicom, left the process running and start the program and read/wrote data. A manual process which only seems to work for one Arduino at a time
Successfully run the program in Windows without fault
Verified the Arduinos are recognized by the Pi running "dmesg | grep tty"
Here is what I hope to solve:
Automatic setup/initialization of the Arduino serial ports. Whether through a shell script run before the main program or within Mono code so that the code below can run as intended.
Here is my connection code:
public bool StartArduinoComms()
{
string[] ports = GetPortNames();
foreach (string port in ports)
{
mLogger.LogMessage(ProsthesisCore.Utility.Logger.LoggerChannels.Arduino, string.Format("Found serial port {0}", port));
}
bool foundCorrectArduino = false;
var idPacket = new ArduinoMessageBase();
idPacket.ID = ArduinoMessageValues.kIdentifyValue;
string jsonOutput = Newtonsoft.Json.JsonConvert.SerializeObject(idPacket);
foreach (string port in ports)
{
SerialPort serialPort = new SerialPort(port, kArduinoCommsBaudRate);
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
//Only check unopened ports
if (!serialPort.IsOpen)
{
serialPort.Open();
//Disable telemtry just incase
var toggle = new { ID = ArduinoMessageValues.kTelemetryEnableValue, EN = false };
string disableTelem = Newtonsoft.Json.JsonConvert.SerializeObject(toggle);
serialPort.Write(disableTelem);
//Discard any built up data
serialPort.DiscardInBuffer();
serialPort.Write(jsonOutput);
serialPort.ReadTimeout = kIDTimeoutMilliseconds;
string response = string.Empty;
for (int i = 0; i < kNumRetries; ++i)
{
try
{
//This is guaranteed to timeout if not configured through minicom
response = ReadLine(serialPort);
break;
}
//Catch case where the serial port is unavailable. MOve to next port
catch (TimeoutException)
{
continue;
}
}
if (!string.IsNullOrEmpty(response))
{
//Perform response validation
}
else
{
//Got no response
}
if (!foundCorrectArduino)
{
serialPort.Close();
}
}
}
return foundCorrectArduino;
}
/// <summary>
/// From https://stackoverflow.com/questions/434494/serial-port-rs232-in-mono-for-multiple-platforms
/// </summary>
/// <returns></returns>
private static string[] GetPortNames()
{
int p = (int)Environment.OSVersion.Platform;
List<string> serial_ports = new List<string>();
// Are we on Unix?
if (p == 4 || p == 128 || p == 6)
{
string[] ttys = System.IO.Directory.GetFiles("/dev/", "tty*");
foreach (string dev in ttys)
{
//Arduino MEGAs show up as ttyACM due to their different USB<->RS232 chips
if (dev.StartsWith("/dev/ttyS") || dev.StartsWith("/dev/ttyUSB") || dev.StartsWith("/dev/ttyACM"))
{
serial_ports.Add(dev);
}
}
}
else
{
serial_ports.AddRange(SerialPort.GetPortNames());
}
return serial_ports.ToArray();
}
Have a look at stty command. It will let you set/read teminal settings
http://linux.about.com/od/lna_guide/a/gdelna38t01.htm will give a rundown on it's use.
It would be easier to call out to than minicom, and the settings stay on the device.
I have done something like the same as you before.
I had to read and write data through USB Serial adapter, and didnt use minicom.
It may not be god code but i found that inorder to read the data I could create a new thread and have that check for data, my code include a lot of stuff but basicly i did this:
System.Threading.Thread newThread;
newThread = new System.Threading.Thread(this.check_get_data);
and the check_get_data method
public void check_get_data ()
{
byte tmpByte = 0;
while (m_objSerialPort.BytesToRead != 0) {
tmpByte = (byte)m_objSerialPort.ReadByte ();
DoSomethingWithByte(tmpByte);
Thread.Sleep(20);
}
}
this is currently running with two usbserials. dont know if it helps but hope you find your solution
My company developed a device that communicates with a PC via Bluetooth using a virtual COM port.
Now we need a user to pair a device with a PC (MS Windows OS) first and then enter it's com port number manually into our application(I bet 95% of users will fail on this taks).
So I'd like my application to present a user with a list of paired bluetooth devices (a list of their "friendly names") and after that I'd like to find out the selecded device's COM port number automatically.
How can I do it in c#? (a solution independent of installed bluetooth stack is appreciated).
Thanks in advance.
See my answer at Widcomm bluetooth : how to open the virtual COM for my understanding of the licence: using the binary version is free for commercial use. And, also that I'm maintainer of the library.
So a brief slight digression. I'm not a big fan of virtual COM ports. It always seems much easier to use a direct 'sockets' connection, rather than attempt to setup a COM port, and try to find what name it was created as (see below!), and then have to open a SerialPort to use it, and then if the connection is lost one doesn't know and have simply to keep retrying... With the library its so much easier to just to create and use that direct Bluetooth connection!
However you may want a solution to your current task at the moment. :-) So, use WMI to find the current COM ports in place and see if any of them are for your device. For example in PowerShell:
C:\> Get-WmiObject -query "select DeviceID,PNPDeviceID from Win32_SerialPort"
...
...
DeviceID : COM66
PNPDeviceID : BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}\7&1D80ECD3&0&00803A686519_C00000003
In that big long string one sees the address of the target device: 00803A686519. One can use WMI from .NET, run that query, filter the ones with "BTHENUM", and then parse out the address.
If you the do need to create a new Bluetooth virtual COM port, use 32feet.NET's BluetoothDeviceInfo.SetServiceState(BluetoothService.SerialPort) API. See the "Bluetooth Serial Ports" section in the User Guide e.g. at http://www.alanjmcf.me.uk/comms/bluetooth/32feet.NET%20--%20User%20Guide.html, and the class documentation in the release.
Unfortunately the native Win32 API we call does not tell what name of COM port it created! :-( So run the WMI query before and after the call to see what new name appeared (or use System.IO.Ports.SerialPort.GetPortNames as its simpler).
That's all specific to the Microsoft Bluetooth stack. I haven't investigated how other stacks behave in this regard. After a brief check Widcomm's serial ports appear in SerialPort.GetPortNames but not in the WMI query...
First, create a Management Object Searcher to search the WMI database:
ManagementObjectSearcher serialSearcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SerialPort");
Next, use LINQ to get all the serial ports into a query:
var query = from ManagementObject s in serialSearcher.Get()
select new { Name = s["Name"], DeviceID = s["DeviceID"], PNPDeviceID = s["PNPDeviceID"] }; // DeviceID -- > PNPDeviceID
You can now print all the COM ports, their friendly names and you can even filter through their PNPDeviceID's to find the bluetooth device address. Here's an example:
foreach (var port in query)
{
Console.WriteLine("{0} - {1}", port.DeviceID, port.Name);
var pnpDeviceId = port.PNPDeviceID.ToString();
if(pnpDeviceId.Contains("BTHENUM"))
{
var bluetoothDeviceAddress = pnpDeviceId.Split('&')[4].Split('_')[0];
if (bluetoothDeviceAddress.Length == 12 && bluetoothDeviceAddress != "000000000000")
{
Console.WriteLine(" - Address: {0}", bluetoothDeviceAddress);
}
}
}
I manage to get the bluetooth name and the COM port by fiddling the registry key
The pseudo code to obtain the bluetooth information is below:
enumerate all the COM port available in the PNP
obtain the device classGuid
search the bluetooth address from the classGuid
when the bluetooth address is known, the bluetooth name can be obtained from the this registry SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices
The code is below, just call the GetBluetoothPort(), it will return a list of bluetooth devices, and you could connect them by passing the COM port number to the SerialPort class
public static string[] GetBluetoothPort()
{
Regex regexPortName = new Regex(#"(COM\d+)");
List<string> portList = new List<string>();
ManagementObjectSearcher searchSerial = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity");
foreach (ManagementObject obj in searchSerial.Get()) {
string name = obj["Name"] as string;
string classGuid = obj["ClassGuid"] as string;
string deviceID = obj["DeviceID"] as string;
if (classGuid != null && deviceID != null) {
if (String.Equals(classGuid, "{4d36e978-e325-11ce-bfc1-08002be10318}", StringComparison.InvariantCulture)) {
string[] tokens = deviceID.Split('&');
if (tokens.Length >= 4) {
string[] addressToken = tokens[4].Split('_');
string bluetoothAddress = addressToken[0];
Match m = regexPortName.Match(name);
string comPortNumber = "";
if (m.Success) {
comPortNumber = m.Groups[1].ToString();
}
if (Convert.ToUInt64(bluetoothAddress, 16) > 0) {
string bluetoothName = GetBluetoothRegistryName(bluetoothAddress);
portList.Add(String.Format("{0} {1} ({2})", bluetoothName, bluetoothAddress, comPortNumber));
}
}
}
}
}
return portList.ToArray();
}
private static string GetBluetoothRegistryName(string address)
{
string deviceName = "";
string registryPath = #"SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices";
string devicePath = String.Format(#"{0}\{1}", registryPath, address);
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(devicePath)) {
if (key != null) {
Object o = key.GetValue("Name");
byte[] raw = o as byte[];
if (raw != null) {
deviceName = Encoding.ASCII.GetString(raw);
}
}
}
return deviceName;
}
Maybe it is not what you are looking for, and maybe you already found your answer...
I just found a question not exactly like yours but worked for me.. With this one you can find out which one of your COM Ports are from a Bluetooth device:
StackOverflow - Determine if serial port is normal COM or SPP
I hope it helps somehow. If you find out how to do what you wanted, please let me know. Thanks.
So, to get the information about a remote device including its name, using 32feet.NET do:
BluetoothAddress addr = ... ...
BluetoothDeviceInfo info = new BluetoothDeviceInfo(addr);
string name = info.DeviceName;
If not using the library you'll have to P/Invoke Win32's BluetoothGetDeviceInfo.
private static string FindSerialPortForRFIDReaderCore()
{
string serialPort = "";
List<string> ports = new List<string>();
System.Management.ManagementObjectSearcher Searcher = new System.Management.ManagementObjectSearcher("Select * from WIN32_SerialPort");
foreach (System.Management.ManagementObject Port in Searcher.Get())
{
if (Port["PNPDeviceID"].ToString().ToUpper().Contains("MacAddress"))
ports.Add(Port["DeviceID"].ToString());
}
if (ports.Count > 1) // There are more than one Serial Ports created for the bluetooth device.
serialPort = ports.OrderByDescending(p => p).FirstOrDefault();
else if(ports.Count == 1)
serialPort = ports[0];
return serialPort;
}