Package com.tinkerforge
Class BrickletRS232
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletRS232
-
public class BrickletRS232 extends Device
Communicates with RS232 devices
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletRS232.Configuration
static interface
BrickletRS232.ErrorCallbackListener
This listener is called if an error occurs.static interface
BrickletRS232.ErrorListener
This listener is called if an error occurs.static interface
BrickletRS232.FrameReadableListener
This listener is called if at least one frame of data is readable.class
BrickletRS232.Read
static interface
BrickletRS232.ReadCallbackListener
This listener is called if new data is available.class
BrickletRS232.ReadFrame
static interface
BrickletRS232.ReadListener
This listener is called if new data is available.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BrickletRS232(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addErrorCallbackListener(BrickletRS232.ErrorCallbackListener listener)
Adds a ErrorCallback listener.void
addErrorListener(BrickletRS232.ErrorListener listener)
Adds a Error listener.void
addFrameReadableListener(BrickletRS232.FrameReadableListener listener)
Adds a FrameReadable listener.void
addReadCallbackListener(BrickletRS232.ReadCallbackListener listener)
Adds a ReadCallback listener.void
addReadListener(BrickletRS232.ReadListener listener)
Adds a Read listener.void
disableReadCallback()
Disables theBrickletRS232.ReadListener
listener.void
enableReadCallback()
Enables theBrickletRS232.ReadListener
listener.BrickletRS232.Configuration
getConfiguration()
Returns the configuration as set bysetConfiguration(short, short, short, short, short, short)
.short
getFrameReadableCallbackConfiguration()
Returns the listener configuration as set bysetFrameReadableCallbackConfiguration(short)
.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.boolean
isReadCallbackEnabled()
Returns *true* if theBrickletRS232.ReadListener
listener is enabled, *false* otherwise.BrickletRS232.Read
read()
Returns the currently buffered message.BrickletRS232.ReadFrame
readFrame()
Returns up to one frame of bytes from the read buffer.void
removeErrorCallbackListener(BrickletRS232.ErrorCallbackListener listener)
Removes a ErrorCallback listener.void
removeErrorListener(BrickletRS232.ErrorListener listener)
Removes a Error listener.void
removeFrameReadableListener(BrickletRS232.FrameReadableListener listener)
Removes a FrameReadable listener.void
removeReadCallbackListener(BrickletRS232.ReadCallbackListener listener)
Removes a ReadCallback listener.void
removeReadListener(BrickletRS232.ReadListener listener)
Removes a Read listener.void
setBreakCondition(int breakTime)
Sets a break condition (the TX output is forced to a logic 0 state).void
setConfiguration(short baudrate, short parity, short stopbits, short wordlength, short hardwareFlowcontrol, short softwareFlowcontrol)
Sets the configuration for the RS232 communication.void
setFrameReadableCallbackConfiguration(short frameSize)
Configures theBrickletRS232.FrameReadableListener
listener.short
write(char[] message, short length)
Writes a string of up to 60 characters to the RS232 interface.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_WRITE
public static final byte FUNCTION_WRITE
- See Also:
- Constant Field Values
-
FUNCTION_READ
public static final byte FUNCTION_READ
- See Also:
- Constant Field Values
-
FUNCTION_ENABLE_READ_CALLBACK
public static final byte FUNCTION_ENABLE_READ_CALLBACK
- See Also:
- Constant Field Values
-
FUNCTION_DISABLE_READ_CALLBACK
public static final byte FUNCTION_DISABLE_READ_CALLBACK
- See Also:
- Constant Field Values
-
FUNCTION_IS_READ_CALLBACK_ENABLED
public static final byte FUNCTION_IS_READ_CALLBACK_ENABLED
- See Also:
- Constant Field Values
-
FUNCTION_SET_CONFIGURATION
public static final byte FUNCTION_SET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_CONFIGURATION
public static final byte FUNCTION_GET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_SET_BREAK_CONDITION
public static final byte FUNCTION_SET_BREAK_CONDITION
- See Also:
- Constant Field Values
-
FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION
public static final byte FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION
public static final byte FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_READ_FRAME
public static final byte FUNCTION_READ_FRAME
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
BAUDRATE_300
public static final short BAUDRATE_300
- See Also:
- Constant Field Values
-
BAUDRATE_600
public static final short BAUDRATE_600
- See Also:
- Constant Field Values
-
BAUDRATE_1200
public static final short BAUDRATE_1200
- See Also:
- Constant Field Values
-
BAUDRATE_2400
public static final short BAUDRATE_2400
- See Also:
- Constant Field Values
-
BAUDRATE_4800
public static final short BAUDRATE_4800
- See Also:
- Constant Field Values
-
BAUDRATE_9600
public static final short BAUDRATE_9600
- See Also:
- Constant Field Values
-
BAUDRATE_14400
public static final short BAUDRATE_14400
- See Also:
- Constant Field Values
-
BAUDRATE_19200
public static final short BAUDRATE_19200
- See Also:
- Constant Field Values
-
BAUDRATE_28800
public static final short BAUDRATE_28800
- See Also:
- Constant Field Values
-
BAUDRATE_38400
public static final short BAUDRATE_38400
- See Also:
- Constant Field Values
-
BAUDRATE_57600
public static final short BAUDRATE_57600
- See Also:
- Constant Field Values
-
BAUDRATE_115200
public static final short BAUDRATE_115200
- See Also:
- Constant Field Values
-
BAUDRATE_230400
public static final short BAUDRATE_230400
- See Also:
- Constant Field Values
-
PARITY_NONE
public static final short PARITY_NONE
- See Also:
- Constant Field Values
-
PARITY_ODD
public static final short PARITY_ODD
- See Also:
- Constant Field Values
-
PARITY_EVEN
public static final short PARITY_EVEN
- See Also:
- Constant Field Values
-
PARITY_FORCED_PARITY_1
public static final short PARITY_FORCED_PARITY_1
- See Also:
- Constant Field Values
-
PARITY_FORCED_PARITY_0
public static final short PARITY_FORCED_PARITY_0
- See Also:
- Constant Field Values
-
STOPBITS_1
public static final short STOPBITS_1
- See Also:
- Constant Field Values
-
STOPBITS_2
public static final short STOPBITS_2
- See Also:
- Constant Field Values
-
WORDLENGTH_5
public static final short WORDLENGTH_5
- See Also:
- Constant Field Values
-
WORDLENGTH_6
public static final short WORDLENGTH_6
- See Also:
- Constant Field Values
-
WORDLENGTH_7
public static final short WORDLENGTH_7
- See Also:
- Constant Field Values
-
WORDLENGTH_8
public static final short WORDLENGTH_8
- See Also:
- Constant Field Values
-
HARDWARE_FLOWCONTROL_OFF
public static final short HARDWARE_FLOWCONTROL_OFF
- See Also:
- Constant Field Values
-
HARDWARE_FLOWCONTROL_ON
public static final short HARDWARE_FLOWCONTROL_ON
- See Also:
- Constant Field Values
-
SOFTWARE_FLOWCONTROL_OFF
public static final short SOFTWARE_FLOWCONTROL_OFF
- See Also:
- Constant Field Values
-
SOFTWARE_FLOWCONTROL_ON
public static final short SOFTWARE_FLOWCONTROL_ON
- See Also:
- Constant Field Values
-
ERROR_OVERRUN
public static final short ERROR_OVERRUN
- See Also:
- Constant Field Values
-
ERROR_PARITY
public static final short ERROR_PARITY
- See Also:
- Constant Field Values
-
ERROR_FRAMING
public static final short ERROR_FRAMING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletRS232
public BrickletRS232(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
write
public short write(char[] message, short length) throws TinkerforgeException
Writes a string of up to 60 characters to the RS232 interface. The string can be binary data, ASCII or similar is not necessary. The length of the string has to be given as an additional parameter. The return value is the number of bytes that could be written. SeesetConfiguration(short, short, short, short, short, short)
for configuration possibilities regarding baudrate, parity and so on.- Throws:
TinkerforgeException
-
read
public BrickletRS232.Read read() throws TinkerforgeException
Returns the currently buffered message. The maximum length of message is 60. If the returned length is 0, no new data was available. Instead of polling with this function, you can also use callbacks. SeeenableReadCallback()
andBrickletRS232.ReadListener
listener.- Throws:
TinkerforgeException
-
enableReadCallback
public void enableReadCallback() throws TinkerforgeException
Enables theBrickletRS232.ReadListener
listener. This will disable theBrickletRS232.FrameReadableListener
listener. By default the listener is disabled.- Throws:
TinkerforgeException
-
disableReadCallback
public void disableReadCallback() throws TinkerforgeException
Disables theBrickletRS232.ReadListener
listener. By default the listener is disabled.- Throws:
TinkerforgeException
-
isReadCallbackEnabled
public boolean isReadCallbackEnabled() throws TinkerforgeException
Returns *true* if theBrickletRS232.ReadListener
listener is enabled, *false* otherwise.- Throws:
TinkerforgeException
-
setConfiguration
public void setConfiguration(short baudrate, short parity, short stopbits, short wordlength, short hardwareFlowcontrol, short softwareFlowcontrol) throws TinkerforgeException
Sets the configuration for the RS232 communication. Hard-/Software flow control can either be on or off but not both simultaneously on.- Throws:
TinkerforgeException
-
getConfiguration
public BrickletRS232.Configuration getConfiguration() throws TinkerforgeException
Returns the configuration as set bysetConfiguration(short, short, short, short, short, short)
.- Throws:
TinkerforgeException
-
setBreakCondition
public void setBreakCondition(int breakTime) throws TinkerforgeException
Sets a break condition (the TX output is forced to a logic 0 state). The parameter sets the hold-time of the break condition. .. versionadded:: 2.0.2$nbsp;(Plugin)- Throws:
TinkerforgeException
-
setFrameReadableCallbackConfiguration
public void setFrameReadableCallbackConfiguration(short frameSize) throws TinkerforgeException
Configures theBrickletRS232.FrameReadableListener
listener. The frame size is the number of bytes, that have to be readable to trigger the listener. A frame size of 0 disables the listener. A frame size greater than 0 enables the listener and disables theBrickletRS232.ReadListener
listener. By default the listener is disabled. .. versionadded:: 2.0.4$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getFrameReadableCallbackConfiguration
public short getFrameReadableCallbackConfiguration() throws TinkerforgeException
Returns the listener configuration as set bysetFrameReadableCallbackConfiguration(short)
. .. versionadded:: 2.0.4$nbsp;(Plugin)- Throws:
TinkerforgeException
-
readFrame
public BrickletRS232.ReadFrame readFrame() throws TinkerforgeException
Returns up to one frame of bytes from the read buffer. The frame size is configured withsetFrameReadableCallbackConfiguration(short)
. If the returned length is 0, no new data was available. .. versionadded:: 2.0.4$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier. The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'. The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addReadListener
public void addReadListener(BrickletRS232.ReadListener listener)
Adds a Read listener.
-
removeReadListener
public void removeReadListener(BrickletRS232.ReadListener listener)
Removes a Read listener.
-
addErrorListener
public void addErrorListener(BrickletRS232.ErrorListener listener)
Adds a Error listener.
-
removeErrorListener
public void removeErrorListener(BrickletRS232.ErrorListener listener)
Removes a Error listener.
-
addFrameReadableListener
public void addFrameReadableListener(BrickletRS232.FrameReadableListener listener)
Adds a FrameReadable listener.
-
removeFrameReadableListener
public void removeFrameReadableListener(BrickletRS232.FrameReadableListener listener)
Removes a FrameReadable listener.
-
addReadCallbackListener
public void addReadCallbackListener(BrickletRS232.ReadCallbackListener listener)
Adds a ReadCallback listener.
-
removeReadCallbackListener
public void removeReadCallbackListener(BrickletRS232.ReadCallbackListener listener)
Removes a ReadCallback listener.
-
addErrorCallbackListener
public void addErrorCallbackListener(BrickletRS232.ErrorCallbackListener listener)
Adds a ErrorCallback listener.
-
removeErrorCallbackListener
public void removeErrorCallbackListener(BrickletRS232.ErrorCallbackListener listener)
Removes a ErrorCallback listener.
-
-