Skip to content

Instantly share code, notes, and snippets.

@souenzzo
Created May 10, 2016 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souenzzo/9e3726c332a960deb91df298e8405668 to your computer and use it in GitHub Desktop.
Save souenzzo/9e3726c332a960deb91df298e8405668 to your computer and use it in GitHub Desktop.
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