openHAB - RS485 Bricklet

Warning

The openHAB bindings are still in beta, but the development was stopped.

This is the description of the openHAB API bindings for the RS485 Bricklet. General information and technical specifications for the RS485 Bricklet are summarized in its hardware description.

An installation guide for the openHAB API bindings is part of their general description.

Examples

The example code below is Public Domain (CC0 1.0).

Modbus Master

Download (ExampleModbusMaster.rules)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For this example configure your RS485 Bricklet to Modbus Master Mode in Paper UI.

rule "Read Modbus Registers"
when
    System started // Replace with trigger of your choice
then
    // Change XYZ to the UID of your NFC RFID Bricklet
    val rs = getActions("tinkerforge", "tinkerforge:brickletrs485:XYZ")
    
    // Read register 1281 and 1282 from slave 1.
    val result = rs.brickletRS485ModbusMasterReadInputRegisters(1, 1281, 2)
    
    if (!result.containsKey("exceptionCode")) {
        logInfo("Example", "Failed sending modbus request.")
        return
    }
    
    val exceptionCode = result.get("exceptionCode") as int
    if (exceptionCode != 0) {
        logInfo("Example", "Modbus device returned exception code " + exceptionCode)
        return
    }
    
    val inputRegisters = result.get("inputRegisters") as int[]
    
    logInfo("Example", "Register 1281: " + inputRegisters.get(0))
    logInfo("Example", "Register 1282: " + inputRegisters.get(1))
end

Thing

UID:
  • tinkerforge:brickletrs485:[UID]
Required firmware version:
  • 2.0.5
Firmware update supported:
  • yes
Channels:
Actions:
Parameters:
  • Mode – Type: Choice, Default: RS485
  • The mode of the Bricklet in which it operates.
  • Options: RS485, Modbus Master RTU

  • Baud Rate – Type: integer, Default: 115200, Min: 100, Max: 2000000
  • The baud rate to send/receive with.

  • Parity – Type: Choice, Default: None
  • The parity mode to use. See `here `__.
  • Options: None, Odd, Even

  • Stop Bits – Type: Choice, Default: 1
  • The number of stop bits to send/expect.
  • Options: 1, 2

  • Word Length – Type: Choice, Default: 8
  • The length of a serial word. Typically one byte.
  • Options: 5, 6, 7, 8

  • Duplex – Type: Choice, Default: Half
  • The flow control mechanism to use. Software uses control characters in-band. Hardware uses the RTS and CTS lines.
  • Options: Half, Full

  • Send Buffer Size – Type: integer, Default: 5120, Min: 1024, Max: 9216
  • The send buffer size in bytes. In total the send and receive buffers are 10240 byte (10 KiB) in size. The minimum buffer size is 1024 byte (1 KiB) each. The binding will configure the read buffer size accordingly. The send buffer holds data that is given by the user and can not be written to RS232 yet. The receive buffer holds data that is received through RS232 but could not yet be send to the user.

  • Frame Size – Type: integer, Default: 1, Min: 0, Max: 9216
  • The size of receivable data frames in bytes. Set this to something other than 1, if you want to receive data with a fix frame size. The frame readable channel will trigger every time a frame of this size is ready to be read, but will wait until this frame is read before triggering again. This means, you can use this channel as a trigger in a rule, that will read exactly one frame.

  • Request Timeout – Type: integer, Default: 1000, Min: 0, Max: 4294967295
  • Time in milliseconds that the master should wait for a response from a slave when in Modbus master mode.

  • Communication LED Configuration – Type: Choice, Default: Show Communication
  • By default the LED shows RS485 communication traffic by flickering. You can also turn the LED permanently on/off or show a heartbeat. If the Bricklet is in bootloader mode, the LED is off.
  • Options: Off, On, Show Heartbeat, Show Communication

  • Error LED Configuration – Type: Choice, Default: Show Error
  • By default the error LED turns on if there is any error (see FrameErrorCountListener callback). You can also turn the LED permanently on/off or show a heartbeat. If the Bricklet is in bootloader mode, the LED is off.
  • Options: Off, On, Show Heartbeat, Show Error

  • Status LED Configuration – Type: Choice, Default: Show Status
  • 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.
  • Options: Off, On, Show Heartbeat, Show Status

Channels

Frame Readable

This channel is triggered in when a new frame was received and can be read out. The channel will only trigger again if the frame was read.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485FrameReadable
Read only:
  • No
Overrun Error Count

The current number of overrun errors

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485OverrunErrorCount
Read only:
  • Yes
Parity Error Count

The current number of parity errors

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485ParityErrorCount
Read only:
  • Yes
Timeout Error Count

Number of timeouts occurred.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485TimeoutErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Checksum Error Count

