我试图创建一个.NET Maui应用程序,从通过USB(RS-232仿真)连接的设备(条形码扫描仪)读取,但我仍然无法获得打开和端口打开的权限。当然,我也有兴趣从港口阅读。请不要有你的成功的解决方案可用?不幸的是,我在.NET Maui文档中找不到任何东西。
这是我的代码,基于[https://stackoverflow.com/questions/73534644/how-to-write-raw-data-to-usb-connected-device-using-net-maui]中的示例:
Activity act = Platform.CurrentActivity;
UsbManager manager = (UsbManager)act.GetSystemService(Context.UsbService);
IDictionary<string, UsbDevice> devicesDictionary = manager.DeviceList;
UsbDevice dvc = _usbDevice; // I find _usbDevice successfully
string ACTION_USB_PERMISSION = "com.MauiAndroidSerialPort.USB_PERMISSION";
var interf = dvc.GetInterface(1);
var 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);
var deviceConnection = manager.OpenDevice(dvc);
if (deviceConnection != null)
deviceConnection.ClaimInterface(interf, true).ToString();
我获取设备,但应用程序在行“PendingIntent mPermissionIntent = PendingIntent.GetBroadcast(act,0,new Intent(ACTION_USB_PERMISSION),0);“
1条答案
按热度按时间v8wbuo2f1#
外部条形码扫描仪的作用类似于外部键盘,并将
types
识别的条形码文本发送到活动控件。有一个活动的文本输入控件,并确保它不会失去与外部条形码阅读器扫描时的重点。而当读取条形码时,它值就会出现在控件中。