当前位置: 首页>>代码示例>>Java>>正文


Java UsbSerialDriver类代码示例

本文整理汇总了Java中com.hoho.android.usbserial.driver.UsbSerialDriver的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialDriver类的具体用法?Java UsbSerialDriver怎么用?Java UsbSerialDriver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UsbSerialDriver类属于com.hoho.android.usbserial.driver包,在下文中一共展示了UsbSerialDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findUsbSerialPort

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
private UsbSerialPort findUsbSerialPort(ConfigStorage.SerialPortIdentifier identifier) {
    final List<UsbSerialDriver> drivers =
            UsbSerialProber.getDefaultProber().findAllDrivers(mUsbManager);

    for (final UsbSerialDriver driver : drivers) {
        for (final UsbSerialPort port : driver.getPorts()) {
            UsbDevice device = port.getDriver().getDevice();
            if (device != null
                    && device.getVendorId() == identifier.getVendorId()
                    && device.getProductId() == identifier.getProductId()
                    && Objects.equals(device.getSerialNumber(), identifier.getSerialNumber())) {
                return port;
            }
        }
    }

    return null;
}
 
开发者ID:OpilkiInside,项目名称:bimdroid,代码行数:19,代码来源:BmwIBusService.java

示例2: onResume

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
protected void onResume() {
    super.onResume();
    changed=new HandleChange(3);
    calibCounter=0;
    Log.d(TAG, "Resumed, port=" + sPort);
    if (sPort == null) {
        mTitleTextView.setText("No serial device.");
    } else {
        usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
        List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
        if (availableDrivers.isEmpty()) {
            mTitleTextView.append("No drivers available\n");
            Log.d("SerialKost", "no drivers available");
            return;
        }

        UsbSerialDriver driver = availableDrivers.get(0);
        sPort = driver.getPorts().get(0);
        device=driver.getDevice();
        UsbDeviceConnection connection = usbManager.openDevice(device);
        if (connection == null) {
            mTitleTextView.setText("Opening device failed");

            PendingIntent mPermissionIntent;

            Log.i("SerialKost", "Setting PermissionIntent -> MainMenu");
            mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
            Log.i("SerialKost", "Setting IntentFilter -> MainMenu");
            IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
            Log.i("SerialKost", "Setting registerReceiver -> MainMenu");
            registerReceiver(mUsbReceiver, filter);
            Log.i("SerialKost", "Setting requestPermission -> MainMenu");
            usbManager.requestPermission(device, mPermissionIntent);
            return;
        }
        communicate();
    }
}
 
开发者ID:kost,项目名称:DroidMeter,代码行数:40,代码来源:SerialConsoleActivity.java

示例3: openDeviceAsync

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@ReactMethod
public void openDeviceAsync(ReadableMap deviceObject, Promise p) {

    try {
        int prodId = deviceObject.getInt("productId");
        UsbManager manager = getUsbManager();
        UsbSerialDriver driver = getUsbSerialDriver(prodId, manager);

        if (manager.hasPermission(driver.getDevice())) {
            WritableMap usd = createUsbSerialDevice(manager, driver);

            p.resolve(usd);
        } else {
            requestUsbPermission(manager, driver.getDevice(), p);
        }

    } catch (Exception e) {
        p.reject(e);
    }
}
 
开发者ID:mapaiva,项目名称:react-native-usbserial,代码行数:21,代码来源:ReactUsbSerialModule.java

示例4: getUsbSerialDriver

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
private UsbSerialDriver getUsbSerialDriver(int prodId, UsbManager manager) throws Exception {

        if (prodId == 0)
            throw new Error(new Error("The deviceObject is not a valid 'UsbDevice' reference"));

        List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);

        // Reject if no driver is available
        if (availableDrivers.isEmpty())
            throw new Exception("No available drivers to communicate with devices");

        for (UsbSerialDriver drv : availableDrivers) {

            if (drv.getDevice().getProductId() == prodId)
                return drv;
        }

        // Reject if no driver exists for the current productId
        throw new Exception(String.format("No driver found for productId '%s'", prodId));
    }
 
开发者ID:mapaiva,项目名称:react-native-usbserial,代码行数:21,代码来源:ReactUsbSerialModule.java

示例5: LogKeeper

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
/*********************************************************************************
 * Class methods
 *********************************************************************************/

// Create new LogKeeper with Context
private LogKeeper(Context ctx){
    mContext = ctx;
    mEntries = new LinkedList<>();

    // From serial driver
    mManager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE);
    List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(mManager);

    // Collect relevant intents
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    mContext.registerReceiver(mUsbReceiver, filter);

    // Handle if already connected
    if (!availableDrivers.isEmpty()) {
        connectDevice();
    }
}
 
开发者ID:dgcrouse,项目名称:Loggerino,代码行数:25,代码来源:LogKeeper.java

示例6: bindToUsbDevice

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
/**
 * Probes available USB devices and sets serialDriver and serialDriverUsbName if available.
 */
protected void bindToUsbDevice(){
	UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
	HashMap<String, UsbDevice> deviceMap = manager.getDeviceList();
	
	// Find the first available driver.
	final UsbSerialDriver driver = UsbSerialProber.findFirstDevice(manager);
	serialDriver = (CommonUsbSerialDriver)driver;
	serialDriverUsbName = null;
	if(serialDriver == null){
		return;
	}
	UsbDevice device = serialDriver.getDevice();
	
	//Reverse engineer the USB name for presence testing in the future.
	for(String key : deviceMap.keySet()){
		if(deviceMap.get(key).equals(device)){
			serialDriverUsbName = key;
			break;
		}
	}
	if(serialDriverUsbName == null){
		Log.e(TAG, "Could not find the USB name from the serial driver we just got... what?");
	}
}
 
开发者ID:neonbjb,项目名称:MAV-Downlink,代码行数:28,代码来源:IOEndpointAndroidSerial.java

示例7: onAttach

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
  public void onAttach(UsbSerialDriver driver, UsbSerialTransfer.Writer writer) {
    activity.appendStatus("serial onAttach");
    synchronized (writer) {
//      this.driver = driver;
      activity.appendStatus("serial device " + driver.getDevice());
      this.writer = writer;
      byte[] data = {
//          ' ', ' ', ' ', ' ', ' ', ' ', '!', 
//        ' ', ' ', ' ', ' ', ' ', ' ', '!', 
        ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
          '.'};
      writer.write(data);
    }
    activity.onUsb();
  }
 
开发者ID:leorleor,项目名称:double-rainbow-fpv,代码行数:17,代码来源:UsbEngine.java

示例8: handleMessage

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_REFRESH:
                    refreshDeviceList();
                    mHandler.sendEmptyMessageDelayed(MESSAGE_REFRESH, REFRESH_TIMEOUT_MILLIS);
// == added fortunnel app m.s.
                    if ((autoPortSelection > 0) && (countrf++ >= autoPortSelection)) {  // number of refresh before connection
                        for (int i = 0; i < mEntries.size(); i++) {
                            final UsbSerialDriver driver = mEntries.get(i).getDriver();
                            final String vendorId = HexDump.toHexString((short) driver.getDevice().getVendorId());
                            final String productId = HexDump.toHexString((short) driver.getDevice().getProductId());
                            if (vendorId.equals(arduinoVendorId) && productId.equals(arduinoProductId)) {
                                countrf = 0;
                                showConsoleActivity(mEntries.get(i));

                            }
                        }

                    }
// == end added
                    break;
                default:
                    super.handleMessage(msg);
                    break;
            }
        }
 
开发者ID:msillano,项目名称:USBphpTunnel,代码行数:28,代码来源:DeviceListActivity.java

示例9: startNodes

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
public NodeMain[] startNodes(UsbDevice baseUsbDevice, UsbManager usbManager) throws Exception {
    if(baseUsbDevice == null) {
        throw new Exception("null USB device provided");
    }
    log.info("Starting base node");

    // Wrap the UsbDevice in the HoHo Driver
    UsbSerialDriver driver = serialDriverForDevice(baseUsbDevice, usbManager);
    UsbDeviceConnection connection = serialConnectionForDevice(usbManager, driver);

    if (connection == null) {
        throw new Exception("No USB connection available to initialize device");
    }

    UsbSerialPort port = serialPortForDevice(driver);

    // Choose the appropriate BaseDevice implementation for the particular
    // robot base, using the corresponding subclass
    BaseDevice baseDevice = getBaseDevice(port, connection);

    // Create the ROS nodes
    log.info("Create base controller node");
    mBaseControllerNode = new BaseControllerNode(baseDevice, "/cmd_vel");
    NodeConfiguration baseControllerNodeConf = NodeConfiguration.newPublic(mRosHostname);
    baseControllerNodeConf.setNodeName(GraphName.of("base_controller"));
    baseControllerNodeConf.setMasterUri(mRosMasterUri);
    mNodeMainExecutor.execute(mBaseControllerNode, baseControllerNodeConf);

    mBatteryPublisherNode = new RobotBatteryPublisherNode(baseDevice);
    NodeConfiguration batteryPublisherConf = NodeConfiguration.newPublic(mRosHostname);
    batteryPublisherConf.setNodeName(mBaseControllerNode.getDefaultNodeName());
    batteryPublisherConf.setMasterUri(mRosMasterUri);
    mNodeMainExecutor.execute(mBatteryPublisherNode, batteryPublisherConf);

    return new NodeMain[]{mBaseControllerNode, mBaseOdomPublisher};
}
 
开发者ID:ekumenlabs,项目名称:tangobot,代码行数:38,代码来源:AbstractBaseNodeLoader.java

示例10: serialDriverForDevice

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
/**
 * Internal helper method that returns a single UsbSerialDriver from the android_usb_serial
 * library given a UsbDevice for which we already have access to
 */
protected UsbSerialDriver serialDriverForDevice(UsbDevice device, UsbManager usbManager) throws Exception {
    // Wrap the UsbDevice in the HoHo Driver
    List<UsbSerialDriver> driverList = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
    // For now, continue only if we have a single driver in the list
    if (driverList.isEmpty()) {
        throw new Exception("No drivers found for the supplied USB device: " + device);
    }
    if (driverList.size() > 1) {
        log.warn("There are " + driverList.size() + " drivers found for the provided USB device: "
                + device + ". Will continue using the first one in the list");
    }
    return driverList.get(0);
}
 
开发者ID:ekumenlabs,项目名称:tangobot,代码行数:18,代码来源:UsbDeviceNodeLoader.java

示例11: openConnection

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
/**
 * Called once we have permission, this will open a connection to the radio
 */
