Skip to content

Instantly share code, notes, and snippets.

@souenzzo souenzzo/server.go
Created May 10, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.