本文整理汇总了Java中com.felhr.usbserial.UsbSerialDevice类的典型用法代码示例。如果您正苦于以下问题:Java UsbSerialDevice类的具体用法?Java UsbSerialDevice怎么用?Java UsbSerialDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsbSerialDevice类属于com.felhr.usbserial包,在下文中一共展示了UsbSerialDevice类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UsbInputStream
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
public UsbInputStream(UsbSerialDevice device) {
this.device=device;
}
开发者ID:BITPlan,项目名称:can4eve,代码行数:4,代码来源:UsbInputStream.java
示例5: 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
示例6: getUsbSerialDevice
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
@Nullable
public UsbSerialDevice getUsbSerialDevice() {
if (usbSerialDevice != null) {
return usbSerialDevice;
}
return null;
}
开发者ID:dh-28,项目名称:ModbusRtuConnect,代码行数:8,代码来源:ModbusRtuConnection.java
示例7: 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
示例8: usbSend
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
public static String usbSend(String data, boolean showToast) {
final String mode = "usb";
if (openedUsbPorts != null && openedUsbPorts.size() > 0) {
if (App.isDebug()) {
Log.d(TAG, "Data to send [ " + mode + " ]: " + data);
}
if (App.getPrefs().getBoolean("crlf", true)) {
data += "\r\n";
}
for (Map.Entry<String, UsbSerialDevice> entry : openedUsbPorts.entrySet()) {
UsbSerialDevice serialPort = entry.getValue();
serialPort.write(data.getBytes());
}
return mode;
} else {
if (App.isDebug()) {
Log.w(TAG, "Can't send data [" + data + "] via " + mode + ". No connected devices");
}
if (showToast) {
Toaster.toast(R.string.toast_serial_send_warning);
}
}
return null;
}
开发者ID:delletenebre,项目名称:SerialManager,代码行数:32,代码来源:ConnectionService.java
示例9: closeUsbConnections
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
public static void closeUsbConnections() {
if (openedUsbPorts != null) {
for (Map.Entry<String, UsbSerialDevice> entry : openedUsbPorts.entrySet()) {
UsbSerialDevice serialPort = entry.getValue();
try {
serialPort.close();
entry.setValue(null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
openedUsbPorts = null;
}
}
开发者ID:delletenebre,项目名称:SerialManager,代码行数:16,代码来源:ConnectionService.java
示例10: UsbOutputStream
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
public UsbOutputStream(UsbSerialDevice device) {
this.device=device;
}
开发者ID:BITPlan,项目名称:can4eve,代码行数:4,代码来源:UsbOutputStream.java
示例11: getSerialPort
import com.felhr.usbserial.UsbSerialDevice; //导入依赖的package包/类
public UsbSerialDevice getSerialPort(){
return _serialPort;
}
开发者ID:GIGATeam,项目名称:UsbExtension,代码行数:4,代码来源:UsbContext.java
示例12: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论