public class SerialPort
extends java.lang.Object
SerialPort.setDevicePower(true); // Power on the port
File port = new File(SerialPort.getSerialPath);
SerialPort serialPort = new SerialPort(port, 9600, 0);
mOutputStream = mSerialPort.getOutputStream();
mInputStream = mSerialPort.getInputStream();
// Start reading and writing data
Constructor and Description |
---|
SerialPort(java.io.File device,
int baudrate,
int flags)
Open the serial connection
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the open connection
|
java.io.InputStream |
getInputStream()
Get the InputStream to read from the device
|
java.io.OutputStream |
getOutputStream()
Get the OutputStream to write to the device
|
static java.lang.String |
getSerialPath()
Detect the correct device path for the current hardware
|
static void |
setDevicePower(android.content.Context context,
boolean enabled)
Turn of power pins and enable the serial for Nautiz X2 and Nautiz X6
|
public SerialPort(java.io.File device, int baudrate, int flags) throws java.lang.SecurityException, java.io.IOException
device
- The device path to connect to.getSerialPath()
to get the correct path for the current hardwarebaudrate
- The baud rate to use for the connectionflags
- Additional flags for the native C open calljava.lang.SecurityException
- If you don't have permission to access the devicejava.io.IOException
- If the device doesn't exist or something goes wrong during the connection setuppublic java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public void close()
public static void setDevicePower(android.content.Context context, boolean enabled)
context
- The app contextenabled
- True to turn power on, false to power offpublic static java.lang.String getSerialPath()
open(String, int, int)