Documentation ¶
Overview ¶
Communicates with RS232 devices.
See also the documentation here: https://www.tinkerforge.com/en/doc/Software/Bricklets/RS232_Bricklet_Go.html.
Index ¶
- Constants
- type Baudrate
- type Error
- type Function
- type HardwareFlowcontrol
- type Parity
- type RS232Bricklet
- func (device *RS232Bricklet) DeregisterErrorCallback(registrationId uint64)
- func (device *RS232Bricklet) DeregisterFrameReadableCallback(registrationId uint64)
- func (device *RS232Bricklet) DeregisterReadCallback(registrationId uint64)
- func (device *RS232Bricklet) DisableReadCallback() (err error)
- func (device *RS232Bricklet) EnableReadCallback() (err error)
- func (device *RS232Bricklet) GetAPIVersion() [3]uint8
- func (device *RS232Bricklet) GetConfiguration() (baudrate Baudrate, parity Parity, stopbits Stopbits, wordlength Wordlength, ...)
- func (device *RS232Bricklet) GetFrameReadableCallbackConfiguration() (frameSize uint8, err error)
- func (device *RS232Bricklet) GetIdentity() (uid string, connectedUid string, position rune, hardwareVersion [3]uint8, ...)
- func (device *RS232Bricklet) GetResponseExpected(functionID Function) (bool, error)
- func (device *RS232Bricklet) IsReadCallbackEnabled() (enabled bool, err error)
- func (device *RS232Bricklet) Read() (message [60]rune, length uint8, err error)
- func (device *RS232Bricklet) ReadFrame() (message [60]rune, length uint8, err error)
- func (device *RS232Bricklet) RegisterErrorCallback(fn func(Error)) uint64
- func (device *RS232Bricklet) RegisterFrameReadableCallback(fn func(uint8)) uint64
- func (device *RS232Bricklet) RegisterReadCallback(fn func([60]rune, uint8)) uint64
- func (device *RS232Bricklet) SetBreakCondition(breakTime uint16) (err error)
- func (device *RS232Bricklet) SetConfiguration(baudrate Baudrate, parity Parity, stopbits Stopbits, wordlength Wordlength, ...) (err error)
- func (device *RS232Bricklet) SetFrameReadableCallbackConfiguration(frameSize uint8) (err error)
- func (device *RS232Bricklet) SetResponseExpected(functionID Function, responseExpected bool) error
- func (device *RS232Bricklet) SetResponseExpectedAll(responseExpected bool)
- func (device *RS232Bricklet) Write(message [60]rune, length uint8) (written uint8, err error)
- type SoftwareFlowcontrol
- type Stopbits
- type Wordlength
Constants ¶
const DeviceDisplayName = "RS232 Bricklet"
const DeviceIdentifier = 254
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Baudrate ¶
type Baudrate = uint8
const ( Baudrate300 Baudrate = 0 Baudrate600 Baudrate = 1 Baudrate1200 Baudrate = 2 Baudrate2400 Baudrate = 3 Baudrate4800 Baudrate = 4 Baudrate9600 Baudrate = 5 Baudrate14400 Baudrate = 6 Baudrate19200 Baudrate = 7 Baudrate28800 Baudrate = 8 Baudrate38400 Baudrate = 9 Baudrate57600 Baudrate = 10 Baudrate115200 Baudrate = 11 Baudrate230400 Baudrate = 12 )
type Function ¶
type Function = uint8
const ( FunctionWrite Function = 1 FunctionRead Function = 2 FunctionEnableReadCallback Function = 3 FunctionDisableReadCallback Function = 4 FunctionIsReadCallbackEnabled Function = 5 FunctionSetConfiguration Function = 6 FunctionGetConfiguration Function = 7 FunctionSetBreakCondition Function = 10 FunctionSetFrameReadableCallbackConfiguration Function = 11 FunctionGetFrameReadableCallbackConfiguration Function = 12 FunctionReadFrame Function = 14 FunctionGetIdentity Function = 255 FunctionCallbackRead Function = 8 FunctionCallbackError Function = 9 FunctionCallbackFrameReadable Function = 13 )
type HardwareFlowcontrol ¶
type HardwareFlowcontrol = uint8
const ( HardwareFlowcontrolOff HardwareFlowcontrol = 0 HardwareFlowcontrolOn HardwareFlowcontrol = 1 )
type RS232Bricklet ¶
type RS232Bricklet struct {
// contains filtered or unexported fields
}
func New ¶
func New(uid string, ipcon *ipconnection.IPConnection) (RS232Bricklet, error)
Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ipcon` is connected.
func (*RS232Bricklet) DeregisterErrorCallback ¶
func (device *RS232Bricklet) DeregisterErrorCallback(registrationId uint64)
Remove a registered Error callback.
func (*RS232Bricklet) DeregisterFrameReadableCallback ¶
func (device *RS232Bricklet) DeregisterFrameReadableCallback(registrationId uint64)
Remove a registered Frame Readable callback.
func (*RS232Bricklet) DeregisterReadCallback ¶
func (device *RS232Bricklet) DeregisterReadCallback(registrationId uint64)
Remove a registered Read callback.
func (*RS232Bricklet) DisableReadCallback ¶
func (device *RS232Bricklet) DisableReadCallback() (err error)
Disables the RegisterReadCallback callback.
By default the callback is disabled.
func (*RS232Bricklet) EnableReadCallback ¶
func (device *RS232Bricklet) EnableReadCallback() (err error)
Enables the RegisterReadCallback callback. This will disable the RegisterFrameReadableCallback callback.
By default the callback is disabled.
func (*RS232Bricklet) GetAPIVersion ¶
func (device *RS232Bricklet) 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 (*RS232Bricklet) GetConfiguration ¶
func (device *RS232Bricklet) GetConfiguration() (baudrate Baudrate, parity Parity, stopbits Stopbits, wordlength Wordlength, hardwareFlowcontrol HardwareFlowcontrol, softwareFlowcontrol SoftwareFlowcontrol, err error)
Returns the configuration as set by SetConfiguration.
Associated constants:
- Baudrate300
- Baudrate600
- Baudrate1200
- Baudrate2400
- Baudrate4800
- Baudrate9600
- Baudrate14400
- Baudrate19200
- Baudrate28800
- Baudrate38400
- Baudrate57600
- Baudrate115200
- Baudrate230400
- ParityNone
- ParityOdd
- ParityEven
- ParityForcedParity1
- ParityForcedParity0
- Stopbits1
- Stopbits2
- Wordlength5
- Wordlength6
- Wordlength7
- Wordlength8
- HardwareFlowcontrolOff
- HardwareFlowcontrolOn
- SoftwareFlowcontrolOff
- SoftwareFlowcontrolOn
func (*RS232Bricklet) GetFrameReadableCallbackConfiguration ¶
func (device *RS232Bricklet) GetFrameReadableCallbackConfiguration() (frameSize uint8, err error)
Returns the callback configuration as set by SetFrameReadableCallbackConfiguration.
.. versionadded:: 2.0.4$nbsp;(Plugin)
func (*RS232Bricklet) GetIdentity ¶
func (device *RS232Bricklet) 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 (*RS232Bricklet) GetResponseExpected ¶
func (device *RS232Bricklet) 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 (*RS232Bricklet) IsReadCallbackEnabled ¶
func (device *RS232Bricklet) IsReadCallbackEnabled() (enabled bool, err error)
Returns *true* if the RegisterReadCallback callback is enabled, *false* otherwise.
func (*RS232Bricklet) Read ¶
func (device *RS232Bricklet) Read() (message [60]rune, length uint8, err error)
Returns the currently buffered message. The maximum length of message is 60. If the returned length is 0, no new data was available.
Instead of polling with this function, you can also use callbacks. See EnableReadCallback and RegisterReadCallback callback.
func (*RS232Bricklet) ReadFrame ¶
func (device *RS232Bricklet) ReadFrame() (message [60]rune, length uint8, err error)
Returns up to one frame of bytes from the read buffer. The frame size is configured with SetFrameReadableCallbackConfiguration. If the returned length is 0, no new data was available.
.. versionadded:: 2.0.4$nbsp;(Plugin)
func (*RS232Bricklet) RegisterErrorCallback ¶
func (device *RS232Bricklet) RegisterErrorCallback(fn func(Error)) uint64
This callback is called if an error occurs. Possible errors are overrun, parity or framing error.
.. versionadded:: 2.0.1$nbsp;(Plugin)
func (*RS232Bricklet) RegisterFrameReadableCallback ¶
func (device *RS232Bricklet) RegisterFrameReadableCallback(fn func(uint8)) 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 or ReadFrame is called. This means, that if you have configured a frame size of X bytes, you can read exactly X bytes using the ReadFrame function, every time the callback triggers without checking the frame count parameter.
.. versionadded:: 2.0.4$nbsp;(Plugin)
func (*RS232Bricklet) RegisterReadCallback ¶
func (device *RS232Bricklet) RegisterReadCallback(fn func([60]rune, uint8)) uint64
This callback is called if new data is available. The message has a maximum size of 60 characters. The actual length of the message is given in addition.
To enable this callback, use EnableReadCallback.
func (*RS232Bricklet) SetBreakCondition ¶
func (device *RS232Bricklet) SetBreakCondition(breakTime uint16) (err error)
Sets a break condition (the TX output is forced to a logic 0 state). The parameter sets the hold-time of the break condition.
.. versionadded:: 2.0.2$nbsp;(Plugin)
func (*RS232Bricklet) SetConfiguration ¶
func (device *RS232Bricklet) SetConfiguration(baudrate Baudrate, parity Parity, stopbits Stopbits, wordlength Wordlength, hardwareFlowcontrol HardwareFlowcontrol, softwareFlowcontrol SoftwareFlowcontrol) (err error)
Sets the configuration for the RS232 communication.
Hard-/Software flow control can either be on or off but not both simultaneously on.
Associated constants:
- Baudrate300
- Baudrate600
- Baudrate1200
- Baudrate2400
- Baudrate4800
- Baudrate9600
- Baudrate14400
- Baudrate19200
- Baudrate28800
- Baudrate38400
- Baudrate57600
- Baudrate115200
- Baudrate230400
- ParityNone
- ParityOdd
- ParityEven
- ParityForcedParity1
- ParityForcedParity0
- Stopbits1
- Stopbits2
- Wordlength5
- Wordlength6
- Wordlength7
- Wordlength8
- HardwareFlowcontrolOff
- HardwareFlowcontrolOn
- SoftwareFlowcontrolOff
- SoftwareFlowcontrolOn
func (*RS232Bricklet) SetFrameReadableCallbackConfiguration ¶
func (device *RS232Bricklet) SetFrameReadableCallbackConfiguration(frameSize uint8) (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.4$nbsp;(Plugin)
func (*RS232Bricklet) SetResponseExpected ¶
func (device *RS232Bricklet) 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 (*RS232Bricklet) SetResponseExpectedAll ¶
func (device *RS232Bricklet) SetResponseExpectedAll(responseExpected bool)
Changes the response expected flag for all setter and callback configuration functions of this device at once.
func (*RS232Bricklet) Write ¶
func (device *RS232Bricklet) Write(message [60]rune, length uint8) (written uint8, err error)
Writes a string of up to 60 characters to the RS232 interface. The string can be binary data, ASCII or similar is not necessary.
The length of the string has to be given as an additional parameter.
The return value is the number of bytes that could be written.
See SetConfiguration for configuration possibilities regarding baudrate, parity and so on.
type SoftwareFlowcontrol ¶
type SoftwareFlowcontrol = uint8
const ( SoftwareFlowcontrolOff SoftwareFlowcontrol = 0 SoftwareFlowcontrolOn SoftwareFlowcontrol = 1 )
type Wordlength ¶
type Wordlength = uint8
const ( Wordlength5 Wordlength = 5 Wordlength6 Wordlength = 6 Wordlength7 Wordlength = 7 Wordlength8 Wordlength = 8 )