📄 serialport.java
字号:
* Timeout and Threshold disabled.
*
* @return InputStream object that can be used to read from the port
*/
public InputStream getInputStream()
{
try
{
Method method = classSerialPort.getMethod("getInputStream", (java.lang.Class[]) null);
return (InputStream) method.invoke(this.realObject);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Returns an output stream. This is the only way to send data to the
* communications port. If the port is unidirectional and doesn't support
* sending data, then getOutputStream returns null.
*
* @return OutputStream object that can be used to write to the port
*/
public OutputStream getOutputStream()
{
try
{
Method method = classSerialPort.getMethod("getOutputStream", (java.lang.Class[]) null);
return (OutputStream) method.invoke(this.realObject);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when there is a break
* interrupt on the line. This notification is hardware dependent and may
* not be supported by all implementations.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnBreakInterrupt(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnBreakInterrupt", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when input data is
* available. This may be used to drive asynchronous input. When data is
* available in the input buffer, this event is propagated to the listener
* registered using addEventListener. The event will be generated once when
* new data arrive at the serial port. Even if the user doesn't read the
* data, it won't be generated again until next time new data arrive.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnDataAvailable(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnDataAvailable", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when there is a parity
* error. This notification is hardware dependent and may not be supported
* by all implementations.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnFramingError(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnFramingError", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when the output buffer is
* empty. This may be used to drive asynchronous output. When the output
* buffer becomes empty, this event is propagated to the listener registered
* using addEventListener. The event will be generated after a write is
* completed, when the system buffer becomes empty again. This notification
* is hardware dependent and may not be supported by all implementations.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnOutputEmpty(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnOutputEmpty", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when there is an overrun
* error. This notification is hardware dependent and may not be supported
* by all implementations.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnOverrunError(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnOverrunError", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Expresses interest in receiving notification when there is a parity
* error. This notification is hardware dependent and may not be supported
* by all implementations.
*
* @param b
* <ul>
* <li> true: enable notification </li>
* <li> false: disable notification </li>
*/
public void notifyOnParityError(boolean b)
{
try
{
Method method = classSerialPort.getMethod("notifyOnParityError", boolean.class);
method.invoke(this.realObject, b);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Sets the flow control mode.
*
* @param flowcontrol
* Can be a bitmask combination of
* <ul>
* <li>FLOWCONTROL_NONE: no flow control</li>
* <li>FLOWCONTROL_RTSCTS_IN: RTS/CTS (hardware) flow control
* for input</li>
* <li>FLOWCONTROL_RTSCTS_OUT: RTS/CTS (hardware) flow control
* for output</li>
* <li>FLOWCONTROL_XONXOFF_IN: XON/XOFF (software) flow control
* for input</li>
* <li>FLOWCONTROL_XONXOFF_OUT: XON/XOFF (software) flow control
* for output</li>
* </ul>
*/
public void setFlowControlMode(int flowcontrol)
{
Class<?>[] paramTypes = new Class<?>[] { int.class };
try
{
Method method = classSerialPort.getMethod("setFlowControlMode", paramTypes);
method.invoke(this.realObject, flowcontrol);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Gets the input buffer size. Note that this method is advisory and the
* underlying OS may choose not to report correct values for the buffer
* size.
*
* @param serial_buffer_size
* input buffer size currently in use
*/
public void setInputBufferSize(int serial_buffer_size)
{
try
{
Method method = classSerialPort.getMethod("setInputBufferSize", int.class);
method.invoke(this.realObject, serial_buffer_size);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Sets the output buffer size. Note that this is advisory and memory
* availability may determine the ultimate buffer size used by the driver.
*
* @param serial_buffer_size
* size of the output buffer
*/
public void setOutputBufferSize(int serial_buffer_size)
{
try
{
Method method = classSerialPort.getMethod("setOutputBufferSize", int.class);
method.invoke(this.realObject, serial_buffer_size);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Sets serial port parameters.
*
* @param baudrate
* If the baudrate passed in by the application is unsupported by
* the driver, the driver will throw an
* UnsupportedCommOperationException
* @param dataBits
* <ul>
* <li>DATABITS_5: 5 bits</li>
* <li>DATABITS_6: 6 bits</li>
* <li>DATABITS_7: 7 bits</li>
* <li>DATABITS_8: 8 bits</li>
* </ul>
* @param stopBits
* <ul>
* <li>STOPBITS_1: 1 stop bit</li>
* <li>STOPBITS_2: 2 stop bits</li>
* <li>STOPBITS_1_5: 1.5 stop bits</li>
* </ul>
* @param parity
* <ul>
* <li>PARITY_NONE: no parity PARITY_ODD: odd parity</li>
* <li>PARITY_EVEN: even parity PARITY_MARK: mark parity</li>
* <li>PARITY_SPACE: space parity</li>
* </ul>
*/
public void setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
{
Class<?>[] paramTypes = new Class<?>[] { int.class, int.class, int.class, int.class };
try
{
Method method = classSerialPort.getMethod("setSerialPortParams", paramTypes);
method.invoke(this.realObject, baudrate, dataBits, stopBits, parity);
}
catch (InvocationTargetException e)
{
throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -