Documentation ¶
Overview ¶
goiio is a pure golang client for IIO (industrial I/O)
Introduction ¶
go-iio was written to access remote iiod instanced, since libiio does not seem to have golang bindings by itself. It's main use case is connecting with remote IIOd instances: local IIO access is out of scope, you'll need to run iiod.
See https://github.com/analogdevicesinc/libiio
Example ¶
The following example shows an example on how to use this library
c, err := goiio.New("my-sensor.home.lan:30431") if err != nil { panic(err) } // Populate the values in attributes if err = c.FetchAttributes(); err != nil { panic(err) } // for _, dev := range c.Context.Devices { log.Infof("Device: id=%s, name=%s", dev.ID, dev.Name) for _, ch := range dev.Channels { log.Infof(" Channel: id=%s", ch.ID) for _, attr := range ch.Attributes { log.Infof(" Attribute: %s, value: %0.3f", attr.Name, attr.Value) } } }
Index ¶
- type Channel
- type ChannelAttribute
- type CompareChannel
- type CompareChannelAttribute
- type CompareContextAttribute
- type CompareDevice
- type Context
- func (c *Context) GetAttribute(comp CompareContextAttribute) *ContextAttribute
- func (c *Context) GetAttributeByName(name string) *ContextAttribute
- func (h *Context) GetDevice(comp CompareDevice) *Device
- func (c *Context) GetDeviceByID(id string) *Device
- func (c *Context) GetDeviceByName(name string) *Device
- func (c *Context) GetDeviceByNameOrID(name, id *string) *Device
- type ContextAttribute
- type Device
- type IIO
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct { ID string `xml:"id,attr"` // ID of the channel, e.g. "temp" Type string `xml:"type,attr"` // Type of the channel, e.g. "input" Attributes []*ChannelAttribute `xml:"attribute"` // List of attributes of the channel }
Channels holds all information related to a channel in a IIO device
func (*Channel) GetAttrByName ¶
func (c *Channel) GetAttrByName(name string) *ChannelAttribute
GetAttrByName fetches the first attribute with given name
func (*Channel) GetAttribute ¶
func (c *Channel) GetAttribute(comp CompareChannelAttribute) *ChannelAttribute
GetAttribute fetches the first attribute from the channel satisfying the comparison function
type ChannelAttribute ¶
type ChannelAttribute struct { Name string `xml:"name,attr"` // Name of the attribute, e.g. "oversampling_ratio" Filename string `xml:"filename,attr"` // Filename of the attribute in sysfs, e.g. "in_pressure_oversampling_ratio" Value float64 `xml:"value,attr,omitempty"` // Value of the attribute }
ChannelAttribute is the data structure describing an attribute of a channel
type CompareChannel ¶
CompareChannel is a type passed to Device.GetChannel implementing some kind of comparison function
type CompareChannelAttribute ¶
type CompareChannelAttribute func(*ChannelAttribute) bool
CompareChannelAttribute is a type passed to Channel.GetAttribute implementing some kind of comparison function
type CompareContextAttribute ¶
type CompareContextAttribute func(*ContextAttribute) bool
CompareContextAttribute is a type passed to Context.GetAttribute implementing some kind of comparison function
type CompareDevice ¶
CompareDevice is a type passed to Context.GetDevice implementing some kind of comparison function
type Context ¶
type Context struct { XMLName xml.Name `xml:"context"` // Not sure where this is for Name string `xml:"name,attr"` // The name of the context Description string `xml:"description,attr"` // Description of the context ContextAttributes []*ContextAttribute `xml:"context-attribute"` // Attributes that apply to the context Devices []*Device `xml:"device"` // Devices connected. This is probably what you need }
Context holds the context of the remote IIOd
func (*Context) GetAttribute ¶
func (c *Context) GetAttribute(comp CompareContextAttribute) *ContextAttribute
GetAttribute fetches the first attribute from the context satisfying the comparison function
func (*Context) GetAttributeByName ¶
func (c *Context) GetAttributeByName(name string) *ContextAttribute
GetAttributeByName fetches the first attribute with given name
func (*Context) GetDevice ¶
func (h *Context) GetDevice(comp CompareDevice) *Device
GetDevice fetches the first device from the context satisfying the comparison function
func (*Context) GetDeviceByID ¶
GetDeviceByID fetches the first device with given name
func (*Context) GetDeviceByName ¶
GetDeviceByName fetches the first device with given name
func (*Context) GetDeviceByNameOrID ¶
GetDeviceByNameOrID fetches the first device that does not mismatch given name or id. If only name is given, it behaves like GetDeviceByName and when only id is given like GetDeviceByID. When both are given, it matches on both attributes and when none are given, it matches any first device.
type ContextAttribute ¶
type ContextAttribute struct { Name string `xml:"name,attr"` // Name of the attribute, e.g. "local,kernel" Value string `xml:"value,attr"` // Value of the attribute, e.g. "5.11.0-40-generic" }
ContextAttribute is the data structure containing attributes relating to the context
type Device ¶
type Device struct { ID string `xml:"id,attr"` // Identifier, e.g. "iio:device0" Name string `xml:"name,attr"` // Name of the device, e.g. "bme280" Channels []*Channel `xml:"channel"` // List of channels in the device }
Device holds information regarding IIO device
func (*Device) GetChannel ¶
func (d *Device) GetChannel(comp CompareChannel) *Channel
GetChannel fetches the first channel from the device satisfying the comparison function
func (*Device) GetChannelByID ¶
GetChannelByID fetches the first attribute with given ID
type IIO ¶
type IIO struct { Context *Context // contains the context of the remote iiod instance // contains filtered or unexported fields }
IIO is the client connecting to a (remote) iiod
func (*IIO) CreateBuffer ¶
func (*IIO) DestroyBuffer ¶
func (*IIO) FetchAttributes ¶
Fetch all attributes for all devices