001/*
002 * ===========================================================================================
003 * = COPYRIGHT
004 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
005 *   This software is supplied under the terms of a license agreement or nondisclosure
006 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
007 *   disclosed except in accordance with the terms in that agreement.
008 *     Copyright (C) 2017-2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
009 * Description: // Detail description about the function of this module,
010 *             // interfaces with the other modules, and dependencies.
011 * Revision History:
012 * Date                         Author                        Action
013 * 2017/04/01                   PAX                     Create/Add/Modify/Delete
014 * ===========================================================================================
015 */
016 
017package com.pax.dal;
018
019import com.pax.dal.exceptions.CommException;
020
021/**
022 * <div class="zh"> 通信接口 </div> <div class="en"> Communication interface </div>
023 */
024public interface IComm {
025
026    /**
027     * <div class="zh"> 连接状态定义 </div> <div class="en"> connection status </div>
028     * 
029     */
030    public enum EConnectStatus {
031        /**
032         * <div class="zh"> 断开连接 </div> <div class="en"> disconnected </div>
033         * 
034         */
035        DISCONNECTED,
036        /**
037         * <div class="zh"> 正在连接 </div> <div class="en"> connecting </div>
038         * 
039         */
040        CONNECTING,
041        /**
042         * <div class="zh"> 已连接 </div> <div class="en"> connected </div>
043         * 
044         */
045        CONNECTED
046    }
047
048    /**
049     * <div class="zh"> 获取连接超时时间,默认20000ms。 </div> <div class="en"> get connect timeout, default is 20000ms </div>
050     * 
051     * 
052     * @return <div class="zh"> 连接超时,单位ms </div> <div class="en"> connect timeout, in ms </div>
053     * 
054     */
055    public int getConnectTimeout();
056
057    /**
058     * <div class="zh"> 设置连接超时时间 ,默认20000ms。</div> <div class="en"> set connect timeout, default is 20000ms </div>
059     * 
060     * 
061     * @param timeoutMs
062     *            <div class="zh"> 连接超时,单位ms </div> <div class="en"> connect timeout, in ms </div>
063     * 
064     */
065    public void setConnectTimeout(int timeoutMs);
066
067    /**
068     * <div class="zh"> 获取发送超时时间,默认20000ms。 </div> <div class="en"> get send timeout, default is 20000ms </div>
069     * 
070     * @return <div class="zh"> 获取发送超时时间 </div> <div class="en"> send timeout, in ms </div>
071     * 
072     */
073    public int getSendTimeout();
074
075    /**
076     * <div class="zh"> 设置发送超时时间,默认20000ms。 </div> <div class="en"> set send timeout, default is 20000ms </div>
077     * 
078     * 
079     * @param timeoutMs
080     *            <div class="zh"> 发送超时,单位ms </div> <div class="en"> send timeout, in ms </div>
081     * 
082     */
083    public void setSendTimeout(int timeoutMs);
084
085    /**
086     * <div class="zh"> 获取接收超时时间,默认20000ms。 </div> <div class="en"> get receive timeout, default is 20000ms </div>
087     * 
088     * 
089     * @return <div class="zh"> 接收超时,单位ms </div> <div class="en"> receive timeout, in ms </div>
090     * 
091     */
092    public int getRecvTimeout();
093
094    /**
095     * <div class="zh"> 设置接收超时时间 ,默认20000ms。</div> <div class="en"> set receive timeout, default is 20000ms </div>
096     * 
097     * 
098     * @param timeoutMs
099     *            <div class="zh"> 接收超时,单位ms </div> <div class="en"> receive timeout, in ms </div>
100     * 
101     * 
102     */
103    public void setRecvTimeout(int timeoutMs);
104
105    /**
106     * <div class="zh"> 连接 </div> <div class="en"> connect </div>
107     * 
108     * 
109     * @throws CommException
110     *             <div class="zh"> 通信异常 </div> <div class="en"> communication exception </div>
111     * 
112     */
113    public void connect() throws CommException;
114
115    /**
116     * <div class="zh"> 获取连接状态 </div> <div class="en"> get connection status </div>
117     * 
118     * 
119     * @return <div class="zh"> 连接状态 </div> <div class="en"> connection status </div>
120     * 
121     */
122    public EConnectStatus getConnectStatus();
123
124    /**
125     * <div class="zh"> 断开连接 </div> <div class="en"> disconnect </div>
126     * 
127     * 
128     * @throws CommException
129     *             <div class="zh"> 通信异常 </div> <div class="en"> communication exception </div>
130     * 
131     */
132    public void disconnect() throws CommException;
133
134    /**
135     * <div class="zh"> 发送数据 </div> <div class="en"> send data </div>
136     * 
137     * 
138     * @param data
139     *            <div class="zh"> 待发送数据 </div> <div class="en"> data to send </div>
140     * 
141     * @throws CommException
142     *             <div class="zh"> 通信异常 </div> <div class="en"> communication exception </div>
143     * 
144     */
145    public void send(byte[] data) throws CommException;
146
147    /**
148     * <div class="zh"> 发送数据 </div> <div class="en"> send data </div>
149     *
150     *
151     * @param data
152     *            <div class="zh"> 待发送数据,数据大小不限制在8K以内 </div> <div class="en"> data to send,Data size is not limited to 8K</div>
153     *
154     * @throws CommException
155     *             <div class="zh"> 通信异常 </div> <div class="en"> communication exception </div>
156     *
157     */
158    public void sendDataUnlimited(byte[] data) throws CommException;
159
160    /**
161     * <div class="zh"> 在阻塞模式下接收指定长度数据 </div> <div class="en"> receive data with expected length, in blocking mode
162     * </div>
163     * 
164     * 
165     * @param expLen
166     *            <div class="zh"> 期望接收的数据长度
167     *            <p>
168     *            若传入-1,则此接口功能为检测串口缓存区的数据长度,此时返回值为int转化后的4字节数组 .
169     *            <ul>
170     *            <li>timeout = 0: 不论串口缓存是否有数据,该接口立刻返回结果 </li>
171     *            <li>timeout > 0: 如在超时时间内检测到缓存数据,立即返回;如缓存无数据,保持检测等待直到超时后返回 </li>
172     *            <li>timeout < 0: 可以无限等待直到有串口缓存数据</li>
173     *            </ul>
174     *            </div> <div class="en"> length of data expected to
175     *            receive
176     *            <p>
177     *            if expLen == -1, the interface is to detect the available data length of the serial buffer, and the
178     *            return value is an int-converted 4-byte array.
179     *            <ul>
180     *            <li>timeout = 0: Whether or not the serial port cache has data, the interface returns the result immediately. </li>
181     *            <li>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. </li>
182     *            <li>timeout < 0: You can wait indefinitely until you have a serial port to cache data</li>
183     *            </ul>
184     *            </div>
185     * 
186     * @return <div class="zh"> 接收到的数据, 如果没收到任何数据则返回new byte[0] </div> <div class="en"> data received, new byte[0] is
187     *         returned if nothing received </div>
188     * 
189     * @throws CommException
190     *             <div class="zh"> 通信错误 </div> <div class="en"> communication exception </div>
191     * 
192     */
193    public byte[] recv(int expLen) throws CommException;
194
195    /**
196     * <div class="zh"> 在非阻塞模式下尽可能多的接收数据(即立即返回) </div> <div class="en"> receive data as much as possible, in
197     * non-blocking mode(i.e. returns immediately) </div>
198     * 
199     * @return <div class="zh"> 接收到的数据, 如果没收到任何数据则返回new byte[0] </div> <div class="en"> data received, new byte[0] is
200     *         returned if nothing received </div>
201     * 
202     * @throws CommException
203     * 
204     *             <div class="zh"> 通信错误 </div> <div class="en"> communication exception </div>
205     * 
206     */
207    public byte[] recvNonBlocking() throws CommException;
208
209    /**
210     * <div class="zh"> 重置接收缓冲区 </div> <div class="en"> reset receive buffer </div>
211     */
212    public void reset();
213
214    /**
215     * <div class="zh"> 在阻塞模式下取消接收数据 </div> <div class="en"> cancel receiving process in blocking mode </div>
216     */
217    public void cancelRecv();
218}