Class: Tinkerforge::BrickletRS485

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_rs485.rb

Overview

Communicates with RS485/Modbus devices with full- or half-duplex

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

277
DEVICE_DISPLAY_NAME =

:nodoc:

'RS485 Bricklet'
CALLBACK_READ_LOW_LEVEL =

See CALLBACK_READ

41
CALLBACK_ERROR_COUNT =

This callback is called if a new error occurs. It returns the current overrun and parity error count.

42
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.

43
CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE_LOW_LEVEL =

See CALLBACK_MODBUS_MASTER_READ_COILS_RESPONSE

44
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.

45
CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE_LOW_LEVEL =

See CALLBACK_MODBUS_MASTER_READ_HOLDING_REGISTERS_RESPONSE

46
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.

47
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.

48
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.

49
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.

50
CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST_LOW_LEVEL =

See CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_COILS_REQUEST

51
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.

52
CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST_LOW_LEVEL =

See CALLBACK_MODBUS_SLAVE_WRITE_MULTIPLE_REGISTERS_REQUEST

53
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.

54
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.

55
CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE_LOW_LEVEL =

See CALLBACK_MODBUS_MASTER_READ_DISCRETE_INPUTS_RESPONSE

56
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.

57
CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE_LOW_LEVEL =

See CALLBACK_MODBUS_MASTER_READ_INPUT_REGISTERS_RESPONSE

58
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 until BrickletRS485#read is called. This means, that if you have configured a frame size of X bytes, you can read exactly X bytes using the BrickletRS485#read function, every time the callback triggers without checking the frame count parameter.

.. versionadded

2.0.5$nbsp;(Plugin)

61
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.

-41
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.

-44
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.

-46
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.

-51
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.

-53
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.

-56
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.

-58
FUNCTION_WRITE_LOW_LEVEL =

:nodoc:

1
FUNCTION_READ_LOW_LEVEL =

:nodoc:

2
FUNCTION_ENABLE_READ_CALLBACK =

:nodoc:

3
FUNCTION_DISABLE_READ_CALLBACK =

:nodoc:

4
FUNCTION_IS_READ_CALLBACK_ENABLED =

:nodoc:

5
FUNCTION_SET_RS485_CONFIGURATION =

:nodoc:

6
FUNCTION_GET_RS485_CONFIGURATION =

:nodoc:

7
FUNCTION_SET_MODBUS_CONFIGURATION =

:nodoc:

8
FUNCTION_GET_MODBUS_CONFIGURATION =

:nodoc:

9
FUNCTION_SET_MODE =

:nodoc:

10
FUNCTION_GET_MODE =

:nodoc:

11
FUNCTION_SET_COMMUNICATION_LED_CONFIG =

:nodoc:

12
FUNCTION_GET_COMMUNICATION_LED_CONFIG =

:nodoc:

13
FUNCTION_SET_ERROR_LED_CONFIG =

:nodoc:

14
FUNCTION_GET_ERROR_LED_CONFIG =

:nodoc:

15
FUNCTION_SET_BUFFER_CONFIG =

:nodoc:

16
FUNCTION_GET_BUFFER_CONFIG =

:nodoc:

17
FUNCTION_GET_BUFFER_STATUS =

:nodoc:

18
FUNCTION_ENABLE_ERROR_COUNT_CALLBACK =

:nodoc:

19
FUNCTION_DISABLE_ERROR_COUNT_CALLBACK =

:nodoc:

20
FUNCTION_IS_ERROR_COUNT_CALLBACK_ENABLED =

:nodoc:

21
FUNCTION_GET_ERROR_COUNT =

:nodoc:

22
FUNCTION_GET_MODBUS_COMMON_ERROR_COUNT =

:nodoc:

23
FUNCTION_MODBUS_SLAVE_REPORT_EXCEPTION =

:nodoc:

24
FUNCTION_MODBUS_SLAVE_ANSWER_READ_COILS_REQUEST_LOW_LEVEL =

:nodoc:

25
FUNCTION_MODBUS_MASTER_READ_COILS =

:nodoc:

