public class BrickletCAN extends Device
Modifier and Type | Class and Description |
---|---|
class |
BrickletCAN.Configuration |
class |
BrickletCAN.ErrorLog |
static interface |
BrickletCAN.FrameReadableListener
This listener is triggered if a data or remote frame was received by the CAN
transceiver.
|
static interface |
BrickletCAN.FrameReadListener
This listener is triggered if a data or remote frame was received by the CAN
transceiver.
|
class |
BrickletCAN.ReadFilter |
class |
BrickletCAN.ReadFrame |
Device.Identity
Constructor and Description |
---|
BrickletCAN(java.lang.String uid,
IPConnection ipcon)
Creates an object with the unique device ID \c uid.
|
Modifier and Type | Method and Description |
---|---|
void |
addFrameReadableListener(BrickletCAN.FrameReadableListener listener)
Adds a FrameReadable listener.
|
void |
addFrameReadListener(BrickletCAN.FrameReadListener listener)
Adds a FrameRead listener.
|
void |
disableFrameReadCallback()
Disables the
BrickletCAN.FrameReadListener listener. |
void |
enableFrameReadCallback()
Enables the
BrickletCAN.FrameReadListener listener. |
BrickletCAN.Configuration |
getConfiguration()
Returns the configuration as set by
setConfiguration(short, short, int) . |
BrickletCAN.ErrorLog |
getErrorLog()
Returns information about different kinds of errors.
|
boolean |
getFrameReadableCallbackConfiguration()
Returns *true* if the
BrickletCAN.FrameReadableListener listener is enabled, *false* otherwise. |
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.
|
BrickletCAN.ReadFilter |
getReadFilter()
Returns the read filter as set by
setReadFilter(short, long, long, long) . |
boolean |
isFrameReadCallbackEnabled()
Returns *true* if the
BrickletCAN.FrameReadListener listener is enabled, *false* otherwise. |
BrickletCAN.ReadFrame |
readFrame()
Tries to read the next data or remote frame from the read buffer and return it.
|
void |
removeFrameReadableListener(BrickletCAN.FrameReadableListener listener)
Removes a FrameReadable listener.
|
void |
removeFrameReadListener(BrickletCAN.FrameReadListener listener)
Removes a FrameRead listener.
|
void |
setConfiguration(short baudRate,
short transceiverMode,
int writeTimeout)
Sets the configuration for the CAN bus communication.
|
void |
setFrameReadableCallbackConfiguration(boolean enabled)
Enables/disables the
BrickletCAN.FrameReadableListener listener. |
void |
setReadFilter(short mode,
long mask,
long filter1,
long filter2)
Set the read filter configuration.
|
boolean |
writeFrame(short frameType,
long identifier,
short[] data,
short length)
Writes a data or remote frame to the write buffer to be transmitted over the
CAN transceiver.
|
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
public static final int DEVICE_IDENTIFIER
public static final java.lang.String DEVICE_DISPLAY_NAME
public static final byte FUNCTION_WRITE_FRAME
public static final byte FUNCTION_READ_FRAME
public static final byte FUNCTION_ENABLE_FRAME_READ_CALLBACK
public static final byte FUNCTION_DISABLE_FRAME_READ_CALLBACK
public static final byte FUNCTION_IS_FRAME_READ_CALLBACK_ENABLED
public static final byte FUNCTION_SET_CONFIGURATION
public static final byte FUNCTION_GET_CONFIGURATION
public static final byte FUNCTION_SET_READ_FILTER
public static final byte FUNCTION_GET_READ_FILTER
public static final byte FUNCTION_GET_ERROR_LOG
public static final byte FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION
public static final byte FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION
public static final byte FUNCTION_GET_IDENTITY
public static final short FRAME_TYPE_STANDARD_DATA
public static final short FRAME_TYPE_STANDARD_REMOTE
public static final short FRAME_TYPE_EXTENDED_DATA
public static final short FRAME_TYPE_EXTENDED_REMOTE
public static final short BAUD_RATE_10KBPS
public static final short BAUD_RATE_20KBPS
public static final short BAUD_RATE_50KBPS
public static final short BAUD_RATE_125KBPS
public static final short BAUD_RATE_250KBPS
public static final short BAUD_RATE_500KBPS
public static final short BAUD_RATE_800KBPS
public static final short BAUD_RATE_1000KBPS
public static final short TRANSCEIVER_MODE_NORMAL
public static final short TRANSCEIVER_MODE_LOOPBACK
public static final short TRANSCEIVER_MODE_READ_ONLY
public static final short FILTER_MODE_DISABLED
public static final short FILTER_MODE_ACCEPT_ALL
public static final short FILTER_MODE_MATCH_STANDARD
public static final short FILTER_MODE_MATCH_STANDARD_AND_DATA
public static final short FILTER_MODE_MATCH_EXTENDED
public BrickletCAN(java.lang.String uid, IPConnection ipcon)
public boolean writeFrame(short frameType, long identifier, short[] data, short length) throws TinkerforgeException
setConfiguration(short, short, int)
). It can also happen if the CAN bus is
congested and the frame cannot be transmitted because it constantly loses
arbitration or because the CAN transceiver is currently disabled due to a high
write error level (see getErrorLog()
).TinkerforgeException
public BrickletCAN.ReadFrame readFrame() throws TinkerforgeException
writeFrame(short, long, short[], short)
.
For remote frames the ``data`` return value always contains invalid data.
A configurable read filter can be used to define which frames should be
received by the CAN transceiver and put into the read buffer (see
setReadFilter(short, long, long, long)
).
Instead of polling with this function, you can also use listeners. See the
enableFrameReadCallback()
function and the BrickletCAN.FrameReadListener
listener.TinkerforgeException
public void enableFrameReadCallback() throws TinkerforgeException
BrickletCAN.FrameReadListener
listener.
By default the listener is disabled. Enabling this listener will disable the BrickletCAN.FrameReadableListener
listener.TinkerforgeException
public void disableFrameReadCallback() throws TinkerforgeException
BrickletCAN.FrameReadListener
listener.
By default the listener is disabled.TinkerforgeException
public boolean isFrameReadCallbackEnabled() throws TinkerforgeException
BrickletCAN.FrameReadListener
listener is enabled, *false* otherwise.TinkerforgeException
public void setConfiguration(short baudRate, short transceiverMode, int writeTimeout) throws TinkerforgeException
TinkerforgeException
public BrickletCAN.Configuration getConfiguration() throws TinkerforgeException
setConfiguration(short, short, int)
.TinkerforgeException
public void setReadFilter(short mode, long mask, long filter1, long filter2) throws TinkerforgeException
TinkerforgeException
public BrickletCAN.ReadFilter getReadFilter() throws TinkerforgeException
setReadFilter(short, long, long, long)
.TinkerforgeException
public BrickletCAN.ErrorLog getErrorLog() throws TinkerforgeException
setConfiguration(short, short, int)
) and are reset to 0 as a side effect of changing
the configuration or the read filter.
The write timeout, read register and buffer overflow counts represents the
number of these errors:
* A write timeout occurs if a frame could not be transmitted before the
configured write timeout expired (see setConfiguration(short, short, int)
).
* A read register overflow occurs if the read register of the CAN transceiver
still contains the last received frame when the next frame arrives. In this
case the newly arrived frame is lost. This happens if the CAN transceiver
receives more frames than the Bricklet can handle. Using the read filter
(see setReadFilter(short, long, long, long)
) can help to reduce the amount of received frames.
This count is not exact, but a lower bound, because the Bricklet might not
able detect all overflows if they occur in rapid succession.
* A read buffer overflow occurs if the read buffer of the Bricklet is already
full when the next frame should be read from the read register of the CAN
transceiver. In this case the frame in the read register is lost. This
happens if the CAN transceiver receives more frames to be added to the read
buffer than are removed from the read buffer using the readFrame()
function. Using the BrickletCAN.FrameReadListener
listener ensures that the read buffer
can not overflow.TinkerforgeException
public void setFrameReadableCallbackConfiguration(boolean enabled) throws TinkerforgeException
BrickletCAN.FrameReadableListener
listener.
By default the listener is disabled. Enabling this listener will disable the BrickletCAN.FrameReadListener
listener.
.. versionadded:: 2.0.1$nbsp;(Plugin)TinkerforgeException
public boolean getFrameReadableCallbackConfiguration() throws TinkerforgeException
BrickletCAN.FrameReadableListener
listener is enabled, *false* otherwise.
.. versionadded:: 2.0.1$nbsp;(Plugin)TinkerforgeException
public Device.Identity getIdentity() throws TinkerforgeException
getIdentity
in class Device
TinkerforgeException
public void addFrameReadListener(BrickletCAN.FrameReadListener listener)
public void removeFrameReadListener(BrickletCAN.FrameReadListener listener)
public void addFrameReadableListener(BrickletCAN.FrameReadableListener listener)
public void removeFrameReadableListener(BrickletCAN.FrameReadableListener listener)
Copyright © 2021 Tinkerforge GmbH. All rights reserved.