Read a serial and write on http
package main | |
import ( | |
// "fmt" | |
// "io" | |
"net/http" | |
"os" | |
) | |
func readSerial(w http.ResponseWriter, r *http.Request) { | |
ser, err := os.Open("./COM9") | |
if err != nil { | |
print("ERRO AO ABRIR COM9") | |
os.Exit(1) | |
} | |
buf := make([]byte, 4000) | |
ser.Read(buf) | |
w.Write(buf) | |
ser.Close() | |
} | |
func main() { | |
http.HandleFunc("/read", readSerial) | |
http.ListenAndServe(":3001", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment