Java Code Examples for gnu.io.SerialPort#PARITY_EVEN

The following examples show how to use gnu.io.SerialPort#PARITY_EVEN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerialFatekConnectionFactory.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
private int getParity() throws IOException {
    final Optional<String> parity = getParam("parity");
    switch (parity.map(String::toUpperCase).orElse("EVEN")) {
        case "NONE":
            return SerialPort.PARITY_NONE;
        case "ODD":
            return SerialPort.PARITY_ODD;
        case "EVEN":
            return SerialPort.PARITY_EVEN;
        case "MARK":
            return SerialPort.PARITY_MARK;
        case "SPACE":
            return SerialPort.PARITY_SPACE;
        default:
            throw new IOException("Unknown parity=" + parity);
    }
}
 
Example 2
Source File: SerialParameters.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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) throws IllegalArgumentException {
    parity = parity.toLowerCase();
    int intParity = SerialPort.PARITY_NONE;

    if (parity.equals("none") || parity.equals("n")) {
        intParity = SerialPort.PARITY_NONE;
    } else if (parity.equals("even") || parity.equals("e")) {
        intParity = SerialPort.PARITY_EVEN;
    } else if (parity.equals("odd") || parity.equals("o")) {
        intParity = SerialPort.PARITY_ODD;
    } else {
        throw new IllegalArgumentException("unknown parity string '" + parity + "'");
    }

    setParity(intParity);
}
 
Example 3
Source File: CULSerialConfigFactory.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public CULConfig create(String deviceType, String deviceAddress, CULMode mode, Dictionary<String, ?> config)
        throws ConfigurationException {
    int baudRate = 9600;
    final String configuredBaudRate = (String) config.get(KEY_BAUDRATE);
    Integer tmpBaudRate = baudrateFromConfig(configuredBaudRate);
    if (tmpBaudRate != null) {
        baudRate = tmpBaudRate;
        logger.info("Update config, {} = {}", KEY_BAUDRATE, baudRate);
    }

    int parityMode = SerialPort.PARITY_EVEN;
    final String configuredParity = (String) config.get(KEY_PARITY);
    Integer parsedParityNumber = parityFromConfig(configuredParity);
    if (parsedParityNumber != null) {
        parityMode = parsedParityNumber;
        logger.info("Update config, {} = {} ({})", KEY_PARITY, convertParityModeToString(parityMode), parityMode);
    }

    return new CULSerialConfig(deviceType, deviceAddress, mode, baudRate, parityMode);
}
 
Example 4
Source File: SerialPortParameters.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
public static int getParity(String sPortParity) {
    switch (sPortParity) {
        case "none":
            return SerialPort.PARITY_NONE;
        case "even":
            return SerialPort.PARITY_EVEN;
        case "odd":
            return SerialPort.PARITY_ODD;
        default:
            return SerialPort.PARITY_NONE;
    }
}
 
Example 5
Source File: SerialParameters.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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";
    }
}
 
Example 6
Source File: SerialParameters.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets parity setting.
 * 
 * @param parity
 *            New parity setting.
 */
public void setParity(final String parity){
	if (parity.equals("None")) { //$NON-NLS-1$
		this.parity = SerialPort.PARITY_NONE;
	}
	if (parity.equals("Even")) { //$NON-NLS-1$
		this.parity = SerialPort.PARITY_EVEN;
	}
	if (parity.equals("Odd")) { //$NON-NLS-1$
		this.parity = SerialPort.PARITY_ODD;
	}
}
 
Example 7
Source File: SerialParameters.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets parity setting as a <code>String</code>.
 * 
 * @return Current parity setting.
 */
public String getParityString(){
	switch (parity) {
	case SerialPort.PARITY_NONE:
		return "None"; //$NON-NLS-1$
	case SerialPort.PARITY_EVEN:
		return "Even"; //$NON-NLS-1$
	case SerialPort.PARITY_ODD:
		return "Odd"; //$NON-NLS-1$
	default:
		return "None"; //$NON-NLS-1$
	}
}
 
Example 8
Source File: DSMRPortSettings.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 *
 * @param portSettings
 * @return
 */
public static DSMRPortSettings getPortSettingsFromString(String portSettings) {
    Matcher m = Pattern.compile(PORT_SETTING_REGEX).matcher(portSettings);

    if (m.find()) {
        int baudrate = Integer.parseInt(m.group(1));
        int databits = Integer.parseInt(m.group(2));
        int parity;
        int stopbits;

        char parityChar = m.group(3).toUpperCase().charAt(0);
        switch (parityChar) {
            case 'E':
                parity = SerialPort.PARITY_EVEN;
                break;
            case 'O':
                parity = SerialPort.PARITY_ODD;
                break;
            case 'N':
                parity = SerialPort.PARITY_NONE;
                break;
            default:
                logger.error("Invalid parity ({}), ignoring fixed port settings.", parityChar);

                return null;
        }
        String stopbitsString = m.group(4);

        if (stopbitsString.equals("1")) {
            stopbits = SerialPort.STOPBITS_1;
        } else if (stopbitsString.equals("1.5")) {
            stopbits = SerialPort.STOPBITS_1_5;
        } else if (stopbitsString.equals("2")) {
            stopbits = SerialPort.STOPBITS_2;
        } else {
            logger.error("Invalid stop bits({}), ignoring fixed port settings.", stopbitsString);

            return null;
        }
        return new DSMRPortSettings(baudrate, databits, parity, stopbits);
    } else {
        return null;
    }
}