예제 #1
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.Main);
			manager = (UsbManager)this.GetSystemService (Context.UsbService);
			tgConnect = FindViewById<ToggleButton>(Resource.Id.toggleButton1);
			Result = FindViewById<TextView>(Resource.Id.textView1);
			tgConnect.CheckedChange += tgConnect_HandleCheckedChange;
		}
        public UsbSerialDevice(UsbManager usbManager, UsbDevice usbDevice, UsbSerialDeviceID id, UsbSerialDeviceInfo info)
        {
            UsbManager = usbManager;
            UsbDevice = usbDevice;
            ID = id;
            Info = info;

            ConstructorInfo cInfo = Info.DriverType.GetConstructor(new Type[] { typeof(UsbManager), typeof(UsbDevice), typeof(int) });
            if (cInfo == null) {
                throw new InvalidProgramException ();
            }

            Ports = new UsbSerialPort[info.NumberOfPorts];
            for (int i = 0; i < Info.NumberOfPorts; i++) {
                Ports[i] = (UsbSerialPort)cInfo.Invoke(new object[] { UsbManager, UsbDevice, i });
            }
        }
        public UsbSerialPort(UsbManager manager, UsbDevice device, int portNumber)
        {
            Baudrate = DefaultBaudrate;
            DataBits = DefaultDataBits;
            Parity = DefaultParity;
            StopBits = DefaultStopBits;

            UsbManager = manager;
            UsbDevice = device;
            mPortNumber = portNumber;

            mInternalReadBuffer = new byte[DEFAULT_INTERNAL_READ_BUFFER_SIZE];
            mTempReadBuffer = new byte[DEFAULT_TEMP_READ_BUFFER_SIZE];
            mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE];
            mReadBufferReadCursor = 0;
            mReadBufferWriteCursor = 0;
            mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE];
        }
        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);
        }
 public CdcAcmSerialPort(UsbManager usbManager, UsbDevice usbDevice, int portNumber)
     : base(usbManager, usbDevice, portNumber)
 {
     mEnableAsyncReads = (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1);
 }
 public ProlificSerialPort(UsbManager manager, UsbDevice device, int portNumber)
     : base(manager, device, portNumber)
 {
 }
 public Cp21xxSerialPort(UsbManager manager, UsbDevice device, int portNumber)
     : base(manager, device, portNumber)
 {
 }
 public UsbSerialDeviceBroadcastReceiver(UsbSerialDeviceManager manager, UsbManager usbManager, string actionUsbPermission)
 {
     DeviceManager = manager;
     UsbManager = usbManager;
     ActionUsbPermission = actionUsbPermission;
 }
 private UsbSerialDevice GetDevice(UsbManager usbManager, UsbDevice usbDevice, bool allowAnonymousCdcAcmDevices)
 {
     UsbSerialDeviceID id = new UsbSerialDeviceID(usbDevice.VendorId, usbDevice.ProductId);
     UsbSerialDeviceInfo info = FindDeviceInfo (id);
     if (info != null) {
         UsbSerialDevice device = new UsbSerialDevice(usbManager, usbDevice, id, info);
         return device;
     }
     else if (allowAnonymousCdcAcmDevices && usbDevice.DeviceClass == UsbClass.Comm)
     {
         UsbSerialDevice device = new UsbSerialDevice(usbManager, usbDevice, id, UsbSerialDeviceInfo.CdcAcm);
         return device;
     }
     return null;
 }
 //
 internal void AddDevice(UsbManager usbManager, UsbDevice usbDevice)
 {
     UsbSerialDevice serialDevice = GetDevice(usbManager, usbDevice, AllowAnonymousCdcAcmDevices);
     if (serialDevice != null)
     {
         lock (AttachedDevicesSyncRoot) {
             AttachedDevices.Add (serialDevice);
             if (DeviceAttached != null) {
                 DeviceAttached (this, new UsbSerialDeviceEventArgs (serialDevice));
             }
         }
     }
 }
 public UsbConnection(UsbDevice device, UsbManager manager)
 {
     this.usbDevice = device;
     this.usbManager = manager;
 }