voltage_current_bricklet

package
v0.0.0-...-8a98e63 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Overview

Measures power, DC voltage and DC current up to 720W/36V/20A‍.

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

Index

Constants

View Source
const DeviceDisplayName = "Voltage/Current Bricklet"
View Source
const DeviceIdentifier = 227

Variables

This section is empty.

Functions

This section is empty.

Types

type Averaging

type Averaging = uint8
const (
	Averaging1    Averaging = 0
	Averaging4    Averaging = 1
	Averaging16   Averaging = 2
	Averaging64   Averaging = 3
	Averaging128  Averaging = 4
	Averaging256  Averaging = 5
	Averaging512  Averaging = 6
	Averaging1024 Averaging = 7
)

type ConversionTime

type ConversionTime = uint8
const (
	ConversionTime140us   ConversionTime = 0
	ConversionTime204us   ConversionTime = 1
	ConversionTime332us   ConversionTime = 2
	ConversionTime588us   ConversionTime = 3
	ConversionTime1_1ms   ConversionTime = 4
	ConversionTime2_116ms ConversionTime = 5
	ConversionTime4_156ms ConversionTime = 6
	ConversionTime8_244ms ConversionTime = 7
)

type Function

type Function = uint8
const (
	FunctionGetCurrent                  Function = 1
	FunctionGetVoltage                  Function = 2
	FunctionGetPower                    Function = 3
	FunctionSetConfiguration            Function = 4
	FunctionGetConfiguration            Function = 5
	FunctionSetCalibration              Function = 6
	FunctionGetCalibration              Function = 7
	FunctionSetCurrentCallbackPeriod    Function = 8
	FunctionGetCurrentCallbackPeriod    Function = 9
	FunctionSetVoltageCallbackPeriod    Function = 10
	FunctionGetVoltageCallbackPeriod    Function = 11
	FunctionSetPowerCallbackPeriod      Function = 12
	FunctionGetPowerCallbackPeriod      Function = 13
	FunctionSetCurrentCallbackThreshold Function = 14
	FunctionGetCurrentCallbackThreshold Function = 15
	FunctionSetVoltageCallbackThreshold Function = 16
	FunctionGetVoltageCallbackThreshold Function = 17
	FunctionSetPowerCallbackThreshold   Function = 18
	FunctionGetPowerCallbackThreshold   Function = 19
	FunctionSetDebouncePeriod           Function = 20
	FunctionGetDebouncePeriod           Function = 21
	FunctionGetIdentity                 Function = 255
	FunctionCallbackCurrent             Function = 22
	FunctionCallbackVoltage             Function = 23
	FunctionCallbackPower               Function = 24
	FunctionCallbackCurrentReached      Function = 25
	FunctionCallbackVoltageReached      Function = 26
	FunctionCallbackPowerReached        Function = 27
)

type ThresholdOption

type ThresholdOption = rune
const (
	ThresholdOptionOff     ThresholdOption = 'x'
	ThresholdOptionOutside ThresholdOption = 'o'
	ThresholdOptionInside  ThresholdOption = 'i'
	ThresholdOptionSmaller ThresholdOption = '<'
	ThresholdOptionGreater ThresholdOption = '>'
)

type VoltageCurrentBricklet

type VoltageCurrentBricklet 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 (*VoltageCurrentBricklet) DeregisterCurrentCallback

func (device *VoltageCurrentBricklet) DeregisterCurrentCallback(registrationId uint64)

Remove a registered Current callback.

func (*VoltageCurrentBricklet) DeregisterCurrentReachedCallback

func (device *VoltageCurrentBricklet) DeregisterCurrentReachedCallback(registrationId uint64)

Remove a registered Current Reached callback.

func (*VoltageCurrentBricklet) DeregisterPowerCallback

func (device *VoltageCurrentBricklet) DeregisterPowerCallback(registrationId uint64)

Remove a registered Power callback.

func (*VoltageCurrentBricklet) DeregisterPowerReachedCallback

func (device *VoltageCurrentBricklet) DeregisterPowerReachedCallback(registrationId uint64)

Remove a registered Power Reached callback.

func (*VoltageCurrentBricklet) DeregisterVoltageCallback

func (device *VoltageCurrentBricklet) DeregisterVoltageCallback(registrationId uint64)

Remove a registered Voltage callback.

func (*VoltageCurrentBricklet) DeregisterVoltageReachedCallback

func (device *VoltageCurrentBricklet) DeregisterVoltageReachedCallback(registrationId uint64)

Remove a registered Voltage Reached callback.

func (*VoltageCurrentBricklet) GetAPIVersion

func (device *VoltageCurrentBricklet) 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 (*VoltageCurrentBricklet) GetCalibration

func (device *VoltageCurrentBricklet) GetCalibration() (gainMultiplier uint16, gainDivisor uint16, err error)

Returns the calibration as set by SetCalibration.

func (*VoltageCurrentBricklet) GetConfiguration

func (device *VoltageCurrentBricklet) GetConfiguration() (averaging Averaging, voltageConversionTime ConversionTime, currentConversionTime ConversionTime, err error)

Returns the configuration as set by SetConfiguration.