private void openConnection() {
    Log.v(TAG, "Opening connection to device");

    usbDeviceConnection = usbManager.openDevice(usbDevice);
    UsbSerialDriver driver = new CdcAcmSerialDriver(usbDevice);

    Log.v(TAG, "Device has " + String.valueOf(driver.getPorts().size()) + " ports");
    deviceSerialInterface = driver.getPorts().get(0);

    try {
        deviceSerialInterface.open(usbDeviceConnection);
        deviceSerialInterface.setParameters(RadioDevice.BAUD_RATE, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
        deviceSerialInterface.setDTR(false);
        deviceSerialInterface.setRTS(true);

        readBuffer.clear();

        readBufferFillerThread = new Thread(readBufferFillerRunnable);
        //readBufferFillerThread.start();

        running = true;
        if (connectionStateListener != null) {
            connectionStateListener.onStart();
        }
    } catch (IOException e) {
        e.printStackTrace();
        closeConnection();
        if (connectionStateListener != null) {
            connectionStateListener.onFail();
        }
    }
}
 
开发者ID:freshollie,项目名称:monkeyboard-radio-android,代码行数:36,代码来源:DeviceConnection.java

示例12: openUsbDevice

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
private void openUsbDevice(UsbDevice device) throws IOException {
    // Get UsbManager from Android.
    UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);

    // Find the first available driver.
    sDriver = UsbSerialProber.openUsbDevice(manager, device);

    if (sDriver == null) {
        Log.d("USB", "No Devices found");
        throw new IOException("No Devices found");
    } else {
        Log.d("USB", "Opening using Baud rate " + mBaudRate);
        try {
            sDriver.open();
            sDriver.setParameters(mBaudRate, 8, UsbSerialDriver.STOPBITS_1,
                    UsbSerialDriver.PARITY_NONE);
        } catch (IOException e) {
            Log.e("USB", "Error setting up device: " + e.getMessage(), e);
            try {
                sDriver.close();
            } catch (IOException e2) {
                // Ignore.
            }
            sDriver = null;
        }
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:28,代码来源:UsbCDCConnection.java

示例13: onResume

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();
    if (currentTimeLeft != 0) {
        countDownTimerWithPause = new GameCountDownTimer(currentTimeLeft, UPDATE_INTERVAL, NOT_RUN_AFTER_CREATION);
    } else {
        countDownTimerWithPause = new GameCountDownTimer(GAME_TIME_DEFAULT, UPDATE_INTERVAL, NOT_RUN_AFTER_CREATION);
    }

    final UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
    if (availableDrivers.isEmpty()) {
        Toast.makeText(this, "USB devices Not found", Toast.LENGTH_SHORT).show();
    } else {
        UsbSerialDriver driver = availableDrivers.get(0);
        usbSerialPort = driver.getPorts().get(0);

        UsbDeviceConnection connection = usbManager.openDevice(usbSerialPort.getDriver().getDevice());
        if (connection == null) {
            return;
        }

        try {
            usbSerialPort.open(connection);
            usbSerialPort.setParameters(BAUD_RATE, UsbSerialPort.DATABITS_8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
        } catch (IOException e) {
            Log.e(TAG, "Error setting up device: " + e.getMessage(), e);
            try {
                usbSerialPort.close();
            } catch (IOException e2) {
                Log.e(TAG, "Close serial port", e2);
            }
            usbSerialPort = null;
            return;
        }
        onDeviceStateChange();
    }
}
 
开发者ID:handsomecode,项目名称:smart-foosball,代码行数:39,代码来源:ScoreboardActivity.java

示例14: open

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
@Override
public void open() throws IOException {
    // Get the UsbSerialDriver instance for this USB device.
    List<UsbSerialDriver> drivers = UsbSerialProber.probeSingleDevice(manager, device);
    if (drivers.size() < 1) throw new IOException("Could not create UsbSerialDriver for device.");
    driver = drivers.get(0);
    // Open the connection using 9600 baud.
    driver.setParameters(9600, 8, 1, 0);
    driver.open();
    // Initialize the reader and writer for reading and writing over USB.
    input = new BufferedReader(new InputStreamReader(new UsbSerialInputStream(driver)));
    output = new BufferedWriter(new OutputStreamWriter(new UsbSerialOutputStream(driver)));
}
 
开发者ID:tdicola,项目名称:SmartCocktailShaker,代码行数:14,代码来源:UsbSerialProvider.java

示例15: findDevice

import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入依赖的package包/类
/**
 * Finds the Arduino USB device and asks the user for permission to use it.
 */
private boolean findDevice() {
    UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
    
    // Find the Arduino device.
    for (UsbSerialDriver driver : availableDrivers) {
        UsbDevice device = driver.getDevice();
        int vendorId = device.getVendorId();
        int productId = device.getProductId();
        if ((vendorId == RCCarReceiverService.ARDUINO_USB_VENDOR_ID && 
                productId == RCCarReceiverService.ARDUINO_UNO_USB_PRODUCT_ID) ||
            (vendorId == RCCarReceiverService.ARDUINO_CLONE_VENDOR_ID && 
                productId == RCCarReceiverService.ARDUINO_CLONE_PRODUCT_ID)) {
            Log.d(TAG, "Found Arduino device!");
            
            mUsbSerialDriver = driver;
            
            // Request user's permission to access the device.
            // Processing continues in mBroadcastReceiver after user grants permission.
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(RCCarReceiverService.ACTION_REQUEST_USB_PERMISSION), 0);
            usbManager.requestPermission(device, pendingIntent);
            return true;
        }
    }
    
    Log.e(TAG, "No Arduino devices found");
    Toast.makeText(this, "No Arduino devices found", Toast.LENGTH_LONG).show();
    return false;

}
 
开发者ID:zvikabh,项目名称:RCCarController,代码行数:34,代码来源:DirectControlActivity.java


注:本文中的com.hoho.android.usbserial.driver.UsbSerialDriver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。