I am trying to auto-detect arduino com ports whenever it is connected to my laptop. I could not find much information about device ip and device description detection of a USB device on the forum. I found a code in C# which does that but I could not understand how to implement it in B4J given it is made in Java.
Here is the c# code:
Here is the link: https://stackoverflow.com/a/5397732/6348662
Here is the c# code:
B4X:
private string AutodetectArduinoPort()
{
ManagementScope connectionScope = new ManagementScope();
SelectQuery serialQuery = new SelectQuery("SELECT * FROM Win32_SerialPort");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(connectionScope, serialQuery);
try
{
foreach (ManagementObject item in searcher.Get())
{
string desc = item["Description"].ToString();
string deviceId = item["DeviceID"].ToString();
if (desc.Contains("Arduino"))
{
return deviceId;
}
}
}
catch (ManagementException e)
{
/* Do Nothing */
}
return null;
}
Here is the link: https://stackoverflow.com/a/5397732/6348662