26
FUNCTION_MODBUS_SLAVE_ANSWER_READ_HOLDING_REGISTERS_REQUEST_LOW_LEVEL =

:nodoc:

27
FUNCTION_MODBUS_MASTER_READ_HOLDING_REGISTERS =

:nodoc:

28
FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_COIL_REQUEST =

:nodoc:

29
FUNCTION_MODBUS_MASTER_WRITE_SINGLE_COIL =

:nodoc:

30
FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_SINGLE_REGISTER_REQUEST =

:nodoc:

31
FUNCTION_MODBUS_MASTER_WRITE_SINGLE_REGISTER =

:nodoc:

32
FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_COILS_REQUEST =

:nodoc:

33
FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_COILS_LOW_LEVEL =

:nodoc:

34
FUNCTION_MODBUS_SLAVE_ANSWER_WRITE_MULTIPLE_REGISTERS_REQUEST =

:nodoc:

35
FUNCTION_MODBUS_MASTER_WRITE_MULTIPLE_REGISTERS_LOW_LEVEL =

:nodoc:

36
FUNCTION_MODBUS_SLAVE_ANSWER_READ_DISCRETE_INPUTS_REQUEST_LOW_LEVEL =

:nodoc:

37
FUNCTION_MODBUS_MASTER_READ_DISCRETE_INPUTS =

:nodoc:

38
FUNCTION_MODBUS_SLAVE_ANSWER_READ_INPUT_REGISTERS_REQUEST_LOW_LEVEL =

:nodoc:

39
FUNCTION_MODBUS_MASTER_READ_INPUT_REGISTERS =

:nodoc:

40
FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION =

:nodoc:

59
FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION =

:nodoc:

60
FUNCTION_GET_SPITFP_ERROR_COUNT =

:nodoc:

234
FUNCTION_SET_BOOTLOADER_MODE =

:nodoc:

235
FUNCTION_GET_BOOTLOADER_MODE =

:nodoc:

236
FUNCTION_SET_WRITE_FIRMWARE_POINTER =

:nodoc:

237
FUNCTION_WRITE_FIRMWARE =

:nodoc:

238
FUNCTION_SET_STATUS_LED_CONFIG =

:nodoc:

239
FUNCTION_GET_STATUS_LED_CONFIG =

:nodoc:

240
FUNCTION_GET_CHIP_TEMPERATURE =

:nodoc:

242
FUNCTION_RESET =

:nodoc:

243
FUNCTION_WRITE_UID =

:nodoc:

248
FUNCTION_READ_UID =

:nodoc:

249
FUNCTION_GET_IDENTITY =

:nodoc:

255
PARITY_NONE =

:nodoc:

0
PARITY_ODD =

:nodoc:

1
PARITY_EVEN =

:nodoc:

2
STOPBITS_1 =

:nodoc:

1
STOPBITS_2 =

:nodoc:

2
WORDLENGTH_5 =

:nodoc:

5
WORDLENGTH_6 =

:nodoc:

6
WORDLENGTH_7 =

:nodoc:

7
WORDLENGTH_8 =

:nodoc:

8
DUPLEX_HALF =

:nodoc:

0
DUPLEX_FULL =

:nodoc:

1
MODE_RS485 =

:nodoc:

0
MODE_MODBUS_MASTER_RTU =

:nodoc:

1
MODE_MODBUS_SLAVE_RTU =

:nodoc:

2
COMMUNICATION_LED_CONFIG_OFF =

:nodoc:

0
COMMUNICATION_LED_CONFIG_ON =

:nodoc:

1
COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION =

:nodoc:

3
ERROR_LED_CONFIG_OFF =

:nodoc:

0
ERROR_LED_CONFIG_ON =

:nodoc:

1
ERROR_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
ERROR_LED_CONFIG_SHOW_ERROR =

:nodoc:

3
EXCEPTION_CODE_TIMEOUT =

:nodoc:

-1 # :nodoc:
EXCEPTION_CODE_SUCCESS =

:nodoc:

0
EXCEPTION_CODE_ILLEGAL_FUNCTION =

:nodoc:

1
EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS =

:nodoc:

2
EXCEPTION_CODE_ILLEGAL_DATA_VALUE =

:nodoc:

3
EXCEPTION_CODE_SLAVE_DEVICE_FAILURE =

:nodoc:

4
EXCEPTION_CODE_ACKNOWLEDGE =

:nodoc:

5
EXCEPTION_CODE_SLAVE_DEVICE_BUSY =

:nodoc:

6
EXCEPTION_CODE_MEMORY_PARITY_ERROR =

:nodoc:

8
EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE =

:nodoc:

10
EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND =

:nodoc:

11
BOOTLOADER_MODE_BOOTLOADER =

:nodoc:

0
BOOTLOADER_MODE_FIRMWARE =

:nodoc:

1
BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =

:nodoc:

2
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =

:nodoc:

3
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =

:nodoc:

4
BOOTLOADER_STATUS_OK =

:nodoc:

0
BOOTLOADER_STATUS_INVALID_MODE =

:nodoc:

1
BOOTLOADER_STATUS_NO_CHANGE =

:nodoc:

2
BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =

:nodoc:

3
BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =

:nodoc:

4
BOOTLOADER_STATUS_CRC_MISMATCH =

:nodoc:

5
STATUS_LED_CONFIG_OFF =

:nodoc:

0
STATUS_LED_CONFIG_ON =

:nodoc:

1
STATUS_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
STATUS_LED_CONFIG_SHOW_STATUS =

:nodoc:

3

Constants inherited from Device

Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid

Instance Method Summary collapse

Methods inherited from Device

#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletRS485

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/tinkerforge/bricklet_rs485.rb', line 373

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

Instance Method Details

#disable_error_count_callbackObject

Disables the CALLBACK_ERROR_COUNT callback.

By default the callback is disabled.



648
649
650
651
652
# File 'lib/tinkerforge/bricklet_rs485.rb', line 648

def disable_error_count_callback
  check_validity

  send_request FUNCTION_DISABLE_ERROR_COUNT_CALLBACK, [], '', 8, ''
end

#disable_read_callbackObject

Disables the CALLBACK_READ callback.

By default the callback is disabled.



500
501
502
503
504
# File 'lib/tinkerforge/bricklet_rs485.rb', line 500

def disable_read_callback
  check_validity

  send_request FUNCTION_DISABLE_READ_CALLBACK, [], '', 8, ''
end

#enable_error_count_callbackObject

Enables the CALLBACK_ERROR_COUNT callback.

By default the callback is disabled.



639
640
641
642
643
# File 'lib/tinkerforge/bricklet_rs485.rb', line 639

def enable_error_count_callback
  check_validity

  send_request FUNCTION_ENABLE_ERROR_COUNT_CALLBACK, [], '', 8, ''
end

#enable_read_callbackObject

Enables the CALLBACK_READ callback. This will disable the CALLBACK_FRAME_READABLE callback.

By default the callback is disabled.



491
492
493
494
495
# File 'lib/tinkerforge/bricklet_rs485.rb', line 491

def enable_read_callback
  check_validity

  send_request FUNCTION_ENABLE_READ_CALLBACK, [], '', 8, ''
end

#get_bootloader_modeObject

Returns the current bootloader mode, see BrickletRS485#set_bootloader_mode.



1024
1025
1026
1027
1028
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1024

def get_bootloader_mode
  check_validity

  send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
end

#get_buffer_configObject

Returns the buffer configuration as set by BrickletRS485#set_buffer_config.



621
622
623
624
625
# File 'lib/tinkerforge/bricklet_rs485.rb', line 621

def get_buffer_config
  check_validity

  send_request FUNCTION_GET_BUFFER_CONFIG, [], '', 12, 'S S'
end

#get_buffer_statusObject

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

See BrickletRS485#set_buffer_config for buffer size configuration.



630
631
632
633
634
# File 'lib/tinkerforge/bricklet_rs485.rb', line 630

def get_buffer_status
  check_validity

  send_request FUNCTION_GET_BUFFER_STATUS, [], '', 12, 'S S'
end

#get_chip_temperatureObject

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.



