From 198023be0f62ef6bb35cdd5ae78f90ab0a6f187e Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 19 Jun 2021 10:23:29 +0200 Subject: Update Python / Golang Interface --- src/camera.go | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/camera.go') diff --git a/src/camera.go b/src/camera.go index 86c0fb1..519cc65 100644 --- a/src/camera.go +++ b/src/camera.go @@ -5,7 +5,9 @@ package main import ( "log" "os/exec" - "io" + "os" + "path/filepath" + "bufio" ) type Camera struct { @@ -51,9 +53,16 @@ func singlePicture(m *Machine) { // create command var cmd *exec.Cmd if !config.Flag.Debug { - cmd = exec.Command("python3", "/usr/lib/python3.9/site-packages/birdscan/") - } else { - cmd = exec.Command("python3", "../python/birdscan", "--debug") // FIXME relative paths do not work in exec.Command! + cmd = exec.Command("/usr/bin/python3", "/usr/lib/python3.9/site-packages/birdscan/") + } else { // debug mode + pwd,err := os.Getwd() + if err != nil { + log.Fatal(err) + } + repoDir := filepath.Dir(pwd) + log.Printf("Repository path is assumed to be = '%s'", repoDir) + pythonPackage := repoDir + "/python/birdscan" + cmd = exec.Command("/usr/bin/python3", pythonPackage, "--debug") } // connect stdout of python process @@ -68,10 +77,16 @@ func singlePicture(m *Machine) { if err != nil { log.Print(err) } - _,err = io.ReadAll(stdout) - if err != nil { - log.Print(err) + + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + text := scanner.Text() + log.Printf("Python returned '%s'", text) + if text == "ok" { + break + } } + err = cmd.Wait() // wait until command execution and io is complete if err != nil { log.Print(err) @@ -84,3 +99,8 @@ func singlePicture(m *Machine) { func (cam *Camera) run() { cam.statemachine.Run() } + +// read until '\n' +func readLine(buff *[]byte, ) { + +} -- cgit v1.2.3-70-g09d2