本文整理汇总了Java中com.felhr.usbserial.UsbSerialInterface类的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialInterface类的具体用法?Java UsbSerialInterface怎么用?Java UsbSerialInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsbSerialInterface类属于com.felhr.usbserial包,在下文中一共展示了UsbSerialInterface类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.felhr.usbserial.UsbSerialInterface; //导入依赖的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");
}
}
示例2: connectSerial
import com.felhr.usbserial.UsbSerialInterface; //导入依赖的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;
}
}
示例3: startSerialConnection
import com.felhr.usbserial.UsbSerialInterface; //导入依赖的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);
}
}
示例4: SerialParameters
import com.felhr.usbserial.UsbSerialInterface; //导入依赖的package包/类
private SerialParameters() {
this.baudRate = 9600;
this.flowControl = UsbSerialInterface.FLOW_CONTROL_OFF;
this.databits = UsbSerialInterface.DATA_BITS_8;
this.stopbits = UsbSerialInterface.STOP_BITS_1;
this.parity = UsbSerialInterface.PARITY_EVEN;
}
示例5: run
import com.felhr.usbserial.UsbSerialInterface; //导入依赖的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.UsbSerialInterface; //导入依赖的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");
}
}
}