Skip to content

gogogoghost/libudevgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libudev binding for go

GoDoc

loading libudev.so with dynamic loading at runtime by libffigo

usage

get this module

go get github.com/gogogoghost/libudevgo

init and create context

udev.init()
ctx, err := udev.NewContext()
if err != nil {
    panic(err)
}

enumerate device

enumerator, err := udev.NewEnumerator(ctx)
if err != nil {
    panic(err)
}
for _, dev := range enumerator.List() {
    //read device
}

monitor event

monitor, err := udev.NewMonitor(ctx, udev.UDEV)
if err != nil {
    panic(err)
}
monitor.AddFilter("tty", "")
channel, err := monitor.StartMonitor()
if err != nil {
    panic(err)
}
for {
    evt := <-channel
    //read event and device
}