Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active June 19, 2023 09:06
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 bodokaiser/c690db287863eb4ca9913743c2aa0c39 to your computer and use it in GitHub Desktop.
Save bodokaiser/c690db287863eb4ca9913743c2aa0c39 to your computer and use it in GitHub Desktop.
Stanford Research Instruments PTC10

Stanford Research Instruments PTC10

Usage

go run main.go > time_date.csv

Show help for optional arguments:

go run main.go -h
package main
import (
"context"
"flag"
"io"
"log"
"net"
"os"
"time"
)
var hostname string
var connTimeout float64
var samplePeriod float64
func main() {
flag.StringVar(&hostname, "hostname", "10.163.103.187:23", "The hostname of the SRC PTC01 controller")
flag.Float64Var(&connTimeout, "connection-timeout", 5, "The timeout of the connection in seconds")
flag.Float64Var(&samplePeriod, "sample-period", 1, "The sample period in seconds")
flag.Parse()
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(connTimeout)*time.Second)
defer cancel()
var d net.Dialer
conn, err := d.DialContext(ctx, "tcp", hostname)
if err != nil {
log.Fatalf("failed to connect to %s: %s", hostname, err)
}
defer conn.Close()
go func() {
_, err := io.Copy(os.Stdout, conn)
if err != nil {
log.Fatalf("failed to receive data: %s", err)
}
}()
if err := requestHeader(conn); err != nil {
log.Fatalf("failed to request headers: %s", err)
}
for range time.Tick(time.Second * time.Duration(samplePeriod)) {
requestRecord(conn)
}
}
func requestHeader(conn net.Conn) error {
_, err := conn.Write([]byte("getOutput.names\r\n"))
return err
}
func requestRecord(conn net.Conn) error {
_, err := conn.Write([]byte("getOutputs\r\n"))
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment