![](/img/trans.png)
[英]how to translate USB Video Class (UVC) into raw USB device data?
[英]How to write raw data to usb connected device using .NET MAUI
我想編寫一個應用程序,將原始數據發送到通過 USB 電纜連接到我的 Android 操作系統手機的設備。 為此,我想使用 .NET MAUI。 我知道這是一個相當新的框架,但我想試一試。 我想知道是否有一種方法可以使用 System.IO 命名空間中的 SerialPort 或其他一些允許我完成此任務的庫。 到目前為止,我已經找到了一個Device.Net庫,但它不支持 .NET MAUI。 如果/如何可能,我將非常感謝任何提示。
活動行為 = Platform.CurrentActivity;
UsbManager manager = (UsbManager)act.GetSystemService(Context.UsbService);
IDictionary<string, UsbDevice> devicesDictionary = manager.DeviceList;
UsbDevice dvc = devicesDictionary.ElementAt(0).Value;
string ACTION_USB_PERMISSION = "rzepak";
var interf = dvc.GetInterface(1);
outEndpoint = interf.GetEndpoint(1);
PendingIntent mPermissionIntent = PendingIntent.GetBroadcast(act, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
if (manager.HasPermission(dvc) == false) manager.RequestPermission(dvc, mPermissionIntent);
deviceConnection = manager.OpenDevice(dvc);
if (deviceConnection != null) deviceConnection.ClaimInterface(interf, true).ToString();
else return false;
設備連接是 Android.Hardware.Usb.UsbDeviceConnection 類型,在連接方法中打開):
byte[] test = new byte[] { 輸入 };
if (deviceConnection.BulkTransfer(outEndpoint, test, test.Length, 500) < 0) Connected = false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.