rs232_v2_bricklet

package
v0.0.0-...-368b749 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Overview

Communicates with RS232 devices.

See also the documentation here: https://www.tinkerforge.com/en/doc/Software/Bricklets/RS232V2_Bricklet_Go.html.

Index

Constants

View Source
const DeviceDisplayName = "RS232 Bricklet 2.0"
View Source
const DeviceIdentifier = 2108

Variables

This section is empty.

Functions

This section is empty.

Types

type BootloaderMode

type BootloaderMode = uint8
const (
	BootloaderModeBootloader                    BootloaderMode = 0
	BootloaderModeFirmware                      BootloaderMode = 1
	BootloaderModeBootloaderWaitForReboot       BootloaderMode = 2
	BootloaderModeFirmwareWaitForReboot         BootloaderMode = 3
	BootloaderModeFirmwareWaitForEraseAndReboot BootloaderMode = 4
)

type BootloaderStatus

type BootloaderStatus = uint8
const (
	BootloaderStatusOK                        BootloaderStatus = 0
	BootloaderStatusInvalidMode               BootloaderStatus = 1
	BootloaderStatusNoChange                  BootloaderStatus = 2
	BootloaderStatusEntryFunctionNotPresent   BootloaderStatus = 3
	BootloaderStatusDeviceIdentifierIncorrect BootloaderStatus = 4
	BootloaderStatusCRCMismatch               BootloaderStatus = 5
)

type Flowcontrol

type Flowcontrol = uint8
const (
	FlowcontrolOff      Flowcontrol = 0
	FlowcontrolSoftware Flowcontrol = 1
	FlowcontrolHardware Flowcontrol = 2
)

type Function

type Function = uint8
const (
	FunctionWriteLowLevel                         Function = 1
	FunctionReadLowLevel                          Function = 2
	FunctionEnableReadCallback                    Function = 3
	FunctionDisableReadCallback                   Function = 4
	FunctionIsReadCallbackEnabled                 Function = 5
	FunctionSetConfiguration                      Function = 6
	FunctionGetConfiguration                      Function = 7
	FunctionSetBufferConfig                       Function = 8
	FunctionGetBufferConfig                       Function = 9
	FunctionGetBufferStatus                       Function = 10
	FunctionGetErrorCount                         Function = 11
	FunctionSetFrameReadableCallbackConfiguration Function = 14
	FunctionGetFrameReadableCallbackConfiguration Function = 15
	FunctionGetSPITFPErrorCount                   Function = 234
	FunctionSetBootloaderMode                     Function = 235
	FunctionGetBootloaderMode                     Function = 236
	FunctionSetWriteFirmwarePointer               Function = 237
	FunctionWriteFirmware                         Function = 238
	FunctionSetStatusLEDConfig                    Function = 239
	FunctionGetStatusLEDConfig                    Function = 240
	FunctionGetChipTemperature                    Function = 242
	FunctionReset                                 Function = 243
	FunctionWriteUID                              Function = 248
	FunctionReadUID                               Function = 249
	FunctionGetIdentity                           Function = 255
	FunctionCallbackReadLowLevel                  Function = 12
	FunctionCallbackErrorCount                    Function = 13
	FunctionCallbackFrameReadable                 Function = 16
)

type Parity

type Parity = uint8
const (
	ParityNone Parity = 0
	ParityOdd  Parity = 1
	ParityEven Parity = 2
)

type RS232V2Bricklet

type RS232V2Bricklet struct {
	// contains filtered or unexported fields
}

