diff --git a/ICS42_ICS43_User_Manual_EN-1.pdf b/ICS42_ICS43_User_Manual_EN-1.pdf new file mode 100644 index 0000000..72fd9bb Binary files /dev/null and b/ICS42_ICS43_User_Manual_EN-1.pdf differ diff --git a/README.md b/README.md index 68b1fbb..a67705b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,34 @@ # mettler-toledo -Test bench for communication with Mettler Toledo scale -specific model ICS 425 \ No newline at end of file +Test bench for communication with Mettler Toledo scale. +specific model ICS 425 + +## Modes +Mettler Toledo scales have several ways to provide weight data. For our purpose the __Server__ or __Client__ options are the best match. +Check manual section 3.6 Communication menu block (page 40) + +### Server mode +The scale act as a server, on which is listening at specific IP address and port waiting for a comand. +To request weight data the following command must be send to the scale controller +```` + S\r\n +```` +*\r\n means CR LF* + + +#### Server mode configuration + + + +### Client mode +The scale act as a client pushing continuos data to the server, configured as specific IP address and port + +Scale is contious sending data: +```` +S S 0.000 kg + +S S 0.000 kg +```` + +#### Client mode configuration + diff --git a/client.go b/client.go new file mode 100644 index 0000000..ad2c482 --- /dev/null +++ b/client.go @@ -0,0 +1,41 @@ +package main +import ( + "net" + "os" +) + +func main() { + strEcho := "SI\r\n" + servAddr := "192.168.8.9:4305" + tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr) + if err != nil { + println("ResolveTCPAddr failed:", err.Error()) + os.Exit(1) + } + + conn, err := net.DialTCP("tcp", nil, tcpAddr) + if err != nil { + println("Dial failed:", err.Error()) + os.Exit(1) + } + + _, err = conn.Write([]byte(strEcho)) + if err != nil { + println("Write to server failed:", err.Error()) + os.Exit(1) + } + + println("write to server = ", strEcho) + + reply := make([]byte, 1024) + + _, err = conn.Read(reply) + if err != nil { + println("Write to server failed:", err.Error()) + os.Exit(1) + } + + println("reply from server=", string(reply)) + + conn.Close() +} diff --git a/server.go b/server.go new file mode 100644 index 0000000..b4d9a41 --- /dev/null +++ b/server.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "net" + "os" +) + +const ( + CONN_HOST = "192.168.8.177" + CONN_PORT = "3333" + CONN_TYPE = "tcp" + CONN_URL = CONN_HOST + ":" + CONN_PORT +) + +func main() { + // Listen for incoming connections + l, err := net.Listen(CONN_TYPE, CONN_URL) + + if err != nil { + fmt.Println("Error listening:", err.Error()) + os.Exit(1) + } + + // Close the listener when this application closes + defer l.Close() + + fmt.Println("Listening on " + CONN_URL) + for { + // Listen for connections + conn, err := l.Accept() + + if err != nil { + fmt.Println("Error accepting connection:", err.Error()) + os.Exit(1) + } + + go handleRequest(conn) + } +} + +func handleRequest(conn net.Conn) { + // Buffer that holds incoming information + buf := make([]byte, 1024) + + for { + len, err := conn.Read(buf) + + if err != nil { + fmt.Println("Error reading:", err.Error()) + break + } + + s := string(buf[:len]) + + fmt.Println(s) + + } +} \ No newline at end of file