Number of failures due to Modbus frame CRC16 checksum mismatch.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485ChecksumErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Frame Too Big Error Count

Number of times frames were rejected because they exceeded maximum Modbus frame size which is 256 bytes.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485FrameTooBigErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Illegal Function Error Count

Number of errors when an unimplemented or illegal function is requested. This corresponds to Modbus exception code 1.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485IllegalFunctionErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Illegal Data Address Error Count

Number of errors due to invalid data address. This corresponds to Modbus exception code 2.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485IllegalDataAddressErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Illegal Data Value Error Count

Number of errors due to invalid data value. This corresponds to Modbus exception code 3.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485IllegalDataValueErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Slave Device Failure Error Count

Number of errors occurred on the slave device which were unrecoverable. This corresponds to Modbus exception code 4.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485SlaveDeviceFailureErrorCount
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Modbus Master RTU.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Send Buffer Used

The number of bytes currently in the send buffer

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:DataAmount
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485SendBufferUsed
Read only:
  • Yes
Unit:
  • Byte
Range:
  • 0 Byte to 9216 Byte (Step 1 Byte)
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Receive Buffer Used

The number of bytes currently in the receive buffer

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:DataAmount
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485ReceiveBufferUsed
Read only:
  • Yes
Unit:
  • Byte
Range:
  • 0 Byte to 9216 Byte (Step 1 Byte)
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Clear Error LED

Clears the error LED.

Type:
  • Commands (String)
UID:
  • tinkerforge:brickletrs485:[UID]:BrickletRS485ClearErrorLED
Read only:
  • No
Predicate:
  • This channel will only be available if Error LED Configuration is Show Error.
Commands:
  • Accepts any string

Actions

Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:

val actions = getActions("tinkerforge", "tinkerforge:brickletrs485:[UID]")
val hwVersion = actions.brickletRS485GetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickletRS485Write(char[] message)
Parameters:
  • message – Type: char[], Length: variable
Return Map:
  • messageWritten – Type: int, Range: [0 to 216 - 1]

Writes characters to the RS485 interface. The characters can be binary data, ASCII or similar is not necessary.

The return value is the number of characters that were written.

See the thing configuration for configuration possibilities regarding baudrate, parity and so on.

brickletRS485Read(int length)
Parameters:
  • length – Type: int, Range: [0 to 216 - 1]
Return Map:
  • message – Type: char[], Length: variable

Returns up to length characters from receive buffer.

brickletRS485GetRS485Configuration()
Return Map:
  • baudrate – Type: long, Unit: 1 Bd, Range: [100 to 2000000], Default: 115200
  • parity – Type: int, Range: See constants, Default: 0
  • stopbits – Type: int, Range: See constants, Default: 1
  • wordlength – Type: int, Range: See constants, Default: 8
  • duplex – Type: int, Range: See constants, Default: 0

Returns the configuration as set by the thing configuration.

The following constants are available for this function:

For parity:

  • val PARITY_NONE = 0
  • val PARITY_ODD = 1
  • val PARITY_EVEN = 2

For stopbits:

  • val STOPBITS_1 = 1
  • val STOPBITS_2 = 2

For wordlength:

  • val WORDLENGTH_5 = 5
  • val WORDLENGTH_6 = 6
  • val WORDLENGTH_7 = 7
  • val WORDLENGTH_8 = 8

For duplex:

  • val DUPLEX_HALF = 0
  • val DUPLEX_FULL = 1
brickletRS485GetMode()
Return Map:
  • mode – Type: int, Range: See constants, Default: 0

Returns the configuration as set by the thing configuration.

The following constants are available for this function:

For mode:

  • val MODE_RS485 = 0
  • val MODE_MODBUS_MASTER_RTU = 1
  • val MODE_MODBUS_SLAVE_RTU = 2
brickletRS485GetModbusConfiguration()
Return Map:
  • slaveAddress – Type: int, Range: [1 to 247], Default: 1
  • masterRequestTimeout – Type: long, Unit: 1 ms, Range: [0 to 232 - 1], Default: 1000

Returns the configuration as set by the thing configuration.

Advanced Actions

brickletRS485GetCommunicationLEDConfig()
Return Map:
  • config – Type: int, Range: See constants, Default: 3

Returns the configuration as set by the thing configuration

The following constants are available for this function:

For config:

  • val COMMUNICATION_LED_CONFIG_OFF = 0
  • val COMMUNICATION_LED_CONFIG_ON = 1
  • val COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT = 2
  • val COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION = 3
brickletRS485GetErrorLEDConfig()
Return Map:
  • config – Type: int, Range: See constants, Default: 3

Returns the configuration as set by Clear Error LED.

