|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.alarexgroup.m2mplf.adapters.serial.SerialAdapter
public final class SerialAdapter
Adapter provides the serial communication
Example:
import com.alarexgroup.m2mplf.adapters.serial.SerialAdapter;
import com.alarexgroup.m2mplf.adapters.serial.SerialAdapterListener;
public class MyM2Mapp extends M2Mlet implements SerialAdapterListener{
.
.
.
serialAdapter = SerialAdapter.getSerialAdapter(this,1);
serialAdapter.openPort("comm:com0;baudrate=4800",DATA_SEPARATOR_CR_LF);
serialAdapter.writeData("Hello, I'am Siemens module!\r\n");
public void onSerialDataReceived(byte[] receivedData, int adapterId) {
serialAdapter.writeData(receivedData);
}
or
serialAdapter = SerialAdapter.getSerialAdapter(this,1);
serialAdapter.openPort("comm:com0;baudrate=4800");
serialAdapter.writeData("Hello, I'am Siemens module!\r\n");
public void onSerialDataReceivedInStream(InputStream receivedData, int adapterId) {
int nums;
try {
nums = receivedData.available();
byte[] b = new byte[nums];
receivedData.read(b);
serialAdapter.writeData(b);
} catch (IOException ex) {
ex.printStackTrace();
}
}
| Parameters | Default: | Description |
|---|---|---|
baudrate |
Platform independent |
Data speed |
bitsperchar |
8 |
Character encoding (7 or 8 bits for character. |
stopbits |
1 |
Number of stop bits(1 or 2) |
parity |
none |
Parity: odd, even,
or none. |
blocking |
on |
If blocking is set to on, it waits for filling up the whole buffer of this device. |
autocts |
on |
If autocts is set to on, it waits for CTS signal before data writingm. |
autorts |
on |
If autorts is set to on, RTS signals incomming data.In case of off, RTS is still turned on. |
[SIEMENS WM ]
TC65 has following restrictions:
baudrate: 300, 600, 1200, 2400, 4800, 9600, 14400,
19200, 28800, 38400, 57600, 115200, 230400, 460800
stopbits: only 1 is supported
parity: 7N1 is not supported
| <comm_connection_string> | ::= "comm:"<port_id>[<options_list>] ; |
| <port_id> | ::= string of characters and numbers |
| <options_list> | ::= *(<baud_rate_string>| <bitsperchar>|
<stopbits>| <parity>|
<blocking>| <autocts>|
<autorts>) ;
; in case of duplicite parameters ; the last one will be used |
| <baud_rate_string> | ::= ";baudrate="<baud_rate> |
| <baud_rate> | ::= string of digits |
| <bitsperchar> | ::= ";bitsperchar="<bit_value> |
| <bit_value> | ::= "7" | "8" |
| <stopbits> | ::= ";stopbits="<stop_value> |
| <stop_value> | ::= "1" | "2" |
| <parity> | ::= ";parity="<parity_value> |
| <parity_value> | ::= "even" | "odd" | "none" |
| <blocking> | ::= ";blocking="<on_off> |
| <autocts> | ::= ";autocts="<on_off> |
| <autorts> | ::= ";autorts="<on_off> |
| <on_off> | ::= "on" | "off" |
| Field Summary | |
|---|---|
static byte[] |
DATA_SEPARATOR_CR
Data block closing sequence: CR - 13 |
static byte[] |
DATA_SEPARATOR_CR_LF
Data block closing sequence: CRLF - 13,10 = 0D,0A in HEX |
static byte[] |
DATA_SEPARATOR_ESCAPE
Data block closing sequence: ESC - 27 |
static byte[] |
DATA_SEPARATOR_ZERO_BYTE
Data block closing sequence: 0 |
static int |
longSleep
|
static int |
shortSleep
|
static int |
timeForSleep
|
| Constructor Summary | |
|---|---|
SerialAdapter()
|
|
| Method Summary | |
|---|---|
void |
close()
Terminates this adapter's work |
boolean |
closePort()
Method stops serail communication.You can reestablish the connection with openPort methods. |
java.io.InputStream |
getInputStream()
Method returns opened InputStream for data receiving from serial port. |
java.io.OutputStream |
getOutputStream()
Method returns opened OutputStream used for sending data to serial port. |
static SerialAdapter |
getSerialAdapter(SerialAdapterListener listener,
int adapterId)
Method creates adapter and returns referrence. |
boolean |
openPort(java.lang.String parameters)
Opens communications port with given parameters. |
boolean |
openPort(java.lang.String parameters,
byte[] dataSeparator)
Opens communications port with given parameters. |
boolean |
openPort(java.lang.String parameters,
byte[] dataSeparator,
long timeOut)
Opens communications port with given parameters. |
void |
setPriority(int priority)
Priority setting of SerialAdapter's internal thread |
boolean |
writeData(byte[] data)
Writes a byte array to serial port |
boolean |
writeData(byte[] data,
int offset,
int length)
Writes length of bytes from a byte array to serial port starting at offset |
boolean |
writeData(java.io.InputStream ist,
int length)
Method writes content of the inputstream to serial port. |
boolean |
writeData(int onebyte)
Writes a single byte to serial port |
boolean |
writeData(java.lang.String data)
Writes a string to serial port |
byte[] |
writeDataAndReadResponse(byte[] data)
Method writes data to serial port and returns response. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final byte[] DATA_SEPARATOR_CR_LF
public static final byte[] DATA_SEPARATOR_ZERO_BYTE
public static final byte[] DATA_SEPARATOR_CR
public static final byte[] DATA_SEPARATOR_ESCAPE
public static int shortSleep
public static int longSleep
public static int timeForSleep
| Constructor Detail |
|---|
public SerialAdapter()
| Method Detail |
|---|
public static SerialAdapter getSerialAdapter(SerialAdapterListener listener,
int adapterId)
adapterId - id of this adapteru. Lets you use multiple serial ports.listener -
SerialAdapter,
SerialAdapterListener
public boolean openPort(java.lang.String parameters,
byte[] dataSeparator)
SerialAdapterListener.onSerialDataReceived(byte[], int) is called by adapter if there was a received data with closing sequence. See DATA_SEPARATOR_CR_LF and more.
dataSeparator - Mark for deliberating the end of the incomming dataSerialAdapterListener.onSerialDataReceived(byte[], int) is called for hanling the incomming data.parameters - Parameters of opened serial prot
public boolean openPort(java.lang.String parameters,
byte[] dataSeparator,
long timeOut)
SerialAdapterListener.onSerialDataReceived(byte[], int) is called by adapter if there was a received data with closing sequence. See DATA_SEPARATOR_CR_LF and more.
dataSeparator - Mark for deliberating the end of the incomming dataSerialAdapterListener.onSerialDataReceived(byte[], int) is called for hanling the incomming data.parameters - Parameters of opened serial prottimeOut - timeout in miliseconds. If there were a data received but not closde by a closing char sequence, they will be processed as if they were closed after the timeout expires.
public boolean openPort(java.lang.String parameters)
SerialAdapterListener.onSerialDataReceived(byte[], int) is called by adapter if there was received at least a single byte.
parameters - Parameters of opened serial protpublic void close()
public boolean closePort()
public void setPriority(int priority)
priority - Thread prioritypublic java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public boolean writeData(byte[] data)
data - byte array
public boolean writeData(byte[] data,
int offset,
int length)
offset - position, from which the data will be sent inclusivelength - length of sent datadata - source byte array
public boolean writeData(java.lang.String data)
data - text
public boolean writeData(int onebyte)
onebyte -
public boolean writeData(java.io.InputStream ist,
int length)
ist - InputStream with data for serial writinglength - Number of bytes to write
public byte[] writeDataAndReadResponse(byte[] data)
data - Dta for writing
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||