Created
May 10, 2016 02:23
-
-
Save souenzzo/9e3726c332a960deb91df298e8405668 to your computer and use it in GitHub Desktop.
Read a serial and write on http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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