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


Java UsbSerialPort类代码示例

本文整理汇总了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;
}
 
开发者ID:OpilkiInside,项目名称:bimdroid,代码行数:19,代码来源:BmwIBusService.java

示例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);
    }
}
 
开发者ID:OpilkiInside,项目名称:bimdroid,代码行数:20,代码来源:BmwIBusService.java

示例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);
    }
}
 
开发者ID:OpilkiInside,项目名称:bimdroid,代码行数:26,代码来源:BmwIBusService.java

示例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();
}
 
开发者ID:kost,项目名称:DroidMeter,代码行数:24,代码来源:SerialConsoleActivity.java

示例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;
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:21,代码来源:SmartMeterMessageService.java

示例6: onUsbSerialPortChanged

import com.hoho.android.usbserial.driver.UsbSerialPort; //导入依赖的package包/类
public void onUsbSerialPortChanged(UsbSerialPort port) {
    stopIoManager();
    if (openConnection(port)) {
        mOpenedPort = port;
        startIoManager(port);
    }
}
 
开发者ID:OpilkiInside,项目名称:bimdroid,代码行数:8,代码来源:BmwIBusService.java

示例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);
}
 
开发者ID:msillano,项目名称:USBphpTunnel,代码行数:10,代码来源:SerialConsoleActivity.java

示例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};
}
 
开发者ID:ekumenlabs,项目名称:tangobot,代码行数:38,代码来源:AbstractBaseNodeLoader.java

示例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);
}
 
开发者ID:kost,项目名称:DroidMeter,代码行数:13,代码来源:SerialConsoleActivity.java

示例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();
        }
    }
}
 
开发者ID:freshollie,项目名称:monkeyboard-radio-android,代码行数:36,代码来源:DeviceConnection.java

示例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);
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:33,代码来源:SmartMeterMessageService.java

示例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();
        }
    }
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:32,代码来源:SmartMeterMessageService.java

示例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);
}
 
开发者ID:dgcrouse,项目名称:Loggerino,代码行数:14,代码来源:LogKeeper.java

示例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();
    }
}
 
开发者ID:handsomecode,项目名称:smart-foosball,代码行数:39,代码来源:ScoreboardActivity.java

示例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();
}
 
开发者ID:fr3ts0n,项目名称:AndrOBD,代码行数:8,代码来源:UsbCommService.java


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