-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
48 lines (37 loc) · 1.32 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package scpi
import (
"context"
"time"
)
// Client is a client of a device controlled using SCPI commands.
type Client interface {
// Close closes the connection.
Close() error
// Exec executes a SCPI command.
Exec(cmd string) error
// ExecContext executes a SCPI command.
ExecContext(ctx context.Context, cmd string) error
// BulkExec executes multiple SCPI commands.
BulkExec(cmds ...string) error
// BulkExecContext executes multiple SCPI commands.
BulkExecContext(ctx context.Context, cmds ...string) error
// Ping verifies the connection to the device is still alive,
// establishing a connection if necessary.
Ping() error
// PingContext verifies the connection to the device is still alive,
// establishing a connection if necessary.
PingContext(ctx context.Context) error
// Query queries the device for the results of the specified command.
Query(cmd string) (res string, err error)
// QueryContext queries the device for the results of the specified command.
QueryContext(ctx context.Context, cmd string) (res string, err error)
}
// NewClient returns a new client of a device controlled using SCPI commands.
func NewClient(proto, addr string, timeout time.Duration) (Client, error) {
switch proto {
case "tcp":
return NewTCPClient(addr, timeout)
default:
return nil, InvalidProtocolError(proto)
}
}