The following constants are available for this function:

For config:

  • val ERROR_LED_CONFIG_OFF = 0
  • val ERROR_LED_CONFIG_ON = 1
  • val ERROR_LED_CONFIG_SHOW_HEARTBEAT = 2
  • val ERROR_LED_CONFIG_SHOW_ERROR = 3
brickletRS485GetBufferConfig()
Return Map:
  • sendBufferSize – Type: int, Unit: 1 B, Range: [210 to 9216], Default: 5120
  • receiveBufferSize – Type: int, Unit: 1 B, Range: [210 to 9216], Default: 5120

Returns the buffer configuration as set by the thing configuration.

brickletRS485GetBufferStatus()
Return Map:
  • sendBufferUsed – Type: int, Unit: 1 B, Range: [0 to 9216]
  • receiveBufferUsed – Type: int, Unit: 1 B, Range: [0 to 9216]

Returns the currently used bytes for the send and received buffer.

See the thing configuration for buffer size configuration.

brickletRS485GetErrorCount()
Return Map:
  • overrunErrorCount – Type: long, Range: [0 to 232 - 1]
  • parityErrorCount – Type: long, Range: [0 to 232 - 1]

Returns the current number of overrun and parity errors.

brickletRS485GetModbusCommonErrorCount()
Return Map:
  • timeoutErrorCount – Type: long, Range: [0 to 232 - 1]
  • checksumErrorCount – Type: long, Range: [0 to 232 - 1]
  • frameTooBigErrorCount – Type: long, Range: [0 to 232 - 1]
  • illegalFunctionErrorCount – Type: long, Range: [0 to 232 - 1]
  • illegalDataAddressErrorCount – Type: long, Range: [0 to 232 - 1]
  • illegalDataValueErrorCount – Type: long, Range: [0 to 232 - 1]
  • slaveDeviceFailureErrorCount – Type: long, Range: [0 to 232 - 1]

Returns the current number of errors occurred in Modbus mode.

  • Timeout Error Count: Number of timeouts occurred.
  • Checksum Error Count: Number of failures due to Modbus frame CRC16 checksum mismatch.
  • Frame Too Big Error Count: Number of times frames were rejected because they exceeded maximum Modbus frame size which is 256 bytes.
  • Illegal Function Error Count: Number of errors when an unimplemented or illegal function is requested. This corresponds to Modbus exception code 1.
  • Illegal Data Address Error Count: Number of errors due to invalid data address. This corresponds to Modbus exception code 2.
  • Illegal Data Value Error Count: Number of errors due to invalid data value. This corresponds to Modbus exception code 3.
  • Slave Device Failure Error Count: Number of errors occurred on the slave device which were unrecoverable. This corresponds to Modbus exception code 4.
brickletRS485ModbusMasterReadCoils(int slaveAddress, long startingAddress, int count)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • count – Type: int, Range: [1 to 2000]
Return Map:
  • exceptionCode – Type: int, Range: See constants
  • coils – Type: boolean[], Length: variable

In Modbus master mode this function can be used to read coils from a slave. This function creates a Modbus function code 1 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first coil to read. For backwards compatibility reasons this parameter is called Starting Address. It is not an address, but instead a coil number in the range of 1 to 65536.
  • Count: Number of coils to read.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response and the data as received by the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timed out or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterReadHoldingRegisters(int slaveAddress, long startingAddress, int count)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • count – Type: int, Range: [1 to 125]
Return Map:
  • exceptionCode – Type: int, Range: See constants
  • holdingRegisters – Type: int[], Length: variable, Range: [0 to 216 - 1]

In Modbus master mode this function can be used to read holding registers from a slave. This function creates a Modbus function code 3 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first holding register to read. For backwards compatibility reasons this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.
  • Count: Number of holding registers to read.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response and the data as received by the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timed out or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterWriteSingleCoil(int slaveAddress, long coilAddress, boolean coilValue)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • coilAddress – Type: long, Range: [1 to 216]
  • coilValue – Type: boolean
Return Map:
  • exceptionCode – Type: int, Range: See constants

In Modbus master mode this function can be used to write a single coil of a slave. This function creates a Modbus function code 5 request.

  • Slave Address: Address of the target Modbus slave.
  • Coil Address: Number of the coil to be written. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a coil number in the range of 1 to 65536.
  • Coil Value: Value to be written.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timed out or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterWriteSingleRegister(int slaveAddress, long registerAddress, int registerValue)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • registerAddress – Type: long, Range: [1 to 216]
  • registerValue – Type: int, Range: [0 to 216 - 1]
Return Map:
  • exceptionCode – Type: int, Range: See constants

