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


Java UsbSerialDevice.createUsbSerialDevice方法代码示例

本文整理汇总了Java中com.felhr.usbserial.UsbSerialDevice.createUsbSerialDevice方法的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialDevice.createUsbSerialDevice方法的具体用法?Java UsbSerialDevice.createUsbSerialDevice怎么用?Java UsbSerialDevice.createUsbSerialDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.felhr.usbserial.UsbSerialDevice的用法示例。


在下文中一共展示了UsbSerialDevice.createUsbSerialDevice方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openUsbSerialDevice

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
private void openUsbSerialDevice(SerialParameters serialParameters) {
    usbSerialDevice = UsbSerialDevice.createUsbSerialDevice(usbDevice, usbDeviceConnection);
    if (usbSerialDevice != null) {
        if (usbSerialDevice.open()) { //Set Serial Connection Parameters.
            if (serialParameters == null) {
                serialParameters = SerialParameters.getDefault();
            }
            usbSerialDevice.setBaudRate(serialParameters.baudRate);
            usbSerialDevice.setDataBits(serialParameters.databits);
            usbSerialDevice.setStopBits(serialParameters.stopbits);
            usbSerialDevice.setParity(serialParameters.parity);
            usbSerialDevice.setFlowControl(serialParameters.flowControl);
            if (listener != null) {
                listener.onConnected();
            }
        } else {
            if (App.IS_DEBUG) System.out.println("USB - SERIAL DEVICE NOT OPEN");
        }
    } else {
        if (App.IS_DEBUG) System.out.println("USB - SERIAL DEVICE IS NULL");
    }
}
 
开发者ID:dh-28,项目名称:ModbusRtuConnect,代码行数:23,代码来源:ModbusRtuConnection.java

示例2: run

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
@Override
public void run() {
    serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
    if (serialPort != null) {
        if (serialPort.open()) {
            serialPortConnected = true;
            serialPort.setBaudRate(BAUD_RATE);
            serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
            serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
            serialPort.setParity(UsbSerialInterface.PARITY_NONE);
            serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
            serialPort.read(readCallback);
            return;
        }
        Log.e(TAG, "USB not working");
    }
}
 
开发者ID:rjaros87,项目名称:pm-home-station,代码行数:18,代码来源:Sensor.java

示例3: connectSerial

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
public Boolean connectSerial(UsbDevice device, Integer baud) {
    UsbDeviceConnection connection = connectDevice(device);
    UsbSerialDevice serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
    _workingDevice = device;
    if(!serialPort.open()){
        return false;
    }else {
        _serialPort = serialPort;
        serialPort.setBaudRate(baud);
        serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
        serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
        serialPort.setParity(UsbSerialInterface.PARITY_NONE);
        serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
        serialPort.read(mCallback);
        return true;
    }
}
 
开发者ID:GIGATeam,项目名称:UsbExtension,代码行数:18,代码来源:UsbContext.java

示例4: startSerialConnection

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
private void startSerialConnection(UsbManager usbManager, UsbDevice device) {
    UsbDeviceConnection connection = usbManager.openDevice(device);
    serial = UsbSerialDevice.createUsbSerialDevice(device, connection);

    if (serial != null && serial.open()) {
        serial.setBaudRate(115200);
        serial.setDataBits(UsbSerialInterface.DATA_BITS_8);
        serial.setStopBits(UsbSerialInterface.STOP_BITS_1);
        serial.setParity(UsbSerialInterface.PARITY_NONE);
        serial.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
        serial.setDTR(false);
    }
}
 
开发者ID:carlemil,项目名称:RPLidarA2AndroidThingsAPI,代码行数:14,代码来源:RPLidarA2Api.java

