⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialparameters.java

📁 jamod is an object oriented implementation of the Modbus protocol, realized 100 in Java. It allows
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      m_Databits = SerialPort.DATABITS_5;    }    if (databits.equals("6")) {      m_Databits = SerialPort.DATABITS_6;    }    if (databits.equals("7")) {      m_Databits = SerialPort.DATABITS_7;    }    if (databits.equals("8")) {      m_Databits = SerialPort.DATABITS_8;    }  }//setDatabits  /**   * Returns the number of data bits as <tt>int</tt>.   *   * @return the number of data bits as <tt>int</tt>.   */  public int getDatabits() {    return m_Databits;  }//getDatabits  /**   * Returns the number of data bits as <tt>String</tt>.   *   * @return the number of data bits as <tt>String</tt>.   */  public String getDatabitsString() {    switch (m_Databits) {      case SerialPort.DATABITS_5:        return "5";      case SerialPort.DATABITS_6:        return "6";      case SerialPort.DATABITS_7:        return "7";      case SerialPort.DATABITS_8:        return "8";      default:        return "8";    }  }//getDataBits  /**   * Sets the number of stop bits.   *   * @param stopbits the new number of stop bits setting.   */  public void setStopbits(int stopbits) {    m_Stopbits = stopbits;  }//setStopbits  /**   * Sets the number of stop bits from the given <tt>String</tt>.   *   * @param stopbits the number of stop bits as <tt>String</tt>.   */  public void setStopbits(String stopbits) {    if (stopbits.equals("1")) {      m_Stopbits = SerialPort.STOPBITS_1;    }    if (stopbits.equals("1.5")) {      m_Stopbits = SerialPort.STOPBITS_1_5;    }    if (stopbits.equals("2")) {      m_Stopbits = SerialPort.STOPBITS_2;    }  }//setStopbits  /**   * Returns the number of stop bits as <tt>int</tt>.   *   * @return the number of stop bits as <tt>int</tt>.   */  public int getStopbits() {    return m_Stopbits;  }//getStopbits  /**   * Returns the number of stop bits as <tt>String</tt>.   *   * @return the number of stop bits as <tt>String</tt>.   */  public String getStopbitsString() {    switch (m_Stopbits) {      case SerialPort.STOPBITS_1:        return "1";      case SerialPort.STOPBITS_1_5:        return "1.5";      case SerialPort.STOPBITS_2:        return "2";      default:        return "1";    }  }//getStopbitsString  /**   * Sets the parity schema.   *   * @param parity the new parity schema as <tt>int</tt>.   */  public void setParity(int parity) {    m_Parity = parity;  }//setParity  /**   * Sets the parity schema from the given   * <tt>String</tt>.   *   * @param parity the new parity schema as <tt>String</tt>.   */  public void setParity(String parity) {    parity = parity.toLowerCase();    if (parity.equals("none")) {      m_Parity = SerialPort.PARITY_NONE;    }    if (parity.equals("even")) {      m_Parity = SerialPort.PARITY_EVEN;    }    if (parity.equals("odd")) {      m_Parity = SerialPort.PARITY_ODD;    }  }//setParity  /**   * Returns the parity schema as <tt>int</tt>.   *   * @return the parity schema as <tt>int</tt>.   */  public int getParity() {    return m_Parity;  }//getParity  /**   * Returns the parity schema as <tt>String</tt>.   *   * @return the parity schema as <tt>String</tt>.   */  public String getParityString() {    switch (m_Parity) {      case SerialPort.PARITY_NONE:        return "none";      case SerialPort.PARITY_EVEN:        return "even";      case SerialPort.PARITY_ODD:        return "odd";      default:        return "none";    }  }//getParityString  /**   * Sets the encoding to be used.   *   * @param enc the encoding as string.   * @see Modbus#SERIAL_ENCODING_ASCII   * @see Modbus#SERIAL_ENCODING_RTU   * @see Modbus#SERIAL_ENCODING_BIN   */  public void setEncoding(String enc) {    enc = enc.toLowerCase();    if (enc.equals(Modbus.SERIAL_ENCODING_ASCII) ||        enc.equals(Modbus.SERIAL_ENCODING_RTU) ||        enc.equals(Modbus.SERIAL_ENCODING_BIN)    ) {      m_Encoding = enc;    } else {      m_Encoding = Modbus.DEFAULT_SERIAL_ENCODING;    }  }//setEncoding  /**   * Returns the encoding to be used.   *   * @return the encoding as string.   * @see Modbus#SERIAL_ENCODING_ASCII   * @see Modbus#SERIAL_ENCODING_RTU   * @see Modbus#SERIAL_ENCODING_BIN   */  public String getEncoding() {    return m_Encoding;  }//getEncoding  /**   * Get the Echo value.   *   * @return the Echo value.   */  public boolean isEcho() {    return m_Echo;  }//getEcho  /**   * Set the Echo value.   *   * @param newEcho The new Echo value.   */  public void setEcho(boolean newEcho) {    m_Echo = newEcho;  }//setEcho  /**   * Converts a <tt>String</tt> describing a flow control type to the   * <tt>int</tt> which is defined in SerialPort.   *   * @param flowcontrol the <tt>String</tt> describing the flow control type.   * @return the <tt>int</tt> describing the flow control type.   */  private int stringToFlow(String flowcontrol) {    flowcontrol = flowcontrol.toLowerCase();    if (flowcontrol.equals("none")) {      return SerialPort.FLOWCONTROL_NONE;    }    if (flowcontrol.equals("xon/xoff out")) {      return SerialPort.FLOWCONTROL_XONXOFF_OUT;    }    if (flowcontrol.equals("xon/xoff in")) {      return SerialPort.FLOWCONTROL_XONXOFF_IN;    }    if (flowcontrol.equals("rts/cts in")) {      return SerialPort.FLOWCONTROL_RTSCTS_IN;    }    if (flowcontrol.equals("rts/cts out")) {      return SerialPort.FLOWCONTROL_RTSCTS_OUT;    }    return SerialPort.FLOWCONTROL_NONE;  }//stringToFlow  /**   * Converts an <tt>int</tt> describing a flow control type to a   * String describing a flow control type.   *   * @param flowcontrol the <tt>int</tt> describing the   *                    flow control type.   * @return the <tt>String</tt> describing the flow control type.   */  private String flowToString(int flowcontrol) {    switch (flowcontrol) {      case SerialPort.FLOWCONTROL_NONE:        return "none";      case SerialPort.FLOWCONTROL_XONXOFF_OUT:        return "xon/xoff out";      case SerialPort.FLOWCONTROL_XONXOFF_IN:        return "xon/xoff in";      case SerialPort.FLOWCONTROL_RTSCTS_IN:        return "rts/cts in";      case SerialPort.FLOWCONTROL_RTSCTS_OUT:        return "rts/cts out";      default:        return "none";    }  }//flowToString  /**   * Populates the settings from an <tt>Proper</tt>   * that reads from a properties file or contains a   * set of properties.   *   * @param in the <tt>InputStream</tt> to read from.   *   private void loadFrom(InputStream in) throws IOException {   Properties props = new Properties();   props.load(in);   setPortName(props.getProperty("portName"));   setBaudRate(props.getProperty("baudRate"));   setFlowControlIn(props.getProperty("flowControlIn"));   setFlowControlOut(props.getProperty("flowControlOut"));   setParity(props.getProperty("parity"));   setDatabits(props.getProperty("databits"));   setStopbits(props.getProperty("stopbits"));   setEncoding(props.getProperty("encoding"));   setEcho(new Boolean(props.getProperty("echo")).booleanValue());   }//loadFrom   */}//class SerialParameters

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -