I'm trying to get information about the USB Devices connected to my MacBook Pro Mid 2012 using MAUI .NET. Specifically the VID and PID of the device.
More details about my project:
How can I accomplish what I'm trying to do?
Thank you
I found a workaround.
Here are the steps:
You might need to edit it, in order to filter to your specific needs. You need to modify the script (lsusb.sh) to return the BSD Name. If you want to get the device mount point in the steps ahead.
After editing the script and confirming the it works in the terminal. Place it in the .NET MAUI app inside the "Resources/Raw" folder
Make sure the build properties for the shell file are - Build action: Maui Asset, and Copy to directory: Always copy
Run the script in your app using the following code -
public string GetUsbDeviceInfoString()
{
string AppDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string scriptPath = AppDirectory.Replace("MonoBundle", "Resources/lsusb.sh");
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "/bin/bash";
p.StartInfo.Arguments = " -c \"" + "sh \'"+ scriptPath + "\' \"";
p.Start();
// To avoid deadlocks, always read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
NOTE!!! I found a bug, the script files don't work if you build the project and release it as a package (.pkg). The scripts only work if you build release the app as a .app file.