Documentation ¶
Index ¶
- Constants
- Variables
- type Device
- func (d *Device) Close() error
- func (d *Device) GetSerialNumber() (sn SerialNumber, err error)
- func (d *Device) Info() (serialNumber SerialNumber, vendorID int, productID int, relayCount int)
- func (d *Device) Off(ch RelayNumber) error
- func (d *Device) On(ch RelayNumber) error
- func (d *Device) Open(readState bool) (err error)
- func (d *Device) RelayCount() int
- func (d *Device) SetSerialNumber(sn SerialNumber) (err error)
- func (d *Device) States() (map[RelayNumber]State, error)
- func (d *Device) String() string
- func (d *Device) Toggle(ch RelayNumber) error
- type RelayNumber
- type SerialNumber
- type State
Constants ¶
const ( DeviceVendorID uint16 = 0x16c0 DeviceProductID uint16 = 0x05DF UdevVendorID string = "16c0" UdevProductID string = "05df" )
Variables ¶
var ( ErrNoDeviceFound = errors.New("no device found") ErrDeviceOpen = errors.New("cannot connect to device") ErrDeviceInfoNotFound = errors.New("cannot connect to device, device information not found") ErrDeviceNotConnected = errors.New("device is not connected, call Open()") ErrInvalidNumberOfRelays = errors.New("invalid number of relays found") ErrRelayStateNotSet = errors.New("relay state could not be set") ErrInvalidSerialNumber = errors.New("invalid serial number") ErrInvalidRelayNumber = errors.New("invalid relay number") )
Error types
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a USB HID relay device
func GetDeviceBySerialNumber ¶
func GetDeviceBySerialNumber(sn SerialNumber) (*Device, error)
func (*Device) GetSerialNumber ¶
func (d *Device) GetSerialNumber() (sn SerialNumber, err error)
GetSerialNumber reads the serial number from the device
func (*Device) Info ¶
func (d *Device) Info() (serialNumber SerialNumber, vendorID int, productID int, relayCount int)
Info returns the basic information about the device as a tuple
func (*Device) Off ¶
func (d *Device) Off(ch RelayNumber) error
Off sets one or all of the relays state on the device to OFF
func (*Device) On ¶
func (d *Device) On(ch RelayNumber) error
On sets one or all of the relays state on the device to ON
func (*Device) RelayCount ¶
RelayCount returns the number of relays found on the device
func (*Device) SetSerialNumber ¶
func (d *Device) SetSerialNumber(sn SerialNumber) (err error)
SetSerialNumber writes the serial number on the device
func (*Device) States ¶
func (d *Device) States() (map[RelayNumber]State, error)
States returns the state of all the relays on the device
func (*Device) Toggle ¶
func (d *Device) Toggle(ch RelayNumber) error
Toggle the state of one or all of the relays on the device
type RelayNumber ¶
type RelayNumber int
RelayNumber is the relay's identifier on the device
Valid identifier can be found by calling Device.RelayCount
const ( R1 RelayNumber = iota + 1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R_ALL = 1000 )
Available RelayNumber(s)
type SerialNumber ¶
type SerialNumber string
SerialNumber is the device's unique identifier
func NewSerialNumber ¶
func NewSerialNumber(s string) SerialNumber
NewSerialNumber returns an array of characters with the length of 5