drok: github.com/MrDoctorKovacic/drok Index | Files | Directories

package drok

import "github.com/MrDoctorKovacic/drok"

Package drok is a simple lib for interfacing with a variety of DROK Buck / Boost power supplies. main.go describes the user facing functions, while the heavy serial lifting is done in drok.go.

Example usage:

package examples

import (
	"fmt"

	drok "github.com/MrDoctorKovacic/drok"
	"github.com/tarm/serial"
)

func main() {
	c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 4800}
	drokDevice, err := serial.OpenPort(c)
	if err != nil {
		panic("Failed to open serial port")
	}

	// Read output
	isOn, err := drok.IsOn(drokDevice)
	if err != nil {
		panic(err.Error())
	}
	if isOn {
		fmt.Println("DROK power supply is turned on")
	} else {
		fmt.Println("DROK power supply is turned off")
	}

	// Read output voltage
	voltage, err := drok.ReadVoltage(drokDevice)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("Output voltage limit set to: %f\n", voltage)

	// Read output current
	current, err := drok.ReadCurrent(drokDevice)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("Output current set to: %f\n", current)

	// Set output to true (enabling power output)
	err = drok.SetOutput(drokDevice, true)
	if err != nil {
		panic(err.Error())
	}

	// Set output voltage to 12.3v
	err = drok.SetVoltage(drokDevice, 12.3)
	if err != nil {
		panic(err.Error())
	}

	// Set output current limit to 0.95A
	err = drok.SetCurrent(drokDevice, 0.95)
	if err != nil {
		panic(err.Error())
	}

}

Index

Package Files

drok.go main.go

func IsOn Uses

func IsOn(device *serial.Port) (bool, error)

IsOn will return true if output is enabled

func ReadCurrent Uses

func ReadCurrent(device *serial.Port) (float32, error)

ReadCurrent will read the output current with a resolution of 2 decimal places. This is the current flowing through the PSU at any given time, not the current limit.

func ReadVoltage Uses

func ReadVoltage(device *serial.Port) (float32, error)

ReadVoltage will read the output voltage with a resolution of 2 decimal places

func SetCurrent Uses

func SetCurrent(device *serial.Port, value float32) error

SetCurrent will set the current limit with a resolution of 2 decimal places

func SetOutput Uses

func SetOutput(device *serial.Port, output bool) error

SetOutput will turn on or off power supply output

func SetVoltage Uses

func SetVoltage(device *serial.Port, value float32) error

SetVoltage will set the voltage with a resolution of 2 decimal places

Directories

PathSynopsis
examples

Package drok imports 5 packages (graph) and is imported by 2 packages. Updated 2019-09-30. Refresh now. Tools for package owners.