本文整理汇总了Java中com.hoho.android.usbserial.driver.UsbSerialDriver.getDevice方法的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialDriver.getDevice方法的具体用法?Java UsbSerialDriver.getDevice怎么用?Java UsbSerialDriver.getDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hoho.android.usbserial.driver.UsbSerialDriver
的用法示例。
在下文中一共展示了UsbSerialDriver.getDevice方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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 == ARDUINO_USB_VENDOR_ID && productId == ARDUINO_UNO_USB_PRODUCT_ID) ||
(vendorId == ARDUINO_CLONE_VENDOR_ID && productId == ARDUINO_CLONE_PRODUCT_ID)) {
Log.d(TAG, "Found Arduino device!");
mUsbSerialDriver = driver;
getUsbPermission(new Intent(ACTION_REQUEST_USB_PERMISSION));
Log.d(TAG, "findDevice() returns true");
return true;
}
}
Log.e(TAG, "No Arduino devices found");
makeToast("No Arduino devices found");
stopSelf();
return false;
}
示例4: onCreate
import com.hoho.android.usbserial.driver.UsbSerialDriver; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (AndProxApplication.hasUsbHostSupport()) {
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
dumpUsbDeviceInfo(manager);
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (availableDrivers.isEmpty()) {
Log.d(TAG, "onCreate: no devices present");
return;
}
// Open a connection to the first available driver.
UsbSerialDriver driver = availableDrivers.get(0);
UsbDevice device = driver.getDevice();
manager.requestPermission(device, mPermissionIntent);
} else {
Log.e(TAG, "no USB host support!");
findViewById(R.id.btnConnect).setEnabled(false);
((TextView) findViewById(R.id.tvIntroText)).setText(R.string.no_usb_host);
if (savedInstanceState == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(R.string.no_usb_host)
.setTitle(R.string.no_usb_host_title);
builder.show();
}
}
// Request permission for storage right away, as requesting this when a file is explicitly
// opened is tedious.
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CALLBACK);
} else {
// We already have permissions
CopyTask t = new CopyTask();
t.execute();
}
}