1082
1083
1084
1085
1086
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1082

def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end

#get_communication_led_configObject

Returns the configuration as set by BrickletRS485#set_communication_led_config



576
577
578
579
580
# File 'lib/tinkerforge/bricklet_rs485.rb', line 576

def get_communication_led_config
  check_validity

  send_request FUNCTION_GET_COMMUNICATION_LED_CONFIG, [], '', 9, 'C'
end

#get_error_countObject

Returns the current number of overrun and parity errors.



663
664
665
666
667
# File 'lib/tinkerforge/bricklet_rs485.rb', line 663

def get_error_count
  check_validity

  send_request FUNCTION_GET_ERROR_COUNT, [], '', 16, 'L L'
end

#get_error_led_configObject

Returns the configuration as set by BrickletRS485#set_error_led_config.



598
599
600
601
602
# File 'lib/tinkerforge/bricklet_rs485.rb', line 598

def get_error_led_config
  check_validity

  send_request FUNCTION_GET_ERROR_LED_CONFIG, [], '', 9, 'C'
end

#get_frame_readable_callback_configurationObject

Returns the callback configuration as set by BrickletRS485#set_frame_readable_callback_configuration.

.. versionadded

2.0.5$nbsp;(Plugin)



985
986
987
988
989
# File 'lib/tinkerforge/bricklet_rs485.rb', line 985

def get_frame_readable_callback_configuration
  check_validity

  send_request FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION, [], '', 10, 'S'
end

#get_identityObject

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|



1129
1130
1131
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1129

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_modbus_common_error_countObject

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.



678
679
680
681
682
# File 'lib/tinkerforge/bricklet_rs485.rb', line 678

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

#get_modbus_configurationObject

Returns the configuration as set by BrickletRS485#set_modbus_configuration.



539
540
541
542
543
# File 'lib/tinkerforge/bricklet_rs485.rb', line 539

def get_modbus_configuration
  check_validity

  send_request FUNCTION_GET_MODBUS_CONFIGURATION, [], '', 13, 'C L'
end

#get_modeObject

Returns the configuration as set by BrickletRS485#set_mode.



557
558
559
560
561
# File 'lib/tinkerforge/bricklet_rs485.rb', line 557

def get_mode
  check_validity

  send_request FUNCTION_GET_MODE, [], '', 9, 'C'
end

#get_rs485_configurationObject

Returns the configuration as set by BrickletRS485#set_rs485_configuration.



522
523
524
525
526
# File 'lib/tinkerforge/bricklet_rs485.rb', line 522

def get_rs485_configuration
  check_validity

  send_request FUNCTION_GET_RS485_CONFIGURATION, [], '', 16, 'L C C C C'
end

#get_spitfp_error_countObject

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.



1002
1003
1004
1005
1006
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1002

def get_spitfp_error_count
  check_validity

  send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
end

#get_status_led_configObject

Returns the configuration as set by BrickletRS485#set_status_led_config



1070
1071
1072
1073
1074
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1070

def get_status_led_config
  check_validity

  send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
end

#is_error_count_callback_enabledObject

Returns true if the CALLBACK_ERROR_COUNT callback is enabled, false otherwise.



656
657
658
659
660
# File 'lib/tinkerforge/bricklet_rs485.rb', line 656

def is_error_count_callback_enabled
  check_validity

  send_request FUNCTION_IS_ERROR_COUNT_CALLBACK_ENABLED, [], '', 9, '?'
end

#is_read_callback_enabledObject

Returns true if the CALLBACK_READ callback is enabled, false otherwise.



508
509
510
511
512
# File 'lib/tinkerforge/bricklet_rs485.rb', line 508

def is_read_callback_enabled
  check_validity

  send_request FUNCTION_IS_READ_CALLBACK_ENABLED, [], '', 9, '?'
end

#modbus_master_read_coils(slave_address, starting_address, count) ⇒ Object

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.



724
725
726
727
728
# File 'lib/tinkerforge/bricklet_rs485.rb', line 724

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

#modbus_master_read_discrete_inputs(slave_address, starting_address, count) ⇒ Object

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.



929
930
931
932
933
# File 'lib/tinkerforge/bricklet_rs485.rb', line 929

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

#modbus_master_read_holding_registers(slave_address, starting_address, count) ⇒ Object

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.



759
760
761
762
763
# File 'lib/tinkerforge/bricklet_rs485.rb', line 759

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

#modbus_master_read_input_registers(slave_address, starting_address, count) ⇒ Object

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.



964
965
966
967
968
# File 'lib/tinkerforge/bricklet_rs485.rb', line 964

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

#modbus_master_write_multiple_coils(slave_address, starting_address, coils) ⇒ Object

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.



1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1309

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

#modbus_master_write_multiple_coils_low_level(slave_address, starting_address, coils_length, coils_chunk_offset, coils_chunk_data) ⇒ Object

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.



861
862
863
864
865
# File 'lib/tinkerforge/bricklet_rs485.rb', line 861

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

#modbus_master_write_multiple_registers(slave_address, starting_address, registers) ⇒ Object

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.



1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1354

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

#modbus_master_write_multiple_registers_low_level(slave_address, starting_address, registers_length, registers_chunk_offset, registers_chunk_data) ⇒ Object

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.



894
895
896
897
898
# File 'lib/tinkerforge/bricklet_rs485.rb', line 894

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

#modbus_master_write_single_coil(slave_address, coil_address, coil_value) ⇒ Object

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.



793
794
795
796
797
# File 'lib/tinkerforge/bricklet_rs485.rb', line 793

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

#modbus_master_write_single_register(slave_address, register_address, register_value) ⇒ Object

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.



828
829
830
831
832
# File 'lib/tinkerforge/bricklet_rs485.rb', line 828

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

#modbus_slave_answer_read_coils_request(request_id, coils) ⇒ Object

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.



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1225

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

#modbus_slave_answer_read_coils_request_low_level(request_id, coils_length, coils_chunk_offset, coils_chunk_data) ⇒ Object

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.



703
704
705
706
707
# File 'lib/tinkerforge/bricklet_rs485.rb', line 703

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

#modbus_slave_answer_read_discrete_inputs_request(request_id, discrete_inputs) ⇒ Object

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.



1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1393

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

#modbus_slave_answer_read_discrete_inputs_request_low_level(request_id, discrete_inputs_length, discrete_inputs_chunk_offset, discrete_inputs_chunk_data) ⇒ Object

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.



908
909
910
911
912
# File 'lib/tinkerforge/bricklet_rs485.rb', line 908

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

#modbus_slave_answer_read_holding_registers_request(request_id, holding_registers) ⇒ Object

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.



1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1264

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

#modbus_slave_answer_read_holding_registers_request_low_level(request_id, holding_registers_length, holding_registers_chunk_offset, holding_registers_chunk_data) ⇒ Object

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.



738
739
740
741
742
# File 'lib/tinkerforge/bricklet_rs485.rb', line 738

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

#modbus_slave_answer_read_input_registers_request(request_id, input_registers) ⇒ Object

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.



1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1432

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

#modbus_slave_answer_read_input_registers_request_low_level(request_id, input_registers_length, input_registers_chunk_offset, input_registers_chunk_data) ⇒ Object

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.



943
944
945
946
947
# File 'lib/tinkerforge/bricklet_rs485.rb', line 943

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

#modbus_slave_answer_write_multiple_coils_request(request_id) ⇒ Object

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.



841
842
843
844
845
# File 'lib/tinkerforge/bricklet_rs485.rb', line 841

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

#modbus_slave_answer_write_multiple_registers_request(request_id) ⇒ Object

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.



874
875
876
877
878
# File 'lib/tinkerforge/bricklet_rs485.rb', line 874

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

#modbus_slave_answer_write_single_coil_request(request_id) ⇒ Object

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.



772
773
774
775
776
# File 'lib/tinkerforge/bricklet_rs485.rb', line 772

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

#modbus_slave_answer_write_single_register_request(request_id) ⇒ Object

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.



807
808
809
810
811
# File 'lib/tinkerforge/bricklet_rs485.rb', line 807

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

#modbus_slave_report_exception(request_id, exception_code) ⇒ Object

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.



689
690
691
692
693
# File 'lib/tinkerforge/bricklet_rs485.rb', line 689

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

#read(length) ⇒ Object

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.



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1184

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

#read_low_level(length) ⇒ Object

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.



482
483
484
485
486
# File 'lib/tinkerforge/bricklet_rs485.rb', line 482

def read_low_level(length)
  check_validity

  send_request FUNCTION_READ_LOW_LEVEL, [length], 'S', 72, 'S S k60'
end

#read_uidObject

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



1113
1114
1115
1116
1117
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1113

def read_uid
  check_validity

  send_request FUNCTION_READ_UID, [], '', 12, 'L'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



1464
1465
1466
1467
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1464

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#resetObject

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!



1094
1095
1096
1097
1098
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1094

def reset
  check_validity

  send_request FUNCTION_RESET, [], '', 8, ''
end

#set_bootloader_mode(mode) ⇒ Object

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.



1017
1018
1019
1020
1021
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1017

def set_bootloader_mode(mode)
  check_validity

  send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
end

#set_buffer_config(send_buffer_size, receive_buffer_size) ⇒ Object

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.



614
615
616
617
618
# File 'lib/tinkerforge/bricklet_rs485.rb', line 614

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

#set_communication_led_config(config) ⇒ Object

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.



569
570
571
572
573
# File 'lib/tinkerforge/bricklet_rs485.rb', line 569

def set_communication_led_config(config)
  check_validity

  send_request FUNCTION_SET_COMMUNICATION_LED_CONFIG, [config], 'C', 8, ''
end

#set_error_led_config(config) ⇒ Object

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.



591
592
593
594
595
# File 'lib/tinkerforge/bricklet_rs485.rb', line 591

def set_error_led_config(config)
  check_validity

  send_request FUNCTION_SET_ERROR_LED_CONFIG, [config], 'C', 8, ''
end

#set_frame_readable_callback_configuration(frame_size) ⇒ Object

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)



976
977
978
979
980
# File 'lib/tinkerforge/bricklet_rs485.rb', line 976

def set_frame_readable_callback_configuration(frame_size)
  check_validity

  send_request FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION, [frame_size], 'S', 8, ''
end

#set_modbus_configuration(slave_address, master_request_timeout) ⇒ Object

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.



532
533
534
535
536
# File 'lib/tinkerforge/bricklet_rs485.rb', line 532

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

#set_mode(mode) ⇒ Object

Sets the mode of the Bricklet in which it operates. Available options are

  • RS485,

  • Modbus Master RTU and

  • Modbus Slave RTU.



550
551
552
553
554
# File 'lib/tinkerforge/bricklet_rs485.rb', line 550

def set_mode(mode)
  check_validity

  send_request FUNCTION_SET_MODE, [mode], 'C', 8, ''
end

#set_rs485_configuration(baudrate, parity, stopbits, wordlength, duplex) ⇒ Object

Sets the configuration for the RS485 communication.



515
516
517
518
519
# File 'lib/tinkerforge/bricklet_rs485.rb', line 515

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

#set_status_led_config(config) ⇒ Object

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.



1063
1064
1065
1066
1067
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1063

def set_status_led_config(config)
  check_validity

  send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
end

#set_write_firmware_pointer(pointer) ⇒ Object

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.



1036
1037
1038
1039
1040
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1036

def set_write_firmware_pointer(pointer)
  check_validity

  send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
end

#write(message) ⇒ Object

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.



1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1140

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

#write_firmware(data) ⇒ Object

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.



1050
1051
1052
1053
1054
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1050

def write_firmware(data)
  check_validity

  send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
end

#write_low_level(message_length, message_chunk_offset, message_chunk_data) ⇒ Object

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.



470
471
472
473
474
# File 'lib/tinkerforge/bricklet_rs485.rb', line 470

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

#write_uid(uid) ⇒ Object

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.



1105
1106
1107
1108
1109
# File 'lib/tinkerforge/bricklet_rs485.rb', line 1105

def write_uid(uid)
  check_validity

  send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
end