public class SerialComm extends EMDKBase
{@code public class MainActivity extends Activity implements EMDKListener { SerialComm serialComm; EMDKManager emdkManager;
Modifier and Type | Class and Description |
---|---|
static class |
SerialComm.ControlSignal
List of control signals
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PORT_NAME |
Modifier and Type | Method and Description |
---|---|
void |
disable()
This method disables USB/serial channel to communicate with the remote device.
|
void |
enable()
This method enables the channel for the application to communicate with the remote device via USB/Serial.
|
SerialCommConfig |
getConfig()
Gets the current configuration settings of serial comm channel.
|
SerialPortInfo |
getPortInfo()
Returns the serial port info used for communication.
|
boolean |
getSignalState(SerialComm.ControlSignal signal)
This method can be used to query the signal status of DTR, DCD, DSR, RI, RTS, CTS.
|
boolean |
isEnabled()
Gets whether the communication port is enabled or not.
|
byte[] |
read(int readTimeOut)
This method reads the available data and returns immediately.
|
void |
setConfig(SerialCommConfig config)
Sets the serial comm settings for the currently choosen port.
|
void |
setSignalState(SerialComm.ControlSignal controlSignal,
boolean signalStatus)
This method allows the application to set the status of control signal.
|
int |
write(byte[] data,
int bytesToWrite)
Writes a specified number of bytes from buffer to the opened communication channel.
|
public static final java.lang.String DEFAULT_PORT_NAME
public boolean isEnabled()
public void enable() throws SerialCommException
SerialCommException
public void disable() throws SerialCommException
SerialCommException
public int write(byte[] data, int bytesToWrite) throws SerialCommException
data
- The byte array that contains the data to write.bytesToWrite
- The number of bytes to write.SerialCommException
public byte[] read(int readTimeOut) throws SerialCommException
readTimeOut
- Wait for data until timeout. The timeout unit is milli seconds.
A timeout of zero means the calling read will wait forever unless interrupted by disable or release.SerialCommException
public SerialCommConfig getConfig() throws SerialCommException
SerialCommException
- Supported in EMDK v6.1.0 or higher.Not supported on all BSP eventhough the EMDK provides this interface. Refer to release notes for more details.
Example Usage: SerialCommConfig config = serialComm.getConfig();
public void setConfig(SerialCommConfig config) throws SerialCommException
config
- object which specifies the settings for the current instance of serial communicationSerialCommException
- Supported in EMDK v6.1.0 or higher.Not supported on all BSP eventhough the EMDK provides this interface. Refer to release notes for more details.
Example Usage: SerialCommConfig config = serialComm.getConfig(); config.baudRate = BaudRates.BR_19200; config.parity = ParityBits.EVEN; serialComm.setConfig(config);
public boolean getSignalState(SerialComm.ControlSignal signal) throws SerialCommException
signal
- SerialCommException
- Supported in EMDK v6.1.0 or higher.Not supported on all BSP eventhough the EMDK provides this interface. Refer to release notes for more details.
Example Usage: boolean signalStatus = serialComm.getSignalState(ControlSignal.RTS)
public void setSignalState(SerialComm.ControlSignal controlSignal, boolean signalStatus) throws SerialCommException
controlSignal
- Control Signal TypesignalStatus
- Status of the control signalSerialCommException
- Supported in EMDK v6.1.0 or higher.Not supported on all BSP eventhough the EMDK provides this interface. Refer to release notes for more details.
Example Usage: boolean signalStatus = serialComm.setSignalState(ControlSignal.RTS, false)
public SerialPortInfo getPortInfo()
Supported in EMDK v6.1.0 or higher.Not supported on all BSP eventhough the EMDK provides this interface. Refer to release notes for more details.