本文整理汇总了Java中com.hoho.android.usbserial.driver.UsbSerialPort类的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialPort类的具体用法?Java UsbSerialPort怎么用?Java UsbSerialPort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsbSerialPort类属于com.hoho.android.usbserial.driver包,在下文中一共展示了UsbSerialPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findUsbSerialPort
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的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;
}
示例2: startIoManager
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
private void startIoManager(UsbSerialPort port) {
if (port != null) {
if (DEBUG) Log.i(TAG, "Starting io manager...");
mDecoder.reset();
mSerialIoManager = new SerialInputOutputManager(port, mListener);
mExecutor.submit(mSerialIoManager);
new Handler(Looper.myLooper()).postDelayed(new Runnable() {
@Override
public void run() {
int randomMessageIndex = new Random(SystemClock.elapsedRealtimeNanos())
.nextInt(WELCOME_MESSAGES.length);
Log.d(TAG, "Sending a welcome message, index: " + randomMessageIndex);
BmwIBusService.this.sendTextMessageToObc(
WELCOME_MESSAGES[randomMessageIndex]);
}
}, 3000);
}
}
示例3: onCreate
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (DEBUG) Log.d(TAG, "onCreate");
mUsbManager = (UsbManager) getBaseContext().getSystemService(Context.USB_SERVICE);
mAudioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
mPowerManager = (PowerManager) getBaseContext().getSystemService(Context.POWER_SERVICE);
mInputManager = (InputManager) getBaseContext().getSystemService(Context.INPUT_SERVICE);
ConfigStorage.SerialPortIdentifier portIdentifier =
ConfigStorage.readDefaultPort(getBaseContext());
if (DEBUG) Log.d(TAG, "onCreate, portIdentifier: " + portIdentifier);
if (portIdentifier != null) {
UsbSerialPort port = findUsbSerialPort(portIdentifier);
if (port == null) {
Log.w(TAG, "Unable to find usb serial port, make sure device is connected: "
+ portIdentifier);
return;
}
onUsbSerialPortChanged(port);
}
}
示例4: communicate
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
private void communicate () {
UsbDeviceConnection connection = usbManager.openDevice(device);
try {
sPort.open(connection);
sPort.setParameters(2400, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
sPort.setRTS(false);
sPort.setDTR(true);
} catch (IOException e) {
Log.e(TAG, "Error setting up device: " + e.getMessage(), e);
mTitleTextView.setText("Error opening device: " + e.getMessage());
try {
sPort.close();
} catch (IOException e2) {
// Ignore.
}
sPort = null;
return;
}
mTitleTextView.setText("Serial device: " + sPort.getClass().getSimpleName());
onDeviceStateChange();
}
示例5: getServiceIdForSerialPort
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
/**
* serialPortからServiceIDを取得する.
* @param serialPort SerialPort.
* @return serviceId または null(該当無し).
*/
public String getServiceIdForSerialPort(final UsbSerialPort serialPort) {
// パラメータ、USB serial device list 数を確認.
if (serialPort == null || mUsbSerialDevices.size() == 0) {
return null;
}
// serialPort によるdevice検索.
for (UsbSerialDevice device : mUsbSerialDevices) {
if (serialPort.equals(device.getSerialPort())) {
return device.getServiceId();
}
}
// 該当無し.
return null;
}
示例6: onUsbSerialPortChanged
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
public void onUsbSerialPortChanged(UsbSerialPort port) {
stopIoManager();
if (openConnection(port)) {
mOpenedPort = port;
startIoManager(port);
}
}
示例7: show
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
/**
* Starts the activity, using the supplied driver instance.
*/
static void show(Context context, UsbSerialPort port) {
sPort = port;
final Intent intent = new Intent(context, SerialConsoleActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
}
示例8: startNodes
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的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};
}
示例9: show
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
/**
* Starts the activity, using the supplied driver instance.
*
* @param context
* @param driver
*/
static void show(Context context, UsbSerialPort port) {
sPort = port;
final Intent intent = new Intent(context, SerialConsoleActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
}
示例10: openConnection
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的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();
}
}
}
示例11: disconnectSmartMeter
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
/**
* スマートメーター通信切断.
* @param response response.
* @param device 切断USBシリアルデバイス.
*/
public void disconnectSmartMeter(final Intent response, final UsbSerialDevice device) {
/* ID、パスワードチェック */
if (mPrefUtil.getBRouteId() == null || mPrefUtil.getBRoutePass() == null) {
if (response != null) {
MessageUtils.setIllegalDeviceStateError(response, "Not found b-route ID or Password.");
sendResponse(response);
}
return;
}
UsbSerialPort serialPort = device.getSerialPort();
if (mSerialPort == null) {
mSerialPort = device.getSerialPort();
} else if (!(mSerialPort.equals(serialPort))) {
try {
mSerialPort.close();
} catch (IOException e) {
e.printStackTrace();
}
mSerialPort = device.getSerialPort();
}
// 切断コマンド送信.
mPairingResponse = response;
mPairngServiceId = device.getServiceId();
ExecuteProcess(BP35C2.Command.TERMINATE, null);
}
示例12: closeDevice
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
/**
* USBシリアルデバイスクローズ.
*/
private void closeDevice() {
Iterator<UsbSerialDevice> index = mUsbSerialDevices.iterator();
while (index.hasNext()) {
UsbSerialDevice device = index.next();
final UsbManager mUsbManager = (UsbManager) this.getSystemService(Context.USB_SERVICE);
UsbDeviceConnection connection = mUsbManager.openDevice(device.getSerialPort().getDriver().getDevice());
if (connection == null) {
SerialInputOutputManager manager = device.getSerialInputOutputManager();
if (manager != null) {
manager.stop();
}
device.setSerialInputOutputManager(null);
UsbSerialPort serialPort = device.getSerialPort();
if (serialPort != null) {
try {
serialPort.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
device.setSerialPort(null);
setOnlineStatus(device.getServiceId(), false, false);
index.remove();
}
}
}
示例13: IOProcessor
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
public IOProcessor(UsbDevice device) throws IOException{
mSendBuffer = new ArrayDeque<>();
// Tweaked rom serial library example
UsbDeviceConnection connection = mManager.openDevice(device);
mSerialPort = mDriver.getPorts().get(0);
mSerialPort.open(connection);
mSerialPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE); // Arduino default settings
mListener = new InputListener();
mSerialIoManager = new SerialInputOutputManager(mSerialPort, mListener);
mExecutor.submit(mSerialIoManager);
}
示例14: onResume
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的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();
}
}
示例15: connect
import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
@Override
public void connect(Object device, boolean secure)
{
setState(STATE.CONNECTING);
setDevice((UsbSerialPort)device);
start();
}