本文整理汇总了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");
}
}
示例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");
}
}
示例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;
}
}
示例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);
}
}
示例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));
}
}
示例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");
}
}
}