class Tinkerforge::BrickletRS485
Communicates with RS485/Modbus devices with full- or half-duplex
Constants
- CALLBACK_ERROR_COUNT
This callback is called if a new error occurs. It returns the current overrun and parity error count.
- CALLBACK_FRAME_READABLE
This callback is called if at least one frame of data is readable. The frame size is configured with
BrickletRS485#set_frame_readable_callback_configuration
. The frame count parameter is the number of frames that can be read. This callback is triggered only once untilBrickletRS485#read
is called. This means, that if you have configured a frame size of X bytes, you can read exactly X bytes using theBrickletRS485#read
function, every time the callback triggers without checking the frame count parameter.- .. versionadded
-
2.0.5$nbsp;(Plugin)
- CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to read coils.
The parameters are request ID of the request, 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
BrickletRS485#set_modbus_configuration
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for coils.
- CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE_LOW_LEVEL
- CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to read discrete inputs.
The parameters are request ID of the request, 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
BrickletRS485#set_modbus_configuration
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for discrete_inputs.
- CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE_LOW_LEVEL
- CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to read holding registers.
The parameters are request ID of the request, 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
BrickletRS485#set_modbus_configuration
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for holding_registers.
- CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE_LOW_LEVEL
- CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to read input registers.
The parameters are request ID of the request, 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
BrickletRS485#set_modbus_configuration
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for input_registers.
- CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE_LOW_LEVEL
- CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_COILS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to read coils.
The parameters are request ID of the request and 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
BrickletRS485#set_modbus_configuration
.- CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to write multiple registers.
The parameters are request ID of the request and 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
BrickletRS485#set_modbus_configuration
.- CALLBACK_MODBUS_MASTER_WRITE_SINGLE_COIL_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to write a single coil.
The parameters are request ID of the request and 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
BrickletRS485#set_modbus_configuration
.- CALLBACK_MODBUS_MASTER_WRITE_SINGLE_REGISTER_RESPONSE
This callback is called only in Modbus master mode when the master receives a valid response of a request to write a single register.
The parameters are request ID of the request and 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
BrickletRS485#set_modbus_configuration
.- CALLBACK_MODBUS_SLAVE_READ_COILS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to read coils. The parameters are request ID of the request, the number of the first coil to be read and the number of coils to be read as received by the request. The number of the first coil is called starting address for backwards compatibility reasons. It is not an address, but instead a coil number in the range of 1 to 65536.
To send a response of this request use
BrickletRS485#modbus_slave_answer_read_coils_request
.- CALLBACK_MODBUS_SLAVE_READ_DISCRETE_INPUTS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to read discrete inputs. The parameters are request ID of the request, the number of the first discrete input and the number of discrete inputs to be read as received by the request. The number of the first discrete input is called starting address for backwards compatibility reasons. 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 omitted.
To send a response of this request use
BrickletRS485#modbus_slave_answer_read_discrete_inputs_request
.- CALLBACK_MODBUS_SLAVE_READ_HOLDING_REGISTERS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to read holding registers. The parameters are request ID of the request, the number of the first holding register to be read and the number of holding registers to be read as received by the request. The number of the first holding register is called starting address for backwards compatibility reasons. 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 omitted.
To send a response of this request use
BrickletRS485#modbus_slave_answer_read_holding_registers_request
.- CALLBACK_MODBUS_SLAVE_READ_INPUT_REGISTERS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to read input registers. The parameters are request ID of the request, the number of the first input register and the number of input registers to be read as received by the request. The number of the first input register is called starting address for backwards compatibility reasons. It is not an address, but instead a input register number in the range of 1 to 65536. The prefix digit 3 (for input register) is omitted.
To send a response of this request use
BrickletRS485#modbus_slave_answer_read_input_registers_request
.- CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to write multiple coils. The parameters are request ID of the request, the number of the first coil and the data to be written as received by the request. The number of the first coil is called starting address for backwards compatibility reasons. It is not an address, but instead a coil number in the range of 1 to 65536.
To send a response of this request use
BrickletRS485#modbus_slave_answer_write_multiple_coils_request
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for coils.
- CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST_LOW_LEVEL
- CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to write multiple holding registers. The parameters are request ID of the request, the number of the first holding register and the data to be written as received by the request. The number of the first holding register is called starting address for backwards compatibility reasons. 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 omitted.
To send a response of this request use
BrickletRS485#modbus_slave_answer_write_multiple_registers_request
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for registers.
- CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST_LOW_LEVEL
- CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_COIL_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to write a single coil. The parameters are request ID of the request, the number of the coil and the value of coil to be written as received by the request. The number of the coil is called coil address for backwards compatibility reasons. It is not an address, but instead a coil number in the range of 1 to 65536.
To send a response of this request use
BrickletRS485#modbus_slave_answer_write_single_coil_request
.- CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_REGISTER_REQUEST
This callback is called only in Modbus slave mode when the slave receives a valid request from a Modbus master to write a single holding register. The parameters are request ID of the request, the number of the holding register and the register value to be written as received by the request. The number of the holding register is called starting address for backwards compatibility reasons. 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 omitted.
To send a response of this request use
BrickletRS485#modbus_slave_answer_write_single_register_request
.- CALLBACK_READ
This callback is called if new data is available.
To enable this callback, use
BrickletRS485#enable_read_callback
.- .. note
-
If reconstructing the value fails, the callback is triggered with nil for message.
- CALLBACK_READ_LOW_LEVEL
See
CALLBACK_READ
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_rs485.rb, line 372 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_WRITE_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_READ_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_ENABLE_READ_CALLBACK] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_DISABLE_READ_CALLBACK] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_IS_READ_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_RS485_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_RS485_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MODBUS_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MODBUS_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MODE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_COMMUNICATION_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_COMMUNICATION_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_BUFFER_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_BUFFER_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_BUFFER_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_ENABLE_ERROR_COUNT_CALLBACK] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_DISABLE_ERROR_COUNT_CALLBACK] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_IS_ERROR_COUNT_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_MODBUS_COMMON_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_REPORT_EXCEPTION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_READ_COILS_REQUEST_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_MODBUS_MASTER_READ_COILS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_READ_HOLDING_REGISTERS_REQUEST_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_MODBUS_MASTER_READ_HOLDING_REGISTERS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_COIL_REQUEST] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_MODBUS_MASTER_WRITE_SINGLE_COIL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_REGISTER_REQUEST] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_MODBUS_MASTER_WRITE_SINGLE_REGISTER] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_COILS_REQUEST] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_COILS_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_REGISTERS_REQUEST] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_READ_DISCRETE_INPUTS_REQUEST_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_MODBUS_MASTER_READ_DISCRETE_INPUTS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_MODBUS_SLAVE_ANSWER_READ_INPUT_REGISTERS_REQUEST_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_MODBUS_MASTER_READ_INPUT_REGISTERS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_READ_LOW_LEVEL] = [72, 'S S k60'] @callback_formats[CALLBACK_ERROR_COUNT] = [16, 'L L'] @callback_formats[CALLBACK_MODBUS_SLAVE_READ_COILS_REQUEST] = [15, 'C L S'] @callback_formats[CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE_LOW_LEVEL] = [72, 'C c S S ?464'] @callback_formats[CALLBACK_MODBUS_SLAVE_READ_HOLDING_REGISTERS_REQUEST] = [15, 'C L S'] @callback_formats[CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE_LOW_LEVEL] = [72, 'C c S S S29'] @callback_formats[CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_COIL_REQUEST] = [14, 'C L ?'] @callback_formats[CALLBACK_MODBUS_MASTER_WRITE_SINGLE_COIL_RESPONSE] = [10, 'C c'] @callback_formats[CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_REGISTER_REQUEST] = [15, 'C L S'] @callback_formats[CALLBACK_MODBUS_MASTER_WRITE_SINGLE_REGISTER_RESPONSE] = [10, 'C c'] @callback_formats[CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST_LOW_LEVEL] = [72, 'C L S S ?440'] @callback_formats[CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_COILS_RESPONSE] = [10, 'C c'] @callback_formats[CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST_LOW_LEVEL] = [71, 'C L S S S27'] @callback_formats[CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_RESPONSE] = [10, 'C c'] @callback_formats[CALLBACK_MODBUS_SLAVE_READ_DISCRETE_INPUTS_REQUEST] = [15, 'C L S'] @callback_formats[CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE_LOW_LEVEL] = [72, 'C c S S ?464'] @callback_formats[CALLBACK_MODBUS_SLAVE_READ_INPUT_REGISTERS_REQUEST] = [15, 'C L S'] @callback_formats[CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE_LOW_LEVEL] = [72, 'C c S S S29'] @callback_formats[CALLBACK_FRAME_READABLE] = [10, 'S'] @high_level_callbacks[CALLBACK_READ] = [['stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @high_level_callbacks[CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE] = [[nil, nil, 'stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil] @ipcon.add_device self end
Public Instance Methods
Disables the CALLBACK_ERROR_COUNT
callback.
By default the callback is disabled.
# File lib/tinkerforge/bricklet_rs485.rb, line 647 def disable_error_count_callback check_validity send_request FUNCTION_DISABLE_ERROR_COUNT_CALLBACK, [], '', 8, '' end
Disables the CALLBACK_READ
callback.
By default the callback is disabled.
# File lib/tinkerforge/bricklet_rs485.rb, line 499 def disable_read_callback check_validity send_request FUNCTION_DISABLE_READ_CALLBACK, [], '', 8, '' end
Enables the CALLBACK_ERROR_COUNT
callback.
By default the callback is disabled.
# File lib/tinkerforge/bricklet_rs485.rb, line 638 def enable_error_count_callback check_validity send_request FUNCTION_ENABLE_ERROR_COUNT_CALLBACK, [], '', 8, '' end
Enables the CALLBACK_READ
callback. This will disable the CALLBACK_FRAME_READABLE
callback.
By default the callback is disabled.
# File lib/tinkerforge/bricklet_rs485.rb, line 490 def enable_read_callback check_validity send_request FUNCTION_ENABLE_READ_CALLBACK, [], '', 8, '' end
Returns the current bootloader mode, see BrickletRS485#set_bootloader_mode
.
# File lib/tinkerforge/bricklet_rs485.rb, line 1023 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end
Returns the buffer configuration as set by BrickletRS485#set_buffer_config
.
# File lib/tinkerforge/bricklet_rs485.rb, line 620 def get_buffer_config check_validity send_request FUNCTION_GET_BUFFER_CONFIG, [], '', 12, 'S S' end
Returns the currently used bytes for the send and received buffer.
See BrickletRS485#set_buffer_config
for buffer size configuration.
# File lib/tinkerforge/bricklet_rs485.rb, line 629 def get_buffer_status check_validity send_request FUNCTION_GET_BUFFER_STATUS, [], '', 12, 'S S' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1081 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end
Returns the configuration as set by BrickletRS485#set_communication_led_config
# File lib/tinkerforge/bricklet_rs485.rb, line 575 def get_communication_led_config check_validity send_request FUNCTION_GET_COMMUNICATION_LED_CONFIG, [], '', 9, 'C' end
Returns the current number of overrun and parity errors.
# File lib/tinkerforge/bricklet_rs485.rb, line 662 def get_error_count check_validity send_request FUNCTION_GET_ERROR_COUNT, [], '', 16, 'L L' end
Returns the configuration as set by BrickletRS485#set_error_led_config
.
# File lib/tinkerforge/bricklet_rs485.rb, line 597 def get_error_led_config check_validity send_request FUNCTION_GET_ERROR_LED_CONFIG, [], '', 9, 'C' end
Returns the callback configuration as set by BrickletRS485#set_frame_readable_callback_configuration
.
- .. versionadded
-
2.0.5$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_rs485.rb, line 984 def get_frame_readable_callback_configuration check_validity send_request FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION, [], '', 10, 'S' end
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|
# File lib/tinkerforge/bricklet_rs485.rb, line 1128 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 677 def get_modbus_common_error_count check_validity send_request FUNCTION_GET_MODBUS_COMMON_ERROR_COUNT, [], '', 36, 'L L L L L L L' end
Returns the configuration as set by BrickletRS485#set_modbus_configuration
.
# File lib/tinkerforge/bricklet_rs485.rb, line 538 def get_modbus_configuration check_validity send_request FUNCTION_GET_MODBUS_CONFIGURATION, [], '', 13, 'C L' end
Returns the configuration as set by BrickletRS485#set_mode
.
# File lib/tinkerforge/bricklet_rs485.rb, line 556 def get_mode check_validity send_request FUNCTION_GET_MODE, [], '', 9, 'C' end
Returns the configuration as set by BrickletRS485#set_rs485_configuration
.
# File lib/tinkerforge/bricklet_rs485.rb, line 521 def get_rs485_configuration check_validity send_request FUNCTION_GET_RS485_CONFIGURATION, [], '', 16, 'L C C C C' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1001 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end
Returns the configuration as set by BrickletRS485#set_status_led_config
# File lib/tinkerforge/bricklet_rs485.rb, line 1069 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end
Returns true if the CALLBACK_ERROR_COUNT
callback is enabled, false otherwise.
# File lib/tinkerforge/bricklet_rs485.rb, line 655 def is_error_count_callback_enabled check_validity send_request FUNCTION_IS_ERROR_COUNT_CALLBACK_ENABLED, [], '', 9, '?' end
Returns true if the CALLBACK_READ
callback is enabled, false otherwise.
# File lib/tinkerforge/bricklet_rs485.rb, line 507 def is_read_callback_enabled check_validity send_request FUNCTION_IS_READ_CALLBACK_ENABLED, [], '', 9, '?' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 723 def modbus_master_read_coils(slave_address, starting_address, count) check_validity send_request FUNCTION_MODBUS_MASTER_READ_COILS, [slave_address, starting_address, count], 'C L S', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 928 def modbus_master_read_discrete_inputs(slave_address, starting_address, count) check_validity send_request FUNCTION_MODBUS_MASTER_READ_DISCRETE_INPUTS, [slave_address, starting_address, count], 'C L S', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 758 def modbus_master_read_holding_registers(slave_address, starting_address, count) check_validity send_request FUNCTION_MODBUS_MASTER_READ_HOLDING_REGISTERS, [slave_address, starting_address, count], 'C L S', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 963 def modbus_master_read_input_registers(slave_address, starting_address, count) check_validity send_request FUNCTION_MODBUS_MASTER_READ_INPUT_REGISTERS, [slave_address, starting_address, count], 'C L S', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_COILS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 1308 def modbus_master_write_multiple_coils(slave_address, starting_address, coils) if coils.length > 65535 raise ArgumentError, 'Coils can be at most 65535 items long' end coils_length = coils.length coils_chunk_offset = 0 if coils_length == 0 coils_chunk_data = [false] * 440 ret = modbus_master_write_multiple_coils_low_level slave_address, starting_address, coils_length, coils_chunk_offset, coils_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while coils_chunk_offset < coils_length coils_chunk_data = coils[coils_chunk_offset, 440] if coils_chunk_data.length < 440 coils_chunk_data += [false] * (440 - coils_chunk_data.length) end ret = modbus_master_write_multiple_coils_low_level slave_address, starting_address, coils_length, coils_chunk_offset, coils_chunk_data coils_chunk_offset += 440 end } end ret end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_COILS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 860 def modbus_master_write_multiple_coils_low_level(slave_address, starting_address, coils_length, coils_chunk_offset, coils_chunk_data) check_validity send_request FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_COILS_LOW_LEVEL, [slave_address, starting_address, coils_length, coils_chunk_offset, coils_chunk_data], 'C L S S ?440', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 1353 def modbus_master_write_multiple_registers(slave_address, starting_address, registers) if registers.length > 65535 raise ArgumentError, 'Registers can be at most 65535 items long' end registers_length = registers.length registers_chunk_offset = 0 if registers_length == 0 registers_chunk_data = [0] * 27 ret = modbus_master_write_multiple_registers_low_level slave_address, starting_address, registers_length, registers_chunk_offset, registers_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while registers_chunk_offset < registers_length registers_chunk_data = registers[registers_chunk_offset, 27] if registers_chunk_data.length < 27 registers_chunk_data += [0] * (27 - registers_chunk_data.length) end ret = modbus_master_write_multiple_registers_low_level slave_address, starting_address, registers_length, registers_chunk_offset, registers_chunk_data registers_chunk_offset += 27 end } end ret end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 893 def modbus_master_write_multiple_registers_low_level(slave_address, starting_address, registers_length, registers_chunk_offset, registers_chunk_data) check_validity send_request FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_LOW_LEVEL, [slave_address, starting_address, registers_length, registers_chunk_offset, registers_chunk_data], 'C L S S S27', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_SINGLE_COIL_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 792 def modbus_master_write_single_coil(slave_address, coil_address, coil_value) check_validity send_request FUNCTION_MODBUS_MASTER_WRITE_SINGLE_COIL, [slave_address, coil_address, coil_value], 'C L ?', 9, 'C' end
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.
Upon success the function will return a non-zero request ID which will represent the current request initiated by the Modbus master. In case of failure the returned request ID will be 0.
When successful this function will also invoke the CALLBACK_MODBUS_MASTER_WRITE_SINGLE_REGISTER_RESPONSE
callback. In this callback the Request ID provided by the callback argument must be matched with the Request ID returned from this function to verify that the callback is indeed for a particular request.
# File lib/tinkerforge/bricklet_rs485.rb, line 827 def modbus_master_write_single_register(slave_address, register_address, register_value) check_validity send_request FUNCTION_MODBUS_MASTER_WRITE_SINGLE_REGISTER, [slave_address, register_address, register_value], 'C L S', 9, 'C' end
In Modbus slave mode this function can be used to answer a master request to read coils.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Coils: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_COILS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 1224 def modbus_slave_answer_read_coils_request(request_id, coils) if coils.length > 65535 raise ArgumentError, 'Coils can be at most 65535 items long' end coils_length = coils.length coils_chunk_offset = 0 if coils_length == 0 coils_chunk_data = [false] * 472 ret = modbus_slave_answer_read_coils_request_low_level request_id, coils_length, coils_chunk_offset, coils_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while coils_chunk_offset < coils_length coils_chunk_data = coils[coils_chunk_offset, 472] if coils_chunk_data.length < 472 coils_chunk_data += [false] * (472 - coils_chunk_data.length) end ret = modbus_slave_answer_read_coils_request_low_level request_id, coils_length, coils_chunk_offset, coils_chunk_data coils_chunk_offset += 472 end } end ret end
In Modbus slave mode this function can be used to answer a master request to read coils.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Coils: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_COILS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 702 def modbus_slave_answer_read_coils_request_low_level(request_id, coils_length, coils_chunk_offset, coils_chunk_data) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_READ_COILS_REQUEST_LOW_LEVEL, [request_id, coils_length, coils_chunk_offset, coils_chunk_data], 'C S S ?472', 8, '' end
In Modbus slave mode this function can be used to answer a master request to read discrete inputs.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Discrete Inputs: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_DISCRETE_INPUTS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 1392 def modbus_slave_answer_read_discrete_inputs_request(request_id, discrete_inputs) if discrete_inputs.length > 65535 raise ArgumentError, 'Discrete Inputs can be at most 65535 items long' end discrete_inputs_length = discrete_inputs.length discrete_inputs_chunk_offset = 0 if discrete_inputs_length == 0 discrete_inputs_chunk_data = [false] * 472 ret = modbus_slave_answer_read_discrete_inputs_request_low_level request_id, discrete_inputs_length, discrete_inputs_chunk_offset, discrete_inputs_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while discrete_inputs_chunk_offset < discrete_inputs_length discrete_inputs_chunk_data = discrete_inputs[discrete_inputs_chunk_offset, 472] if discrete_inputs_chunk_data.length < 472 discrete_inputs_chunk_data += [false] * (472 - discrete_inputs_chunk_data.length) end ret = modbus_slave_answer_read_discrete_inputs_request_low_level request_id, discrete_inputs_length, discrete_inputs_chunk_offset, discrete_inputs_chunk_data discrete_inputs_chunk_offset += 472 end } end ret end
In Modbus slave mode this function can be used to answer a master request to read discrete inputs.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Discrete Inputs: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_DISCRETE_INPUTS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 907 def modbus_slave_answer_read_discrete_inputs_request_low_level(request_id, discrete_inputs_length, discrete_inputs_chunk_offset, discrete_inputs_chunk_data) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_READ_DISCRETE_INPUTS_REQUEST_LOW_LEVEL, [request_id, discrete_inputs_length, discrete_inputs_chunk_offset, discrete_inputs_chunk_data], 'C S S ?472', 8, '' end
In Modbus slave mode this function can be used to answer a master request to read holding registers.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Holding Registers: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_HOLDING_REGISTERS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 1263 def modbus_slave_answer_read_holding_registers_request(request_id, holding_registers) if holding_registers.length > 65535 raise ArgumentError, 'Holding Registers can be at most 65535 items long' end holding_registers_length = holding_registers.length holding_registers_chunk_offset = 0 if holding_registers_length == 0 holding_registers_chunk_data = [0] * 29 ret = modbus_slave_answer_read_holding_registers_request_low_level request_id, holding_registers_length, holding_registers_chunk_offset, holding_registers_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while holding_registers_chunk_offset < holding_registers_length holding_registers_chunk_data = holding_registers[holding_registers_chunk_offset, 29] if holding_registers_chunk_data.length < 29 holding_registers_chunk_data += [0] * (29 - holding_registers_chunk_data.length) end ret = modbus_slave_answer_read_holding_registers_request_low_level request_id, holding_registers_length, holding_registers_chunk_offset, holding_registers_chunk_data holding_registers_chunk_offset += 29 end } end ret end
In Modbus slave mode this function can be used to answer a master request to read holding registers.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Holding Registers: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_HOLDING_REGISTERS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 737 def modbus_slave_answer_read_holding_registers_request_low_level(request_id, holding_registers_length, holding_registers_chunk_offset, holding_registers_chunk_data) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_READ_HOLDING_REGISTERS_REQUEST_LOW_LEVEL, [request_id, holding_registers_length, holding_registers_chunk_offset, holding_registers_chunk_data], 'C S S S29', 8, '' end
In Modbus slave mode this function can be used to answer a master request to read input registers.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Input Registers: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_INPUT_REGISTERS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 1431 def modbus_slave_answer_read_input_registers_request(request_id, input_registers) if input_registers.length > 65535 raise ArgumentError, 'Input Registers can be at most 65535 items long' end input_registers_length = input_registers.length input_registers_chunk_offset = 0 if input_registers_length == 0 input_registers_chunk_data = [0] * 29 ret = modbus_slave_answer_read_input_registers_request_low_level request_id, input_registers_length, input_registers_chunk_offset, input_registers_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while input_registers_chunk_offset < input_registers_length input_registers_chunk_data = input_registers[input_registers_chunk_offset, 29] if input_registers_chunk_data.length < 29 input_registers_chunk_data += [0] * (29 - input_registers_chunk_data.length) end ret = modbus_slave_answer_read_input_registers_request_low_level request_id, input_registers_length, input_registers_chunk_offset, input_registers_chunk_data input_registers_chunk_offset += 29 end } end ret end
In Modbus slave mode this function can be used to answer a master request to read input registers.
-
Request ID: Request ID of the corresponding request that is being answered.
-
Input Registers: Data that is to be sent to the Modbus master for the corresponding request.
This function must be called from the CALLBACK_MODBUS_SLAVE_READ_INPUT_REGISTERS_REQUEST
callback with the Request ID as provided by the argument of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 942 def modbus_slave_answer_read_input_registers_request_low_level(request_id, input_registers_length, input_registers_chunk_offset, input_registers_chunk_data) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_READ_INPUT_REGISTERS_REQUEST_LOW_LEVEL, [request_id, input_registers_length, input_registers_chunk_offset, input_registers_chunk_data], 'C S S S29', 8, '' end
In Modbus slave mode this function can be used to answer a master request to write multiple coils.
-
Request ID: Request ID of the corresponding request that is being answered.
This function must be called from the CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST
callback with the Request ID of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 840 def modbus_slave_answer_write_multiple_coils_request(request_id) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_COILS_REQUEST, [request_id], 'C', 8, '' end
In Modbus slave mode this function can be used to answer a master request to write multiple registers.
-
Request ID: Request ID of the corresponding request that is being answered.
This function must be called from the CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST
callback with the Request ID of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 873 def modbus_slave_answer_write_multiple_registers_request(request_id) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_REGISTERS_REQUEST, [request_id], 'C', 8, '' end
In Modbus slave mode this function can be used to answer a master request to write a single coil.
-
Request ID: Request ID of the corresponding request that is being answered.
This function must be called from the CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_COIL_REQUEST
callback with the Request ID as provided by the arguments of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 771 def modbus_slave_answer_write_single_coil_request(request_id) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_COIL_REQUEST, [request_id], 'C', 8, '' end
In Modbus slave mode this function can be used to answer a master request to write a single register.
-
Request ID: Request ID of the corresponding request that is being answered.
This function must be called from the CALLBACK_MODBUS_SLAVE_WRITE_SINGLE_REGISTER_REQUEST
callback with the Request ID, Register Address and Register Value as provided by the arguments of the callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 806 def modbus_slave_answer_write_single_register_request(request_id) check_validity send_request FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_REGISTER_REQUEST, [request_id], 'C', 8, '' end
In Modbus slave mode this function can be used to report a Modbus exception for a Modbus master request.
-
Request ID: Request ID of the request received by the slave.
-
Exception Code: Modbus exception code to report to the Modbus master.
# File lib/tinkerforge/bricklet_rs485.rb, line 688 def modbus_slave_report_exception(request_id, exception_code) check_validity send_request FUNCTION_MODBUS_SLAVE_REPORT_EXCEPTION, [request_id, exception_code], 'C c', 8, '' end
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 callback is disabled. See BrickletRS485#enable_read_callback
and CALLBACK_READ
callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 1183 def read(length) message_length = nil # assigned in block message_data = nil # assigned in block @stream_mutex.synchronize { ret = read_low_level length message_length = ret[0] message_chunk_offset = ret[1] message_out_of_sync = message_chunk_offset != 0 message_data = ret[2] while not message_out_of_sync and message_data.length < message_length ret = read_low_level length message_length = ret[0] message_chunk_offset = ret[1] message_out_of_sync = message_chunk_offset != message_data.length message_data += ret[2] end if message_out_of_sync # discard remaining stream to bring it back in-sync while message_chunk_offset + 60 < message_length ret = read_low_level length message_length = ret[0] message_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Message stream is out-of-sync' end } message_data[0, message_length] end
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 callback is disabled. See BrickletRS485#enable_read_callback
and CALLBACK_READ
callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 481 def read_low_level(length) check_validity send_request FUNCTION_READ_LOW_LEVEL, [length], 'S', 72, 'S S k60' end
Returns the current UID as an integer. Encode as Base58
to get the usual string version.
# File lib/tinkerforge/bricklet_rs485.rb, line 1112 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_rs485.rb, line 1463 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
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!
# File lib/tinkerforge/bricklet_rs485.rb, line 1093 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1016 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end
Sets the send and receive buffer size in byte. In sum there is 10240 byte (10KiB) buffer available and the minimum buffer size is 1024 byte (1KiB) for both.
The current buffer content is lost if this function is called.
The send buffer holds data that was given by BrickletRS485#write
and could not be written yet. The receive buffer holds data that is received through RS485 but could not yet be send to the user, either by BrickletRS485#read
or through CALLBACK_READ
callback.
# File lib/tinkerforge/bricklet_rs485.rb, line 613 def set_buffer_config(send_buffer_size, receive_buffer_size) check_validity send_request FUNCTION_SET_BUFFER_CONFIG, [send_buffer_size, receive_buffer_size], 'S S', 8, '' end
Sets the communication LED configuration. 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.
# File lib/tinkerforge/bricklet_rs485.rb, line 568 def set_communication_led_config(config) check_validity send_request FUNCTION_SET_COMMUNICATION_LED_CONFIG, [config], 'C', 8, '' end
Sets the error LED configuration.
By default the error LED turns on if there is any error (see CALLBACK_ERROR_COUNT
callback). If you call this function with the SHOW ERROR option again, the LED will turn off until the next error occurs.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is off.
# File lib/tinkerforge/bricklet_rs485.rb, line 590 def set_error_led_config(config) check_validity send_request FUNCTION_SET_ERROR_LED_CONFIG, [config], 'C', 8, '' end
Configures the CALLBACK_FRAME_READABLE
callback. The frame size is the number of bytes, that have to be readable to trigger the callback. A frame size of 0 disables the callback. A frame size greater than 0 enables the callback and disables the CALLBACK_READ
callback.
By default the callback is disabled.
- .. versionadded
-
2.0.5$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_rs485.rb, line 975 def set_frame_readable_callback_configuration(frame_size) check_validity send_request FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION, [frame_size], 'S', 8, '' end
Sets the configuration for the RS485 Modbus communication. Available options:
-
Slave Address: Address to be used as the Modbus slave address in Modbus slave mode. Valid Modbus slave address range is 1 to 247.
-
Master Request Timeout: Specifies how long the master should wait for a response from a slave when in Modbus master mode.
# File lib/tinkerforge/bricklet_rs485.rb, line 531 def set_modbus_configuration(slave_address, master_request_timeout) check_validity send_request FUNCTION_SET_MODBUS_CONFIGURATION, [slave_address, master_request_timeout], 'C L', 8, '' end
Sets the mode of the Bricklet in which it operates. Available options are
-
RS485,
-
Modbus Master RTU and
-
Modbus Slave RTU.
# File lib/tinkerforge/bricklet_rs485.rb, line 549 def set_mode(mode) check_validity send_request FUNCTION_SET_MODE, [mode], 'C', 8, '' end
Sets the configuration for the RS485 communication.
# File lib/tinkerforge/bricklet_rs485.rb, line 514 def set_rs485_configuration(baudrate, parity, stopbits, wordlength, duplex) check_validity send_request FUNCTION_SET_RS485_CONFIGURATION, [baudrate, parity, stopbits, wordlength, duplex], 'L C C C C', 8, '' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1062 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end
Sets the firmware pointer for BrickletRS485#write_firmware
. 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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1035 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end
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 BrickletRS485#set_rs485_configuration
for configuration possibilities regarding baudrate, parity and so on.
# File lib/tinkerforge/bricklet_rs485.rb, line 1139 def write(message) if message.length > 65535 raise ArgumentError, 'Message can be at most 65535 items long' end message_length = message.length message_chunk_offset = 0 if message_length == 0 message_chunk_data = ['\0'] * 60 ret = write_low_level message_length, message_chunk_offset, message_chunk_data message_written = ret else message_written = 0 # assigned in block @stream_mutex.synchronize { while message_chunk_offset < message_length message_chunk_data = message[message_chunk_offset, 60] if message_chunk_data.length < 60 message_chunk_data += ['\0'] * (60 - message_chunk_data.length) end ret = write_low_level message_length, message_chunk_offset, message_chunk_data message_written += ret if ret < 60 break # either last chunk or short write end message_chunk_offset += 60 end } end message_written end
Writes 64 Bytes of firmware at the position as written by BrickletRS485#set_write_firmware_pointer
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1049 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end
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 BrickletRS485#set_rs485_configuration
for configuration possibilities regarding baudrate, parity and so on.
# File lib/tinkerforge/bricklet_rs485.rb, line 469 def write_low_level(message_length, message_chunk_offset, message_chunk_data) check_validity send_request FUNCTION_WRITE_LOW_LEVEL, [message_length, message_chunk_offset, message_chunk_data], 'S S k60', 9, 'C' end
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.
# File lib/tinkerforge/bricklet_rs485.rb, line 1104 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end