📄 serialportparam.java
字号:
package com.zcsoft.comm;import java.io.*;/** * <p>Title: 串口通信</p> * <p>Description: 串口通信实验</p> * <p>Copyright: Copyright (c) 2004-2005</p> * <p>Company: Zhicheng Software&Service Co. Ltd.</p> * @author 蒋智湘 * @version 1.0 *//** * 串口配置参数。 * 参数包括:波特率、数据位、停止位、奇偶校验、接收方式及其该方式下的参数值 */public class SerialPortParam implements Serializable{ private int baudRate; private int dataBits; private int parity; private int stopBits; /** 定长接收,当接收缓冲区中的字节长度不小于指定的长度时,读取该长度的字节 */ public static final Integer METHOD_FIX_LENGTH = new Integer(0); /** 定时接收 */ public static final Integer METHOD_FIX_DURATION = new Integer(1); /** 固定字符结尾 */ public static final Integer METHOD_FIX_TERMINAL = new Integer(2); /** */ public static final Integer METHOD_FREE = new Integer(3); /** 接收方式。缺省地以回车字符结尾 */ private Integer receiveMethod = METHOD_FIX_LENGTH; /** 各种接收方式对应的配置参数值。 */ private String methodParam = "16"; public SerialPortParam() { } public void setBaudRate(int baudRate) { this.baudRate = baudRate; } public int getBaudRate() { return baudRate; } public void setDataBits(int dataBits) { this.dataBits = dataBits; } public int getDataBits() { return dataBits; } public void setParity(int parity) { this.parity = parity; } public int getParity() { return parity; } public void setStopBits(int stopBits) { this.stopBits = stopBits; } public int getStopBits() { return stopBits; } /** * * @param receiveMethod FIX_LENGTH | FIX_DURATION | FIX_TERMINAL * * @exception NullPointerException receiveMethod is null * @exception IllegalArgumentException receiveMethod not in{FIX_LENGTH | FIX_DURATION | FIX_TERMINAL} */ public void setReceiveMethod(Integer receiveMethod) { if (!receiveMethod.equals(METHOD_FIX_LENGTH) && !receiveMethod.equals(METHOD_FIX_DURATION) && !receiveMethod.equals(METHOD_FIX_TERMINAL) && !receiveMethod.equals(METHOD_FREE)) { throw new IllegalArgumentException(); } this.receiveMethod = receiveMethod; } public Integer getReceiveMethod() { return receiveMethod; } public String getMethodParam() { return methodParam; } /** * * @param methodParam 长度大于1的字符串 * @exception IllegalArgumentException methodParam.length == 0 */ public void setMethodParam(String methodParam) { if (methodParam.length() == 0) { throw new IllegalArgumentException(); } this.methodParam = methodParam; } public boolean isParameterValueValid() { return this.baudRate > 0 && this.dataBits > 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -