com.pax.dal
Interface IComm
-
public interface IComm
通信接口Communication interface
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static classIComm.EConnectStatus连接状态定义connection status
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidcancelRecv()在阻塞模式下取消接收数据cancel receiving process in blocking modevoidconnect()连接connectvoiddisconnect()断开连接disconnectIComm.EConnectStatusgetConnectStatus()获取连接状态get connection statusintgetConnectTimeout()获取连接超时时间,默认20000ms。get connect timeout, default is 20000msintgetRecvTimeout()获取接收超时时间,默认20000ms。get receive timeout, default is 20000msintgetSendTimeout()获取发送超时时间,默认20000ms。get send timeout, default is 20000msbyte[]recv(int expLen)在阻塞模式下接收指定长度数据receive data with expected length, in blocking modebyte[]recvNonBlocking()在非阻塞模式下尽可能多的接收数据(即立即返回)receive data as much as possible, in non-blocking mode(i.e.voidreset()重置接收缓冲区reset receive buffervoidsend(byte[] data)发送数据send datavoidsendDataUnlimited(byte[] data)发送数据send datavoidsetConnectTimeout(int timeoutMs)设置连接超时时间 ,默认20000ms。set connect timeout, default is 20000msvoidsetRecvTimeout(int timeoutMs)设置接收超时时间 ,默认20000ms。set receive timeout, default is 20000msvoidsetSendTimeout(int timeoutMs)设置发送超时时间,默认20000ms。set send timeout, default is 20000ms
-
-
-
Method Detail
-
getConnectTimeout
int getConnectTimeout()
获取连接超时时间,默认20000ms。get connect timeout, default is 20000ms- Returns:
- 连接超时,单位msconnect timeout, in ms
-
setConnectTimeout
void setConnectTimeout(int timeoutMs)
设置连接超时时间 ,默认20000ms。set connect timeout, default is 20000ms- Parameters:
timeoutMs-连接超时,单位msconnect timeout, in ms
-
getSendTimeout
int getSendTimeout()
获取发送超时时间,默认20000ms。get send timeout, default is 20000ms- Returns:
- 获取发送超时时间send timeout, in ms
-
setSendTimeout
void setSendTimeout(int timeoutMs)
设置发送超时时间,默认20000ms。set send timeout, default is 20000ms- Parameters:
timeoutMs-发送超时,单位mssend timeout, in ms
-
getRecvTimeout
int getRecvTimeout()
获取接收超时时间,默认20000ms。get receive timeout, default is 20000ms- Returns:
- 接收超时,单位msreceive timeout, in ms
-
setRecvTimeout
void setRecvTimeout(int timeoutMs)
设置接收超时时间 ,默认20000ms。set receive timeout, default is 20000ms- Parameters:
timeoutMs-接收超时,单位msreceive timeout, in ms
-
connect
void connect() throws CommException
连接connect- Throws:
CommException-通信异常communication exception
-
getConnectStatus
IComm.EConnectStatus getConnectStatus()
获取连接状态get connection status- Returns:
- 连接状态connection status
-
disconnect
void disconnect() throws CommException
断开连接disconnect- Throws:
CommException-通信异常communication exception
-
send
void send(byte[] data) throws CommException
发送数据send data- Parameters:
data-待发送数据data to send- Throws:
CommException-通信异常communication exception
-
sendDataUnlimited
void sendDataUnlimited(byte[] data) throws CommException
发送数据send data- Parameters:
data-待发送数据,数据大小不限制在8K以内data to send,Data size is not limited to 8K- Throws:
CommException-通信异常communication exception
-
recv
byte[] recv(int expLen) throws CommException
在阻塞模式下接收指定长度数据receive data with expected length, in blocking mode- Parameters:
expLen-期望接收的数据长度若传入-1,则此接口功能为检测串口缓存区的数据长度,此时返回值为int转化后的4字节数组 .
- timeout = 0: 不论串口缓存是否有数据,该接口立刻返回结果
- timeout > 0: 如在超时时间内检测到缓存数据,立即返回;如缓存无数据,保持检测等待直到超时后返回
- timeout < 0: 可以无限等待直到有串口缓存数据
length of data expected to receiveif expLen == -1, the interface is to detect the available data length of the serial buffer, and the return value is an int-converted 4-byte array.
- timeout = 0: Whether or not the serial port cache has data, the interface returns the result immediately.
- timeout > 0: If the cached data is detected within the timeout time, it will be returned immediately; if there is no data in the cache, keep the detection waiting until it returns after the timeout.
- timeout < 0: You can wait indefinitely until you have a serial port to cache data
- Returns:
- 接收到的数据, 如果没收到任何数据则返回new byte[0]data received, new byte[0] is returned if nothing received
- Throws:
CommException-通信错误communication exception
-
recvNonBlocking
byte[] recvNonBlocking() throws CommException
在非阻塞模式下尽可能多的接收数据(即立即返回)receive data as much as possible, in non-blocking mode(i.e. returns immediately)- Returns:
- 接收到的数据, 如果没收到任何数据则返回new byte[0]data received, new byte[0] is returned if nothing received
- Throws:
CommException-通信错误communication exception
-
reset
void reset()
重置接收缓冲区reset receive buffer
-
cancelRecv
void cancelRecv()
在阻塞模式下取消接收数据cancel receiving process in blocking mode
-
-