communication working on server and client mode
This commit is contained in:
BIN
ICS42_ICS43_User_Manual_EN-1.pdf
Normal file
BIN
ICS42_ICS43_User_Manual_EN-1.pdf
Normal file
Binary file not shown.
32
README.md
32
README.md
@@ -1,4 +1,34 @@
|
||||
# mettler-toledo
|
||||
|
||||
Test bench for communication with Mettler Toledo scale
|
||||
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
|
||||
|
||||
|
||||
41
client.go
Normal file
41
client.go
Normal file
@@ -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()
|
||||
}
|
||||
59
server.go
Normal file
59
server.go
Normal file
@@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user