func New

Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ipcon` is connected.

func (*RS232V2Bricklet) DeregisterErrorCountCallback

func (device *RS232V2Bricklet) DeregisterErrorCountCallback(registrationId uint64)

Remove a registered Error Count callback.

func (*RS232V2Bricklet) DeregisterFrameReadableCallback

func (device *RS232V2Bricklet) DeregisterFrameReadableCallback(registrationId uint64)

Remove a registered Frame Readable callback.

func (*RS232V2Bricklet) DeregisterReadCallback

func (device *RS232V2Bricklet) DeregisterReadCallback(registrationId uint64)

Remove a registered Read Low Level callback.

func (*RS232V2Bricklet) DeregisterReadLowLevelCallback

func (device *RS232V2Bricklet) DeregisterReadLowLevelCallback(registrationId uint64)

Remove a registered Read Low Level callback.

func (*RS232V2Bricklet) DisableReadCallback

func (device *RS232V2Bricklet) DisableReadCallback() (err error)

Disables the RegisterReadCallback callback.

By default the callback is disabled.

func (*RS232V2Bricklet) EnableReadCallback

func (device *RS232V2Bricklet) EnableReadCallback() (err error)

Enables the RegisterReadCallback callback. This will disable the RegisterFrameReadableCallback callback.

By default the callback is disabled.

func (*RS232V2Bricklet) GetAPIVersion

func (device *RS232V2Bricklet) GetAPIVersion() [3]uint8

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

func (*RS232V2Bricklet) GetBootloaderMode

func (device *RS232V2Bricklet) GetBootloaderMode() (mode BootloaderMode, err error)

Returns the current bootloader mode, see SetBootloaderMode.

Associated constants:

  • BootloaderModeBootloader
  • BootloaderModeFirmware
  • BootloaderModeBootloaderWaitForReboot
  • BootloaderModeFirmwareWaitForReboot
  • BootloaderModeFirmwareWaitForEraseAndReboot

func (*RS232V2Bricklet) GetBufferConfig

func (device *RS232V2Bricklet) GetBufferConfig() (sendBufferSize uint16, receiveBufferSize uint16, err error)

Returns the buffer configuration as set by SetBufferConfig.

func (*RS232V2Bricklet) GetBufferStatus

func (device *RS232V2Bricklet) GetBufferStatus() (sendBufferUsed uint16, receiveBufferUsed uint16, err error)

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

See SetBufferConfig for buffer size configuration.

func (*RS232V2Bricklet) GetChipTemperature

func (device *RS232V2Bricklet) GetChipTemperature() (temperature int16, err error)

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.

func (*RS232V2Bricklet) GetConfiguration

func (device *RS232V2Bricklet) GetConfiguration() (baudrate uint32, parity Parity, stopbits Stopbits, wordlength Wordlength, flowcontrol Flowcontrol, err error)

Returns the configuration as set by SetConfiguration.

Associated constants:

  • ParityNone
  • ParityOdd
  • ParityEven
  • Stopbits1
  • Stopbits2
  • Wordlength5
  • Wordlength6
  • Wordlength7
  • Wordlength8
  • FlowcontrolOff
  • FlowcontrolSoftware
  • FlowcontrolHardware

func (*RS232V2Bricklet) GetErrorCount

func (device *RS232V2Bricklet) GetErrorCount() (errorCountOverrun uint32, errorCountParity uint32, err error)

Returns the current number of overrun and parity errors.

func (*RS232V2Bricklet) GetFrameReadableCallbackConfiguration

func (device *RS232V2Bricklet) GetFrameReadableCallbackConfiguration() (frameSize uint16, err error)

Returns the callback configuration as set by SetFrameReadableCallbackConfiguration.

.. versionadded:: 2.0.3$nbsp;(Plugin)

func (*RS232V2Bricklet) GetIdentity

func (device *RS232V2Bricklet) GetIdentity() (uid string, connectedUid string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, err error)

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an `Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found `here <device_identifier>`. |device_identifier_constant|

func (*RS232V2Bricklet) GetResponseExpected

func (device *RS232V2Bricklet) GetResponseExpected(functionID Function) (bool, error)

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by SetResponseExpected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

See SetResponseExpected for the list of function ID constants available for this function.

func (*RS232V2Bricklet) GetSPITFPErrorCount

func (device *RS232V2Bricklet) GetSPITFPErrorCount() (errorCountAckChecksum uint32, errorCountMessageChecksum uint32, errorCountFrame uint32, errorCountOverflow uint32, err error)

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.

func (*RS232V2Bricklet) GetStatusLEDConfig

func (device *RS232V2Bricklet) GetStatusLEDConfig() (config StatusLEDConfig, err error)

Returns the configuration as set by SetStatusLEDConfig

Associated constants:

  • StatusLEDConfigOff
  • StatusLEDConfigOn
  • StatusLEDConfigShowHeartbeat
  • StatusLEDConfigShowStatus

func (*RS232V2Bricklet) IsReadCallbackEnabled

func (device *RS232V2Bricklet) IsReadCallbackEnabled() (enabled bool, err error)

Returns *true* if the RegisterReadCallback callback is enabled, *false* otherwise.

func (*RS232V2Bricklet) Read

func (device *RS232V2Bricklet) Read(length uint16) (message []rune, err error)

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 EnableReadCallback and RegisterReadCallback callback.

func (*RS232V2Bricklet) ReadLowLevel

func (device *RS232V2Bricklet) ReadLowLevel(length uint16) (messageLength uint16, messageChunkOffset uint16, messageChunkData [60]rune, err error)

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 EnableReadCallback and RegisterReadCallback callback.

func (*RS232V2Bricklet) ReadUID

func (device *RS232V2Bricklet) ReadUID() (uid uint32, err error)

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

func (*RS232V2Bricklet) RegisterErrorCountCallback

func (device *RS232V2Bricklet) RegisterErrorCountCallback(fn func(uint32, uint32)) uint64

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

func (*RS232V2Bricklet) RegisterFrameReadableCallback

func (device *RS232V2Bricklet) RegisterFrameReadableCallback(fn func(uint16)) uint64

This callback is called if at least one frame of data is readable. The frame size is configured with SetFrameReadableCallbackConfiguration. The frame count parameter is the number of frames that can be read. This callback is triggered only once until Read is called. This means, that if you have configured a frame size of X bytes, you can read exactly X bytes using the Read function, every time the callback triggers without checking the frame count parameter.

.. versionadded:: 2.0.3$nbsp;(Plugin)

func (*RS232V2Bricklet) RegisterReadCallback

func (device *RS232V2Bricklet) RegisterReadCallback(fn func([]rune)) uint64

This callback is called if new data is available.

To enable this callback, use EnableReadCallback.

Note

If reconstructing the value fails, the callback is triggered with nil for message.

func (*RS232V2Bricklet) RegisterReadLowLevelCallback

func (device *RS232V2Bricklet) RegisterReadLowLevelCallback(fn func(uint16, uint16, [60]rune)) uint64

See RegisterReadCallback

func (*RS232V2Bricklet) Reset

func (device *RS232V2Bricklet) Reset() (err error)

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!

func (*RS232V2Bricklet) SetBootloaderMode

func (device *RS232V2Bricklet) SetBootloaderMode(mode BootloaderMode) (status BootloaderStatus, err error)

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.

Associated constants:

  • BootloaderModeBootloader
  • BootloaderModeFirmware
  • BootloaderModeBootloaderWaitForReboot
  • BootloaderModeFirmwareWaitForReboot
  • BootloaderModeFirmwareWaitForEraseAndReboot
  • BootloaderStatusOK
  • BootloaderStatusInvalidMode
  • BootloaderStatusNoChange
  • BootloaderStatusEntryFunctionNotPresent
  • BootloaderStatusDeviceIdentifierIncorrect
  • BootloaderStatusCRCMismatch

func (*RS232V2Bricklet) SetBufferConfig

func (device *RS232V2Bricklet) SetBufferConfig(sendBufferSize uint16, receiveBufferSize uint16) (err error)

