-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
56 lines (46 loc) · 1.24 KB
/
example_test.go
File metadata and controls
56 lines (46 loc) · 1.24 KB
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
49
50
51
52
53
54
55
56
// Copyright (c) 2017-2026 The asrl developers. All rights reserved.
// Project site: https://github.com/gotmc/asrl
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE.txt file for the project.
package asrl_test
import (
"context"
"fmt"
"log"
"github.com/gotmc/asrl"
)
func Example() {
ctx := context.Background()
// Open a serial device using a VISA resource string.
dev, err := asrl.NewDevice(ctx, "ASRL::/dev/tty.usbserial-PX484GRU::9600::8N2::INSTR")
if err != nil {
log.Fatal(err)
}
defer func() { _ = dev.Close() }()
// Query the instrument identification.
idn, err := dev.Query(ctx, "*IDN?")
if err != nil {
log.Fatal(err)
}
fmt.Println(idn)
// Send a SCPI command.
if err := dev.Command(ctx, "OUTP ON"); err != nil {
log.Fatal(err)
}
}
func Example_withOptions() {
ctx := context.Background()
// Open a device with functional options.
dev, err := asrl.NewDevice(ctx,
"ASRL::/dev/tty.usbserial-PX8X3YR6::9600::8N2::INSTR",
asrl.WithHWHandshaking(true),
)
if err != nil {
log.Fatal(err)
}
defer func() { _ = dev.Close() }()
// With hardware handshaking enabled, Command polls DSR before writing.
if err := dev.Command(ctx, "SYST:REM"); err != nil {
log.Fatal(err)
}
}