Associated constants:

  • Averaging1
  • Averaging4
  • Averaging16
  • Averaging64
  • Averaging128
  • Averaging256
  • Averaging512
  • Averaging1024
  • ConversionTime140us
  • ConversionTime204us
  • ConversionTime332us
  • ConversionTime588us
  • ConversionTime11ms
  • ConversionTime2116ms
  • ConversionTime4156ms
  • ConversionTime8244ms

func (*VoltageCurrentBricklet) GetCurrent

func (device *VoltageCurrentBricklet) GetCurrent() (current int32, err error)

Returns the current.

If you want to get the current periodically, it is recommended to use the RegisterCurrentCallback callback and set the period with SetCurrentCallbackPeriod.

func (*VoltageCurrentBricklet) GetCurrentCallbackPeriod

func (device *VoltageCurrentBricklet) GetCurrentCallbackPeriod() (period uint32, err error)

Returns the period as set by SetCurrentCallbackPeriod.

func (*VoltageCurrentBricklet) GetCurrentCallbackThreshold

func (device *VoltageCurrentBricklet) GetCurrentCallbackThreshold() (option ThresholdOption, min int32, max int32, err error)

Returns the threshold as set by SetCurrentCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*VoltageCurrentBricklet) GetDebouncePeriod

func (device *VoltageCurrentBricklet) GetDebouncePeriod() (debounce uint32, err error)

Returns the debounce period as set by SetDebouncePeriod.

func (*VoltageCurrentBricklet) GetIdentity

func (device *VoltageCurrentBricklet) 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 (*VoltageCurrentBricklet) GetPower

func (device *VoltageCurrentBricklet) GetPower() (power int32, err error)

Returns the power.

If you want to get the power periodically, it is recommended to use the RegisterPowerCallback callback and set the period with SetPowerCallbackPeriod.

func (*VoltageCurrentBricklet) GetPowerCallbackPeriod

func (device *VoltageCurrentBricklet) GetPowerCallbackPeriod() (period uint32, err error)

Returns the period as set by GetPowerCallbackPeriod.

func (*VoltageCurrentBricklet) GetPowerCallbackThreshold

func (device *VoltageCurrentBricklet) GetPowerCallbackThreshold() (option ThresholdOption, min int32, max int32, err error)

Returns the threshold as set by SetPowerCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*VoltageCurrentBricklet) GetResponseExpected

func (device *VoltageCurrentBricklet) 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 (*VoltageCurrentBricklet) GetVoltage

func (device *VoltageCurrentBricklet) GetVoltage() (voltage int32, err error)

Returns the voltage.

If you want to get the voltage periodically, it is recommended to use the RegisterVoltageCallback callback and set the period with SetVoltageCallbackPeriod.

func (*VoltageCurrentBricklet) GetVoltageCallbackPeriod

func (device *VoltageCurrentBricklet) GetVoltageCallbackPeriod() (period uint32, err error)

Returns the period as set by SetVoltageCallbackPeriod.

func (*VoltageCurrentBricklet) GetVoltageCallbackThreshold

func (device *VoltageCurrentBricklet) GetVoltageCallbackThreshold() (option ThresholdOption, min int32, max int32, err error)

Returns the threshold as set by SetVoltageCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*VoltageCurrentBricklet) RegisterCurrentCallback

func (device *VoltageCurrentBricklet) RegisterCurrentCallback(fn func(int32)) uint64

This callback is triggered periodically with the period that is set by SetCurrentCallbackPeriod. The parameter is the current of the sensor.

The RegisterCurrentCallback callback is only triggered if the current has changed since the last triggering.

func (*VoltageCurrentBricklet) RegisterCurrentReachedCallback

func (device *VoltageCurrentBricklet) RegisterCurrentReachedCallback(fn func(int32)) uint64

This callback is triggered when the threshold as set by SetCurrentCallbackThreshold is reached. The parameter is the current of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by SetDebouncePeriod.

func (*VoltageCurrentBricklet) RegisterPowerCallback

func (device *VoltageCurrentBricklet) RegisterPowerCallback(fn func(int32)) uint64

This callback is triggered periodically with the period that is set by SetPowerCallbackPeriod. The parameter is the power of the sensor.

The RegisterPowerCallback callback is only triggered if the power has changed since the last triggering.

func (*VoltageCurrentBricklet) RegisterPowerReachedCallback

func (device *VoltageCurrentBricklet) RegisterPowerReachedCallback(fn func(int32)) uint64

This callback is triggered when the threshold as set by SetPowerCallbackThreshold is reached. The parameter is the power of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by SetDebouncePeriod.

func (*VoltageCurrentBricklet) RegisterVoltageCallback

func (device *VoltageCurrentBricklet) RegisterVoltageCallback(fn func(int32)) uint64

This callback is triggered periodically with the period that is set by SetVoltageCallbackPeriod. The parameter is the voltage of the sensor.

The RegisterVoltageCallback callback is only triggered if the voltage has changed since the last triggering.

func (*VoltageCurrentBricklet) RegisterVoltageReachedCallback

func (device *VoltageCurrentBricklet) RegisterVoltageReachedCallback(fn func(int32)) uint64