Sets the send and receive buffer size in byte. In total the buffers have to be 10240 byte (10KiB) in size, the minimum buffer size is 1024 byte (1KiB) for each.

The current buffer content is lost if this function is called.

The send buffer holds data that is given by Write and can not be written yet. The receive buffer holds data that is received through RS232 but could not yet be send to the user, either by Read or through RegisterReadCallback callback.

func (*RS232V2Bricklet) SetConfiguration

func (device *RS232V2Bricklet) SetConfiguration(baudrate uint32, parity Parity, stopbits Stopbits, wordlength Wordlength, flowcontrol Flowcontrol) (err error)

Sets the configuration for the RS232 communication.

Associated constants:

  • ParityNone
  • ParityOdd
  • ParityEven
  • Stopbits1
  • Stopbits2
  • Wordlength5
  • Wordlength6
  • Wordlength7
  • Wordlength8
  • FlowcontrolOff
  • FlowcontrolSoftware
  • FlowcontrolHardware

func (*RS232V2Bricklet) SetFrameReadableCallbackConfiguration

func (device *RS232V2Bricklet) SetFrameReadableCallbackConfiguration(frameSize uint16) (err error)

Configures the RegisterFrameReadableCallback 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 RegisterReadCallback callback.

By default the callback is disabled.

.. versionadded:: 2.0.3$nbsp;(Plugin)

func (*RS232V2Bricklet) SetResponseExpected

func (device *RS232V2Bricklet) SetResponseExpected(functionID Function, responseExpected bool) error

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

func (*RS232V2Bricklet) SetResponseExpectedAll

func (device *RS232V2Bricklet) SetResponseExpectedAll(responseExpected bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

func (*RS232V2Bricklet) SetStatusLEDConfig

func (device *RS232V2Bricklet) SetStatusLEDConfig(config StatusLEDConfig) (err error)

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.

Associated constants:

  • StatusLEDConfigOff
  • StatusLEDConfigOn
  • StatusLEDConfigShowHeartbeat
  • StatusLEDConfigShowStatus

func (*RS232V2Bricklet) SetWriteFirmwarePointer

func (device *RS232V2Bricklet) SetWriteFirmwarePointer(pointer uint32) (err error)

Sets the firmware pointer for WriteFirmware. 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.

func (*RS232V2Bricklet) Write

func (device *RS232V2Bricklet) Write(message []rune) (messageChunkWritten uint64, err error)

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

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

See SetConfiguration for configuration possibilities regarding baud rate, parity and so on.

func (*RS232V2Bricklet) WriteFirmware

func (device *RS232V2Bricklet) WriteFirmware(data [64]uint8) (status uint8, err error)

Writes 64 Bytes of firmware at the position as written by SetWriteFirmwarePointer 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.

func (*RS232V2Bricklet) WriteLowLevel

func (device *RS232V2Bricklet) WriteLowLevel(messageLength uint16, messageChunkOffset uint16, messageChunkData [60]rune) (messageChunkWritten uint8, err error)

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

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

See SetConfiguration for configuration possibilities regarding baud rate, parity and so on.

func (*RS232V2Bricklet) WriteUID

func (device *RS232V2Bricklet) WriteUID(uid uint32) (err error)

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.

type StatusLEDConfig

type StatusLEDConfig = uint8
const (
	StatusLEDConfigOff           StatusLEDConfig = 0
	StatusLEDConfigOn            StatusLEDConfig = 1
	StatusLEDConfigShowHeartbeat StatusLEDConfig = 2
	StatusLEDConfigShowStatus    StatusLEDConfig = 3
)

type Stopbits

type Stopbits = uint8
const (
	Stopbits1 Stopbits = 1
	Stopbits2 Stopbits = 2
)

type Wordlength

type Wordlength = uint8
const (
	Wordlength5 Wordlength = 5
	Wordlength6 Wordlength = 6
	Wordlength7 Wordlength = 7
	Wordlength8 Wordlength = 8
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL