本文整理汇总了Java中gnu.io.SerialPort.PARITY_EVEN属性的典型用法代码示例。如果您正苦于以下问题:Java SerialPort.PARITY_EVEN属性的具体用法?Java SerialPort.PARITY_EVEN怎么用?Java SerialPort.PARITY_EVEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gnu.io.SerialPort
的用法示例。
在下文中一共展示了SerialPort.PARITY_EVEN属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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) 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);
}
示例2: 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) 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);
}
示例3: create
@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);
}
示例4: getParityString
/**
* 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";
}
}
示例5: getParityString
/**
* 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$
}
}
示例6: setParity
/**
* 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;
}
}
示例7: 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;
}
}
示例8: getParity
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;
}
}
示例9: getParityString
/**
* 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";
}
}
示例10: setParity
/**
* 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;
}
}
示例11: getParityString
/**
* 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$
}
}
示例12: open
/**
* @param def has 2 formats: e.g. "COM5,57600,8,1,N" or "ttyS3,9600"
* @return the connection, never null
* @throws IOException if we cannot parse the definition
*/
public static RXTXConnection open(final String def) throws IOException {
StringTokenizer st = new StringTokenizer(def, ",");
int count = st.countTokens();
final int minParam = 2;
final int maxParam = 5;
if ((count < minParam) || (count > maxParam)) {
throw new IOException("Open comm string must contain " + minParam + " to " + maxParam + " parameters");
}
String portName = st.nextToken();
String baudRateStr = st.nextToken();
int baudRate;
try {
baudRate = Integer.parseInt(baudRateStr);
} catch (NumberFormatException e) {
throw new IOException("Baud rate must be number: \"" + baudRateStr + "\"");
}
String dataBitsStr = "8";
if (count > minParam) {
dataBitsStr = st.nextToken().trim();
}
int dataBits;
if ("5".equals(dataBitsStr)) {
dataBits = SerialPort.DATABITS_5;
} else if ("6".equals(dataBitsStr)) {
dataBits = SerialPort.DATABITS_6;
} else if ("7".equals(dataBitsStr)) {
dataBits = SerialPort.DATABITS_7;
} else if ("8".equals(dataBitsStr)) {
dataBits = SerialPort.DATABITS_8;
} else {
throw new IOException("Data bits value may only be one of 5, 6, 7 or 8");
}
String stopBitsStr = "1";
if (count > minParam + 1) {
stopBitsStr = st.nextToken().trim();
}
int stopBits;
if ("1".equals(stopBitsStr)) {
stopBits = SerialPort.STOPBITS_1;
} else if ("1.5".equals(stopBitsStr)) {
stopBits = SerialPort.STOPBITS_1_5;
} else if ("2".equals(stopBitsStr)) {
stopBits = SerialPort.STOPBITS_2;
} else {
throw new IOException("Stop bits value may one be one of 1, 1.5 or 2");
}
String parityStr = "N";
if (count > minParam + 2) {
parityStr = st.nextToken().trim().toUpperCase();
}
int parity;
if ("E".equals(parityStr)) {
parity = SerialPort.PARITY_EVEN;
} else if ("O".equals(parityStr)) {
parity = SerialPort.PARITY_ODD;
} else if ("N".equals(parityStr)) {
parity = SerialPort.PARITY_NONE;
} else if ("M".equals(parityStr)) {
parity = SerialPort.PARITY_MARK;
} else {
throw new IOException("Parity value may only be one of E, O, N, M");
}
return new RXTXConnection(portName, baudRate, dataBits, stopBits, parity);
}
示例13: getPortSettingsFromString
/**
*
* @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;
}
}