コード例 #1
0
        public SmartScopeUsbInterfaceXamarin(Context context, UsbManager usbManager, UsbDevice device)
        {
            Destroyed = false;
            if(!usbManager.HasPermission(device))
            {
                Logger.Error("Permission denied");
                throw new Exception("Device permission not obtained");
            }

            UsbInterface interf = device.GetInterface(0);
            for (int i = 0; i < interf.EndpointCount; i++)
            {
                if (interf.GetEndpoint(i).EndpointNumber == 1)
                    dataEndpoint = interf.GetEndpoint(i);
                else if (interf.GetEndpoint(i).EndpointNumber == 2)
                    commandWriteEndpoint = interf.GetEndpoint(i);
                else if (interf.GetEndpoint(i).EndpointNumber == 3)
                    commandReadEndpoint = interf.GetEndpoint(i);
            }
            usbConnection = usbManager.OpenDevice(device);
            usbConnection.ClaimInterface(interf, true);
        }
コード例 #2
0
 protected void CreateConnection()
 {
     if (UsbManager != null && UsbDevice != null) {
         lock (mReadBufferLock) {
             lock (mWriteBufferLock) {
                 Connection = UsbManager.OpenDevice (UsbDevice);
             }
         }
     }
 }
コード例 #3
0
 protected void CloseConnection()
 {
     if (Connection != null) {
         lock (mReadBufferLock) {
             lock (mWriteBufferLock) {
                 Connection.Close();
                 Connection = null;
             }
         }
     }
 }
コード例 #4
0
        public async Task<bool> OpenAsync()
        {
            if (connected)
                return false;

            usbManager.RequestPermission(usbDevice, PendingIntent.GetBroadcast(ConnectionService.Instance.Context, 0, new Intent(ConnectionService.Instance.ActionUsbPermission), PendingIntentFlags.CancelCurrent));


            UsbInterface intf = usbDevice.GetInterface(0);
            pinReportEndpoint = intf.GetEndpoint(0);
            peripheralResponseEndpoint = intf.GetEndpoint(1);
            pinConfigEndpoint = intf.GetEndpoint(2);
            peripheralConfigEndpoint = intf.GetEndpoint(3);
            connection = usbManager.OpenDevice(usbDevice);
            if (connection != null)
            {
                bool intfClaimed = connection.ClaimInterface(intf, true);
                if (intfClaimed)
                {
                    connected = true;
                    return true;
                }
            }
            return false;
        }