本文整理汇总了Java中com.google.android.things.pio.UartDevice类的典型用法代码示例。如果您正苦于以下问题:Java UartDevice类的具体用法?Java UartDevice怎么用?Java UartDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UartDevice类属于com.google.android.things.pio包,在下文中一共展示了UartDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: startup
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public void startup() {
PeripheralManagerService mPeripheralManagerService = new PeripheralManagerService();
try {
mDevice = mPeripheralManagerService.openUartDevice(arduino.getUartDeviceName());
mDevice.setDataSize(arduino.getDataBits());
mDevice.setParity(UartDevice.PARITY_NONE);
mDevice.setStopBits(arduino.getStopBits());
mDevice.setBaudrate(arduino.getBaudRate());
} catch (IOException e){
try {
close();
} catch (Exception e1) {
e1.printStackTrace();
}
throw new IllegalStateException("Sensor can't start", e);
}
}
开发者ID:mplacona,项目名称:arduwrap,代码行数:20,代码来源:Dht22Driver.java
示例2: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Invoked by mUartDeviceCallback when new data arrives in the UART buffer.
*/
private synchronized boolean onUartDeviceDataAvailable(UartDevice uart) {
try {
final int count = uart.read(mInboundRawBuffer, mInboundRawBuffer.length);
if (count > 0) {
processBuffer(mInboundRawBuffer, count);
}
} catch (IOException e) {
Log.w(TAG, "Unable to read UART data", e);
onUnexpectedClose();
}
return true;
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:19,代码来源:UartLowpanModule.java
示例3: openUart
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Access and configure the requested UART device for 8N1.
*
* @param name Name of the UART peripheral device to open.
* @param baudRate Data transfer rate. Should be a standard UART baud,
* such as 9600, 19200, 38400, 57600, 115200, etc.
* @throws IOException if an error occurs opening the UART port.
*/
private void openUart(String name, int baudRate) throws IOException {
mUartDevice = peripheralManagerService.openUartDevice(name);
/** Configure the UART*/
mUartDevice.setBaudrate(baudRate);
mUartDevice.setDataSize(DATA_BITS);
mUartDevice.setParity(UartDevice.PARITY_NONE);
mUartDevice.setStopBits(STOP_BITS);
mUartDevice.registerUartDeviceCallback(getUartCallback);
}
开发者ID:IoT-Ignite,项目名称:IgniteGreenhouseGateway,代码行数:19,代码来源:UartManager.java
示例4: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Read available data from the UART device
try {
readUartBuffer(uart);
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
// Continue listening for more interrupts
return true;
}
开发者ID:jpuderer,项目名称:Taxi-Datalogger,代码行数:13,代码来源:HpmSensor.java
示例5: HpmSensor
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
public HpmSensor(String uartName, Handler handler) throws IOException {
mHandler = handler;
// Open and setup UARTdevice
PeripheralManagerService manager = new PeripheralManagerService();
mDevice = manager.openUartDevice(uartName);
mDevice.setBaudrate(9600);
mDevice.setDataSize(8);
mDevice.setParity(UartDevice.PARITY_NONE);
mDevice.setStopBits(1);
}
开发者ID:jpuderer,项目名称:Taxi-Datalogger,代码行数:12,代码来源:HpmSensor.java
示例6: readUartBuffer
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
private void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
byte[] buffer = new byte[LENGTH_DATA_FRAME * 2];
int count;
while ((count = uart.read(buffer, buffer.length)) > 0) {
processBuffer(buffer, count);
}
}
开发者ID:jpuderer,项目名称:Taxi-Datalogger,代码行数:9,代码来源:HpmSensor.java
示例7: init
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
private void init(String uartName) throws IOException {
try {
PeripheralManagerService manager = new PeripheralManagerService();
mDevice = manager.openUartDevice(uartName);
mDevice.setBaudrate(Sim900Constants.BAUD_RATE);
mDevice.setDataSize(Sim900Constants.DATA_BITS);
mDevice.setParity(UartDevice.PARITY_NONE);
mDevice.setStopBits(Sim900Constants.STOP_BITS);
} catch (IOException | RuntimeException e) {
close();
throw e;
}
}
开发者ID:MacSimmy,项目名称:Sim900AndroidThings,代码行数:15,代码来源:Sim900.java
示例8: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
try {
byte[] buffer = new byte[1];
int count = uart.read(buffer, 1);
System.out.println("--- " + String.valueOf(count) +" ------> " + String.valueOf(buffer[0]));
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
return true;
}
开发者ID:bregydoc,项目名称:MarsWeatherSimulator,代码行数:14,代码来源:SerialControl.java
示例9: configureUartFrame
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
public void configureUartFrame(UartDevice uart) throws IOException {
// Configure the UART port
uart.setBaudrate(115200);
uart.setDataSize(8);
uart.setParity(UartDevice.PARITY_NONE);
uart.setStopBits(1);
}
开发者ID:bregydoc,项目名称:MarsWeatherSimulator,代码行数:8,代码来源:SerialControl.java
示例10: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Queue up a data transfer
transferUartData();
//Continue listening for more interrupts
return true;
}
开发者ID:androidthings,项目名称:sample-uartloopback,代码行数:8,代码来源:LoopbackActivity.java
示例11: openUart
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Access and configure the requested UART device for 8N1.
*
* @param name Name of the UART peripheral device to open.
* @param baudRate Data transfer rate. Should be a standard UART baud,
* such as 9600, 19200, 38400, 57600, 115200, etc.
*
* @throws IOException if an error occurs opening the UART port.
*/
private void openUart(String name, int baudRate) throws IOException {
mLoopbackDevice = mService.openUartDevice(name);
// Configure the UART
mLoopbackDevice.setBaudrate(baudRate);
mLoopbackDevice.setDataSize(DATA_BITS);
mLoopbackDevice.setParity(UartDevice.PARITY_NONE);
mLoopbackDevice.setStopBits(STOP_BITS);
mLoopbackDevice.registerUartDeviceCallback(mCallback, mInputHandler);
}
开发者ID:androidthings,项目名称:sample-uartloopback,代码行数:20,代码来源:LoopbackActivity.java
示例12: connectUart
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Sets up UART port for sensor communication
* @param port UART port on which the sensor is connected
* @throws IOException
*/
private void connectUart(String port) throws IOException {
mDevice = pioService.openUartDevice(port);
mDevice.setBaudrate(115200);
mDevice.setDataSize(8);
mDevice.setParity(UartDevice.PARITY_NONE);
mDevice.setStopBits(1);
mDevice.registerUartDeviceCallback(onUart);
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:15,代码来源:ZXGestureSensorUart.java
示例13: NmeaGpsModule
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Create a new NmeaGpsModule.
*
* @param uartName UART port name where the module is attached. Cannot be null.
* @param baudRate Baud rate used for the module UART.
* @param handler optional {@link Handler} for software polling and callback events.
*/
public NmeaGpsModule(String uartName, int baudRate, Handler handler) throws IOException {
try {
PeripheralManagerService manager = new PeripheralManagerService();
UartDevice device = manager.openUartDevice(uartName);
init(device, baudRate, handler);
} catch (IOException | RuntimeException e) {
close();
throw e;
}
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:18,代码来源:NmeaGpsModule.java
示例14: init
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* Initialize peripheral defaults from the constructor.
*/
private void init(UartDevice device, int baudRate, Handler handler) throws IOException {
mDevice = device;
mDevice.setBaudrate(baudRate);
mDevice.registerUartDeviceCallback(mCallback, handler);
mParser = new NmeaParser();
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:11,代码来源:NmeaGpsModule.java
示例15: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
try {
readUartBuffer();
} catch (IOException e) {
Log.w(TAG, "Unable to read UART data", e);
}
return true;
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:11,代码来源:NmeaGpsModule.java
示例16: onUartDeviceDataAvailable
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
readUartData();
return true;
}
开发者ID:IoT-Ignite,项目名称:IgniteGreenhouseGateway,代码行数:6,代码来源:UartManager.java
示例17: onUartDeviceError
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.e(TAG, uart + ": Error event " + error);
}
开发者ID:IoT-Ignite,项目名称:IgniteGreenhouseGateway,代码行数:5,代码来源:UartManager.java
示例18: onUartDeviceError
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
开发者ID:jpuderer,项目名称:Taxi-Datalogger,代码行数:5,代码来源:HpmSensor.java
示例19: readUartBuffer
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
/**
* parse data from UART connection
*
* @param uart UART device object to be read
* @throws IOException
*/
private void readUartBuffer(UartDevice uart) throws IOException {
final int maxCount = 256;
byte[] buffer = new byte[maxCount];
int count;
SensorResult result = null;
while ((count = uart.read(buffer, buffer.length)) > 0) {
for (int i = 0; i < count; i++) {
try {
result = mParser.parse(buffer[i]);
} catch (InvalidByteException e) {
Log.e(TAG, "Invalid byte sequence encountered " +
"while reading from sensor connected to UART", e);
}
if (result != null) {
switch (result.resultType) {
case PEN_UP:
mGestureDetector.penUp();
break;
case X_POS:
mGestureDetector.setXpos(result.xPosition);
break;
case Z_POS:
mGestureDetector.setZpos(result.zPosition);
break;
case GESTURE:
mGestureDetector.setGesture(result.gesture,
result.gestureParams);
break;
case RANGE:
mGestureDetector.setRanges(result.rangeL, result.rangeR);
break;
case ID:
break;
}
result = null;
}
}
}
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:47,代码来源:ZXGestureSensorUart.java
示例20: onUartDeviceError
import com.google.android.things.pio.UartDevice; //导入依赖的package包/类
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, "Error receiving incoming data: " + error);
}
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:5,代码来源:NmeaGpsModule.java
注:本文中的com.google.android.things.pio.UartDevice类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论