示例5: run

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
@Override
public void run() {
    serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
    if (serialPort != null) {
        if (serialPort.open()) {
            serialPortConnected = true;
            serialPort.setBaudRate(BAUD_RATE);
            serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
            serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
            serialPort.setParity(UsbSerialInterface.PARITY_NONE);
            /**
             * Current flow control Options:
             * UsbSerialInterface.FLOW_CONTROL_OFF
             * UsbSerialInterface.FLOW_CONTROL_RTS_CTS only for CP2102 and FT232
             * UsbSerialInterface.FLOW_CONTROL_DSR_DTR only for CP2102 and FT232
             */
            serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
            serialPort.read(mCallback);
            serialPort.getCTS(ctsCallback);
            serialPort.getDSR(dsrCallback);
            // Everything went as expected
            EventBus.getDefault().post(new UsbSerialActionEvent(ACTION_USB_READY));
        } else {
            // Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit
            if (serialPort instanceof CDCSerialDevice) {
                EventBus.getDefault().post(new UsbSerialActionEvent(ACTION_CDC_DRIVER_NOT_WORKING));
            } else {
                EventBus.getDefault().post(new UsbSerialActionEvent(ACTION_USB_DEVICE_NOT_WORKING));
            }
        }
    } else {
        // No driver for given device, even generic CDC driver could not be loaded
        EventBus.getDefault().post(new UsbSerialActionEvent(ACTION_USB_NOT_SUPPORTED));
    }
}
 
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:36,代码来源:UsbService.java

示例6: connectToUsbDevice

import com.felhr.usbserial.UsbSerialDevice; //导入方法依赖的package包/类
private void connectToUsbDevice(UsbDevice device) {
    UsbSerialDevice serialPort = UsbSerialDevice.createUsbSerialDevice(device,
            usbManager.openDevice(device));
    if (serialPort != null) {
        if (serialPort.open()) {
            int baudRate = Integer.parseInt(App.getPrefs().getString("baudRate", "9600"));
            int dataBits = Integer.parseInt(App.getPrefs().getString("dataBits", "8"));
            int stopBits = Integer.parseInt(App.getPrefs().getString("stopBits", "1"));
            int parity = Integer.parseInt(App.getPrefs().getString("parity", "0"));
            boolean dtr = App.getPrefs().getBoolean("dtr", false);
            boolean rts = App.getPrefs().getBoolean("rts", false);

            serialPort.setBaudRate(baudRate);
            serialPort.setDataBits(dataBits);
            serialPort.setStopBits(stopBits);
            serialPort.setParity(parity);
            /**
             * Current flow control Options:
             * UsbSerialInterface.FLOW_CONTROL_OFF
             * UsbSerialInterface.FLOW_CONTROL_RTS_CTS only for CP2102 and FT232
             * UsbSerialInterface.FLOW_CONTROL_DSR_DTR only for CP2102 and FT232
             */
            serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
            serialPort.setDTR(dtr);
            serialPort.setRTS(rts);

            serialPort.read(usbReceiveCallback);

            openedUsbPorts.put(device.getDeviceName(), serialPort);
            updateNotificationText();

            sendInfoScreenState(null);

            if (App.isDebug()) {
                Toaster.toast("USB device [" + device.getDeviceName() + "] connected");
                Log.d(TAG, "USB device [" + device.getDeviceName() + "] connected");
            }
        } else {
            // Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit
            if (serialPort instanceof CDCSerialDevice) {
                if (App.isDebug()) {
                    Log.d(TAG, "CDC driver not working");
                }
                Toaster.toast("CDC driver not working");
            } else {
                if (App.isDebug()) {
                    Log.d(TAG, "USB device not working");
                }
                Toaster.toast("USB device not working");
            }
        }
    } else {
        if (App.isDebug()) {
            Log.d(TAG, "USB device not supported");
        }

        if (App.getPrefs().getBoolean("usb_reset_hub", false)) {
            if (!usbRestartState) {
                resetUsbHubs();
            }
        } else {
            Toaster.toast("USB device not supported");
        }
    }
}
 
开发者ID:delletenebre,项目名称:SerialManager,代码行数:66,代码来源:ConnectionService.java


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