com.pax.dal

Interface IComm



  • public interface IComm
    通信接口
    Communication interface
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface and Description
      static class  IComm.EConnectStatus
      连接状态定义
      connection status
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method and Description
      void cancelRecv()
      在阻塞模式下取消接收数据
      cancel receiving process in blocking mode
      void connect()
      连接
      connect
      void disconnect()
      断开连接
      disconnect
      IComm.EConnectStatus getConnectStatus()
      获取连接状态
      get connection status
      int getConnectTimeout()
      获取连接超时时间,默认20000ms。
      get connect timeout, default is 20000ms
      int getRecvTimeout()
      获取接收超时时间,默认20000ms。
      get receive timeout, default is 20000ms
      int getSendTimeout()
      获取发送超时时间,默认20000ms。
      get send timeout, default is 20000ms
      byte[] recv(int expLen)
      在阻塞模式下接收指定长度数据
      receive data with expected length, in blocking mode
      byte[] recvNonBlocking()
      在非阻塞模式下尽可能多的接收数据(即立即返回)
      receive data as much as possible, in non-blocking mode(i.e.
      void reset()
      重置接收缓冲区
      reset receive buffer
      void send(byte[] data)
      发送数据
      send data
      void sendDataUnlimited(byte[] data)
      发送数据
      send data
      void setConnectTimeout(int timeoutMs)
      设置连接超时时间 ,默认20000ms。
      set connect timeout, default is 20000ms
      void setRecvTimeout(int timeoutMs)
      设置接收超时时间 ,默认20000ms。
      set receive timeout, default is 20000ms
      void setSendTimeout(int timeoutMs)
      设置发送超时时间,默认20000ms。
      set send timeout, default is 20000ms
    • Method Detail

      • getConnectTimeout

        int getConnectTimeout()
        获取连接超时时间,默认20000ms。
        get connect timeout, default is 20000ms
        Returns:
        连接超时,单位ms
        connect timeout, in ms
      • setConnectTimeout

        void setConnectTimeout(int timeoutMs)
        设置连接超时时间 ,默认20000ms。
        set connect timeout, default is 20000ms
        Parameters:
        timeoutMs -
        连接超时,单位ms
        connect 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 -
        发送超时,单位ms
        send timeout, in ms
      • getRecvTimeout

        int getRecvTimeout()
        获取接收超时时间,默认20000ms。
        get receive timeout, default is 20000ms
        Returns:
        接收超时,单位ms
        receive timeout, in ms
      • setRecvTimeout

        void setRecvTimeout(int timeoutMs)
        设置接收超时时间 ,默认20000ms。
        set receive timeout, default is 20000ms
        Parameters:
        timeoutMs -
        接收超时,单位ms
        receive timeout, in ms
      • 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 receive

        if 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