Package com.tinkerforge
Class BrickletRS232V2
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletRS232V2
-
public class BrickletRS232V2 extends Device
Communicates with RS232 devices
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletRS232V2.BufferConfig
class
BrickletRS232V2.BufferStatus
class
BrickletRS232V2.Configuration
class
BrickletRS232V2.ErrorCount
static interface
BrickletRS232V2.ErrorCountListener
This listener is called if a new error occurs.static interface
BrickletRS232V2.FrameReadableListener
This listener is called if at least one frame of data is readable.static interface
BrickletRS232V2.ReadListener
This listener is called if new data is available.class
BrickletRS232V2.ReadLowLevel
static interface
BrickletRS232V2.ReadLowLevelListener
class
BrickletRS232V2.SPITFPErrorCount
-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BrickletRS232V2(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
addErrorCountListener(BrickletRS232V2.ErrorCountListener listener)
Adds a ErrorCount listener.void
addFrameReadableListener(BrickletRS232V2.FrameReadableListener listener)
Adds a FrameReadable listener.void
addReadListener(BrickletRS232V2.ReadListener listener)
Adds a Read listener.void
addReadLowLevelListener(BrickletRS232V2.ReadLowLevelListener listener)
Adds a ReadLowLevel listener.void
disableReadCallback()
Disables theBrickletRS232V2.ReadListener
listener.void
enableReadCallback()
Enables theBrickletRS232V2.ReadListener
listener.int
getBootloaderMode()
Returns the current bootloader mode, seesetBootloaderMode(int)
.BrickletRS232V2.BufferConfig
getBufferConfig()
Returns the buffer configuration as set bysetBufferConfig(int, int)
.BrickletRS232V2.BufferStatus
getBufferStatus()
Returns the currently used bytes for the send and received buffer.int
getChipTemperature()
Returns the temperature as measured inside the microcontroller.BrickletRS232V2.Configuration
getConfiguration()
Returns the configuration as set bysetConfiguration(long, int, int, int, int)
.BrickletRS232V2.ErrorCount
getErrorCount()
Returns the current number of overrun and parity errors.int
getFrameReadableCallbackConfiguration()
Returns the listener configuration as set bysetFrameReadableCallbackConfiguration(int)
.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.BrickletRS232V2.SPITFPErrorCount
getSPITFPErrorCount()
Returns the error count for the communication between Brick and Bricklet.int
getStatusLEDConfig()
Returns the configuration as set bysetStatusLEDConfig(int)
boolean
isReadCallbackEnabled()
Returns *true* if theBrickletRS232V2.ReadListener
listener is enabled, *false* otherwise.char[]
read(int length)
Returns up to *length* characters from receive buffer.BrickletRS232V2.ReadLowLevel
readLowLevel(int length)
Returns up to *length* characters from receive buffer.long
readUID()
Returns the current UID as an integer.void
removeErrorCountListener(BrickletRS232V2.ErrorCountListener listener)
Removes a ErrorCount listener.void
removeFrameReadableListener(BrickletRS232V2.FrameReadableListener listener)
Removes a FrameReadable listener.void
removeReadListener(BrickletRS232V2.ReadListener listener)
Removes a Read listener.void
removeReadLowLevelListener(BrickletRS232V2.ReadLowLevelListener listener)
Removes a ReadLowLevel listener.void
reset()
Calling this function will reset the Bricklet.int
setBootloaderMode(int mode)
Sets the bootloader mode and returns the status after the requested mode change was instigated.void
setBufferConfig(int sendBufferSize, int receiveBufferSize)
Sets the send and receive buffer size in byte.void
setConfiguration(long baudrate, int parity, int stopbits, int wordlength, int flowcontrol)
Sets the configuration for the RS232 communication.void
setFrameReadableCallbackConfiguration(int frameSize)
Configures theBrickletRS232V2.FrameReadableListener
listener.void
setStatusLEDConfig(int config)
Sets the status LED configuration.void
setWriteFirmwarePointer(long pointer)
Sets the firmware pointer forwriteFirmware(int[])
.int
write(char[] message)
Writes characters to the RS232 interface.int
writeFirmware(int[] data)
Writes 64 Bytes of firmware at the position as written bysetWriteFirmwarePointer(long)
before.int
writeLowLevel(int messageLength, int messageChunkOffset, char[] messageChunkData)
Writes characters to the RS232 interface.void
writeUID(long uid)
Writes a new UID into flash.-
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_LOW_LEVEL
public static final byte FUNCTION_WRITE_LOW_LEVEL
- See Also:
- Constant Field Values
-
FUNCTION_READ_LOW_LEVEL
public static final byte FUNCTION_READ_LOW_LEVEL
- 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_BUFFER_CONFIG
public static final byte FUNCTION_SET_BUFFER_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_BUFFER_CONFIG
public static final byte FUNCTION_GET_BUFFER_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_BUFFER_STATUS
public static final byte FUNCTION_GET_BUFFER_STATUS
- See Also:
- Constant Field Values
-
FUNCTION_GET_ERROR_COUNT
public static final byte FUNCTION_GET_ERROR_COUNT
- 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_GET_SPITFP_ERROR_COUNT
public static final byte FUNCTION_GET_SPITFP_ERROR_COUNT
- See Also:
- Constant Field Values
-
FUNCTION_SET_BOOTLOADER_MODE
public static final byte FUNCTION_SET_BOOTLOADER_MODE
- See Also:
- Constant Field Values
-
FUNCTION_GET_BOOTLOADER_MODE
public static final byte FUNCTION_GET_BOOTLOADER_MODE
- See Also:
- Constant Field Values
-
FUNCTION_SET_WRITE_FIRMWARE_POINTER
public static final byte FUNCTION_SET_WRITE_FIRMWARE_POINTER
- See Also:
- Constant Field Values
-
FUNCTION_WRITE_FIRMWARE
public static final byte FUNCTION_WRITE_FIRMWARE
- See Also:
- Constant Field Values
-
FUNCTION_SET_STATUS_LED_CONFIG
public static final byte FUNCTION_SET_STATUS_LED_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_STATUS_LED_CONFIG
public static final byte FUNCTION_GET_STATUS_LED_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_CHIP_TEMPERATURE
public static final byte FUNCTION_GET_CHIP_TEMPERATURE
- See Also:
- Constant Field Values
-
FUNCTION_RESET
public static final byte FUNCTION_RESET
- See Also:
- Constant Field Values
-
FUNCTION_WRITE_UID
public static final byte FUNCTION_WRITE_UID
- See Also:
- Constant Field Values
-
FUNCTION_READ_UID
public static final byte FUNCTION_READ_UID
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
PARITY_NONE
public static final int PARITY_NONE
- See Also:
- Constant Field Values
-
PARITY_ODD
public static final int PARITY_ODD
- See Also:
- Constant Field Values
-
PARITY_EVEN
public static final int PARITY_EVEN
- See Also:
- Constant Field Values
-
STOPBITS_1
public static final int STOPBITS_1
- See Also:
- Constant Field Values
-
STOPBITS_2
public static final int STOPBITS_2
- See Also:
- Constant Field Values
-
WORDLENGTH_5
public static final int WORDLENGTH_5
- See Also:
- Constant Field Values
-
WORDLENGTH_6
public static final int WORDLENGTH_6
- See Also:
- Constant Field Values
-
WORDLENGTH_7
public static final int WORDLENGTH_7
- See Also:
- Constant Field Values
-
WORDLENGTH_8
public static final int WORDLENGTH_8
- See Also:
- Constant Field Values
-
FLOWCONTROL_OFF
public static final int FLOWCONTROL_OFF
- See Also:
- Constant Field Values
-
FLOWCONTROL_SOFTWARE
public static final int FLOWCONTROL_SOFTWARE
- See Also:
- Constant Field Values
-
FLOWCONTROL_HARDWARE
public static final int FLOWCONTROL_HARDWARE
- See Also:
- Constant Field Values
-
BOOTLOADER_MODE_BOOTLOADER
public static final int BOOTLOADER_MODE_BOOTLOADER
- See Also:
- Constant Field Values
-
BOOTLOADER_MODE_FIRMWARE
public static final int BOOTLOADER_MODE_FIRMWARE
- See Also:
- Constant Field Values
-
BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
public static final int BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
- See Also:
- Constant Field Values
-
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
public static final int BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
- See Also:
- Constant Field Values
-
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
public static final int BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_OK
public static final int BOOTLOADER_STATUS_OK
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_INVALID_MODE
public static final int BOOTLOADER_STATUS_INVALID_MODE
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_NO_CHANGE
public static final int BOOTLOADER_STATUS_NO_CHANGE
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
public static final int BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
public static final int BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
- See Also:
- Constant Field Values
-
BOOTLOADER_STATUS_CRC_MISMATCH
public static final int BOOTLOADER_STATUS_CRC_MISMATCH
- See Also:
- Constant Field Values
-
STATUS_LED_CONFIG_OFF
public static final int STATUS_LED_CONFIG_OFF
- See Also:
- Constant Field Values
-
STATUS_LED_CONFIG_ON
public static final int STATUS_LED_CONFIG_ON
- See Also:
- Constant Field Values
-
STATUS_LED_CONFIG_SHOW_HEARTBEAT
public static final int STATUS_LED_CONFIG_SHOW_HEARTBEAT
- See Also:
- Constant Field Values
-
STATUS_LED_CONFIG_SHOW_STATUS
public static final int STATUS_LED_CONFIG_SHOW_STATUS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletRS232V2
public BrickletRS232V2(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
-
writeLowLevel
public int writeLowLevel(int messageLength, int messageChunkOffset, char[] messageChunkData) throws TinkerforgeException
Writes characters to the RS232 interface. The characters can be binary data, ASCII or similar is not necessary. The return value is the number of characters that were written. SeesetConfiguration(long, int, int, int, int)
for configuration possibilities regarding baud rate, parity and so on.- Throws:
TinkerforgeException
-
readLowLevel
public BrickletRS232V2.ReadLowLevel readLowLevel(int length) throws TinkerforgeException
Returns up to *length* characters from receive buffer. Instead of polling with this function, you can also use callbacks. But note that this function will return available data only when the read listener is disabled. SeeenableReadCallback()
andBrickletRS232V2.ReadListener
listener.- Throws:
TinkerforgeException
-
enableReadCallback
public void enableReadCallback() throws TinkerforgeException
Enables theBrickletRS232V2.ReadListener
listener. This will disable theBrickletRS232V2.FrameReadableListener
listener. By default the listener is disabled.- Throws:
TinkerforgeException
-
disableReadCallback
public void disableReadCallback() throws TinkerforgeException
Disables theBrickletRS232V2.ReadListener
listener. By default the listener is disabled.- Throws:
TinkerforgeException
-
isReadCallbackEnabled
public boolean isReadCallbackEnabled() throws TinkerforgeException
Returns *true* if theBrickletRS232V2.ReadListener
listener is enabled, *false* otherwise.- Throws:
TinkerforgeException
-
setConfiguration
public void setConfiguration(long baudrate, int parity, int stopbits, int wordlength, int flowcontrol) throws TinkerforgeException
Sets the configuration for the RS232 communication.- Throws:
TinkerforgeException
-
getConfiguration
public BrickletRS232V2.Configuration getConfiguration() throws TinkerforgeException
Returns the configuration as set bysetConfiguration(long, int, int, int, int)
.- Throws:
TinkerforgeException
-
setBufferConfig
public void setBufferConfig(int sendBufferSize, int receiveBufferSize) throws TinkerforgeException
Sets the send and receive buffer size in byte. In total the buffers have to be 10240 byte (10KiB) in size, the minimum buffer size is 1024 byte (1KiB) for each. The current buffer content is lost if this function is called. The send buffer holds data that is given bywrite(char[])
and can not be written yet. The receive buffer holds data that is received through RS232 but could not yet be send to the user, either byread(int)
or throughBrickletRS232V2.ReadListener
listener.- Throws:
TinkerforgeException
-
getBufferConfig
public BrickletRS232V2.BufferConfig getBufferConfig() throws TinkerforgeException
Returns the buffer configuration as set bysetBufferConfig(int, int)
.- Throws:
TinkerforgeException
-
getBufferStatus
public BrickletRS232V2.BufferStatus getBufferStatus() throws TinkerforgeException
Returns the currently used bytes for the send and received buffer. SeesetBufferConfig(int, int)
for buffer size configuration.- Throws:
TinkerforgeException
-
getErrorCount
public BrickletRS232V2.ErrorCount getErrorCount() throws TinkerforgeException
Returns the current number of overrun and parity errors.- Throws:
TinkerforgeException
-
setFrameReadableCallbackConfiguration
public void setFrameReadableCallbackConfiguration(int frameSize) throws TinkerforgeException
Configures theBrickletRS232V2.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 theBrickletRS232V2.ReadListener
listener. By default the listener is disabled. .. versionadded:: 2.0.3$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getFrameReadableCallbackConfiguration
public int getFrameReadableCallbackConfiguration() throws TinkerforgeException
Returns the listener configuration as set bysetFrameReadableCallbackConfiguration(int)
. .. versionadded:: 2.0.3$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getSPITFPErrorCount
public BrickletRS232V2.SPITFPErrorCount getSPITFPErrorCount() throws TinkerforgeException
Returns the error count for the communication between Brick and Bricklet. The errors are divided into * ACK checksum errors, * message checksum errors, * framing errors and * overflow errors. The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.- Throws:
TinkerforgeException
-
setBootloaderMode
public int setBootloaderMode(int mode) throws TinkerforgeException
Sets the bootloader mode and returns the status after the requested mode change was instigated. You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct. This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.- Throws:
TinkerforgeException
-
getBootloaderMode
public int getBootloaderMode() throws TinkerforgeException
Returns the current bootloader mode, seesetBootloaderMode(int)
.- Throws:
TinkerforgeException
-
setWriteFirmwarePointer
public void setWriteFirmwarePointer(long pointer) throws TinkerforgeException
Sets the firmware pointer forwriteFirmware(int[])
. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256). This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.- Throws:
TinkerforgeException
-
writeFirmware
public int writeFirmware(int[] data) throws TinkerforgeException
Writes 64 Bytes of firmware at the position as written bysetWriteFirmwarePointer(long)
before. The firmware is written to flash every 4 chunks. You can only write firmware in bootloader mode. This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.- Throws:
TinkerforgeException
-
setStatusLEDConfig
public void setStatusLEDConfig(int config) throws TinkerforgeException
Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets. You can also turn the LED permanently on/off or show a heartbeat. If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.- Throws:
TinkerforgeException
-
getStatusLEDConfig
public int getStatusLEDConfig() throws TinkerforgeException
Returns the configuration as set bysetStatusLEDConfig(int)
- Throws:
TinkerforgeException
-
getChipTemperature
public int getChipTemperature() throws TinkerforgeException
Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature! The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.- Throws:
TinkerforgeException
-
reset
public void reset() throws TinkerforgeException
Calling this function will reset the Bricklet. All configurations will be lost. After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!- Throws:
TinkerforgeException
-
writeUID
public void writeUID(long uid) throws TinkerforgeException
Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first. We recommend that you use Brick Viewer to change the UID.- Throws:
TinkerforgeException
-
readUID
public long readUID() throws TinkerforgeException
Returns the current UID as an integer. Encode as Base58 to get the usual string version.- 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
-
write
public int write(char[] message) throws TinkerforgeException
Writes characters to the RS232 interface. The characters can be binary data, ASCII or similar is not necessary. The return value is the number of characters that were written. SeesetConfiguration(long, int, int, int, int)
for configuration possibilities regarding baud rate, parity and so on.- Throws:
TinkerforgeException
-
read
public char[] read(int length) throws TinkerforgeException
Returns up to *length* characters from receive buffer. Instead of polling with this function, you can also use callbacks. But note that this function will return available data only when the read listener is disabled. SeeenableReadCallback()
andBrickletRS232V2.ReadListener
listener.- Throws:
TinkerforgeException
-
addReadLowLevelListener
public void addReadLowLevelListener(BrickletRS232V2.ReadLowLevelListener listener)
Adds a ReadLowLevel listener.
-
removeReadLowLevelListener
public void removeReadLowLevelListener(BrickletRS232V2.ReadLowLevelListener listener)
Removes a ReadLowLevel listener.
-
addErrorCountListener
public void addErrorCountListener(BrickletRS232V2.ErrorCountListener listener)
Adds a ErrorCount listener.
-
removeErrorCountListener
public void removeErrorCountListener(BrickletRS232V2.ErrorCountListener listener)
Removes a ErrorCount listener.
-
addFrameReadableListener
public void addFrameReadableListener(BrickletRS232V2.FrameReadableListener listener)
Adds a FrameReadable listener.
-
removeFrameReadableListener
public void removeFrameReadableListener(BrickletRS232V2.FrameReadableListener listener)
Removes a FrameReadable listener.
-
addReadListener
public void addReadListener(BrickletRS232V2.ReadListener listener)
Adds a Read listener.
-
removeReadListener
public void removeReadListener(BrickletRS232V2.ReadListener listener)
Removes a Read listener.
-
-