This callback is triggered when the threshold as set by SetVoltageCallbackThreshold is reached. The parameter is the voltage of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by SetDebouncePeriod.

func (*VoltageCurrentBricklet) SetCalibration

func (device *VoltageCurrentBricklet) SetCalibration(gainMultiplier uint16, gainDivisor uint16) (err error)

Since the shunt resistor that is used to measure the current is not perfectly precise, it needs to be calibrated by a multiplier and divisor if a very precise reading is needed.

For example, if you are expecting a measurement of 1000mA and you are measuring 1023mA, you can calibrate the Voltage/Current Bricklet by setting the multiplier to 1000 and the divisor to 1023.

func (*VoltageCurrentBricklet) SetConfiguration

func (device *VoltageCurrentBricklet) SetConfiguration(averaging Averaging, voltageConversionTime ConversionTime, currentConversionTime ConversionTime) (err error)

Sets the configuration of the Voltage/Current Bricklet. It is possible to configure number of averages as well as voltage and current conversion time.

Associated constants:

  • Averaging1
  • Averaging4
  • Averaging16
  • Averaging64
  • Averaging128
  • Averaging256
  • Averaging512
  • Averaging1024
  • ConversionTime140us
  • ConversionTime204us
  • ConversionTime332us
  • ConversionTime588us
  • ConversionTime11ms
  • ConversionTime2116ms
  • ConversionTime4156ms
  • ConversionTime8244ms

func (*VoltageCurrentBricklet) SetCurrentCallbackPeriod

func (device *VoltageCurrentBricklet) SetCurrentCallbackPeriod(period uint32) (err error)

Sets the period with which the RegisterCurrentCallback callback is triggered periodically. A value of 0 turns the callback off.

The RegisterCurrentCallback callback is only triggered if the current has changed since the last triggering.

func (*VoltageCurrentBricklet) SetCurrentCallbackThreshold

func (device *VoltageCurrentBricklet) SetCurrentCallbackThreshold(option ThresholdOption, min int32, max int32) (err error)

Sets the thresholds for the RegisterCurrentReachedCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Callback is turned off
'o'|    Callback is triggered when the current is *outside* the min and max values
'i'|    Callback is triggered when the current is *inside* the min and max values
'<'|    Callback is triggered when the current is smaller than the min value (max is ignored)
'>'|    Callback is triggered when the current is greater than the min value (max is ignored)

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*VoltageCurrentBricklet) SetDebouncePeriod

func (device *VoltageCurrentBricklet) SetDebouncePeriod(debounce uint32) (err error)

Sets the period with which the threshold callbacks

* RegisterCurrentReachedCallback, * RegisterVoltageReachedCallback, * RegisterPowerReachedCallback

are triggered, if the thresholds

* SetCurrentCallbackThreshold, * SetVoltageCallbackThreshold, * SetPowerCallbackThreshold

keep being reached.

func (*VoltageCurrentBricklet) SetPowerCallbackPeriod

func (device *VoltageCurrentBricklet) SetPowerCallbackPeriod(period uint32) (err error)

Sets the period with which the RegisterPowerCallback callback is triggered periodically. A value of 0 turns the callback off.

The RegisterPowerCallback callback is only triggered if the power has changed since the last triggering.

func (*VoltageCurrentBricklet) SetPowerCallbackThreshold

func (device *VoltageCurrentBricklet) SetPowerCallbackThreshold(option ThresholdOption, min int32, max int32) (err error)

Sets the thresholds for the RegisterPowerReachedCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Callback is turned off
'o'|    Callback is triggered when the power is *outside* the min and max values
'i'|    Callback is triggered when the power is *inside* the min and max values
'<'|    Callback is triggered when the power is smaller than the min value (max is ignored)
'>'|    Callback is triggered when the power is greater than the min value (max is ignored)

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*VoltageCurrentBricklet) SetResponseExpected

func (device *VoltageCurrentBricklet) 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 (*VoltageCurrentBricklet) SetResponseExpectedAll

func (device *VoltageCurrentBricklet) SetResponseExpectedAll(responseExpected bool)

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

func (*VoltageCurrentBricklet) SetVoltageCallbackPeriod

func (device *VoltageCurrentBricklet) SetVoltageCallbackPeriod(period uint32) (err error)

Sets the period with which the RegisterVoltageCallback callback is triggered periodically. A value of 0 turns the callback off.

The RegisterVoltageCallback callback is only triggered if the voltage has changed since the last triggering.

func (*VoltageCurrentBricklet) SetVoltageCallbackThreshold

func (device *VoltageCurrentBricklet) SetVoltageCallbackThreshold(option ThresholdOption, min int32, max int32) (err error)

Sets the thresholds for the RegisterVoltageReachedCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Callback is turned off
'o'|    Callback is triggered when the voltage is *outside* the min and max values
'i'|    Callback is triggered when the voltage is *inside* the min and max values
'<'|    Callback is triggered when the voltage is smaller than the min value (max is ignored)
'>'|    Callback is triggered when the voltage is greater than the min value (max is ignored)

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

Jump to

Keyboard shortcuts

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