In Modbus master mode this function can be used to write a single holding register of a slave. This function creates a Modbus function code 6 request.

  • Slave Address: Address of the target Modbus slave.
  • Register Address: Number of the holding register to be written. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.
  • Register Value: Value to be written.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timed out or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterWriteMultipleCoils(int slaveAddress, long startingAddress, boolean[] coils)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • coils – Type: boolean[], Length: variable
Return Map:
  • exceptionCode – Type: int, Range: See constants

In Modbus master mode this function can be used to write multiple coils of a slave. This function creates a Modbus function code 15 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first coil to write. For backwards compatibility reasons, this parameter is called Starting Address.It is not an address, but instead a coil number in the range of 1 to 65536.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timedout or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterWriteMultipleRegisters(int slaveAddress, long startingAddress, int[] registers)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • registers – Type: int[], Length: variable, Range: [0 to 216 - 1]
Return Map:
  • exceptionCode – Type: int, Range: See constants

In Modbus master mode this function can be used to write multiple registers of a slave. This function creates a Modbus function code 16 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first holding register to write. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timedout or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterReadDiscreteInputs(int slaveAddress, long startingAddress, int count)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • count – Type: int, Range: [1 to 2000]
Return Map:
  • exceptionCode – Type: int, Range: See constants
  • discreteInputs – Type: boolean[], Length: variable

In Modbus master mode this function can be used to read discrete inputs from a slave. This function creates a Modbus function code 2 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first discrete input to read. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a discrete input number in the range of 1 to 65536. The prefix digit 1 (for discrete input) is implicit and must be omitted.
  • Count: Number of discrete inputs to read.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response and the data as received by the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timedout or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485ModbusMasterReadInputRegisters(int slaveAddress, long startingAddress, int count)
Parameters:
  • slaveAddress – Type: int, Range: [0 to 247]
  • startingAddress – Type: long, Range: [1 to 216]
  • count – Type: int, Range: [1 to 125]
Return Map:
  • exceptionCode – Type: int, Range: See constants
  • inputRegisters – Type: int[], Length: variable, Range: [0 to 216 - 1]

In Modbus master mode this function can be used to read input registers from a slave. This function creates a Modbus function code 4 request.

  • Slave Address: Address of the target Modbus slave.
  • Starting Address: Number of the first input register to read. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead an input register number in the range of 1 to 65536. The prefix digit 3 (for input register) is implicit and must be omitted.
  • Count: Number of input registers to read.

If sending the request fails, the function will return an empty map.

Upon success the function will return the exception code of the response and the data as received by the response.

Any non-zero exception code indicates a problem. If the exception code is greater than 0 then the number represents a Modbus exception code. If it is less than 0 then it represents other errors. For example, -1 indicates that the request timedout or that the master did not receive any valid response of the request within the master request timeout period as set by the thing configuration.

The following constants are available for this function:

For exceptionCode:

  • val EXCEPTION_CODE_TIMEOUT = -1
  • val EXCEPTION_CODE_SUCCESS = 0
  • val EXCEPTION_CODE_ILLEGAL_FUNCTION = 1
  • val EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS = 2
  • val EXCEPTION_CODE_ILLEGAL_DATA_VALUE = 3
  • val EXCEPTION_CODE_SLAVE_DEVICE_FAILURE = 4
  • val EXCEPTION_CODE_ACKNOWLEDGE = 5
  • val EXCEPTION_CODE_SLAVE_DEVICE_BUSY = 6
  • val EXCEPTION_CODE_MEMORY_PARITY_ERROR = 8
  • val EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE = 10
  • val EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 11
brickletRS485GetChipTemperature()
Return Map:
  • temperature – Type: int, Unit: 1 °C, Range: [-215 to 215 - 1]

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.

brickletRS485GetStatusLEDConfig()
Return Map:
  • config – Type: int, Range: See constants, Default: 3

Returns the configuration as set by the thing configuration

The following constants are available for this function:

For config:

  • val STATUS_LED_CONFIG_OFF = 0
  • val STATUS_LED_CONFIG_ON = 1
  • val STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
  • val STATUS_LED_CONFIG_SHOW_STATUS = 3
brickletRS485GetSPITFPErrorCount()
Return Map:
  • errorCountAckChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountMessageChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountFrame – Type: long, Range: [0 to 232 - 1]
  • errorCountOverflow – Type: long, Range: [0 to 232 - 1]

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.

brickletRS485Reset()

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!

brickletRS485GetIdentity()
Return Map:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – Type: int, Range: [0 to 216 - 1]

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 Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here

Internal Actions

brickletRS485ReadUID()
Return Map:
  • uid – Type: long, Range: [0 to 232 - 1]

Returns the current UID as an integer. Encode as Base58 to get the usual string version.