/
trigger.go
54 lines (48 loc) · 1.61 KB
/
trigger.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
49
50
51
52
53
54
// Copyright (c) 2017-2020 The ivi developers. All rights reserved.
// Project site: https://github.com/gotmc/ivi
// 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 ds345
import (
"errors"
"log"
"strings"
"github.com/gotmc/ivi/fgen"
)
// Make sure that the key33220 driver implements the IviFgenTrigger capability
// group.
var _ fgen.TriggerChannel = (*Channel)(nil)
// TriggerSource determines the trigger srouce. TriggerSource is the getter for
// the read-write IviFgenTrigger Attribute Trigger Source described in Section
// 9.2.1 of IVI-4.3: IviFgen Class Specification.
func (ch *Channel) TriggerSource() (fgen.TriggerSource, error) {
var src fgen.TriggerSource
s, err := ch.QueryString("TSRC?\n")
if err != nil {
return src, err
}
s = strings.TrimSpace(strings.ToUpper(s))
switch s {
case "1":
src = fgen.InternalTrigger
case "2", "3":
src = fgen.ExternalTrigger
default:
return src, errors.New("error determining trigger source")
}
return src, nil
}
// SetTriggerSource specifies the trigger srouce. SetTriggerSource is the
// setter for the read-write IviFgenTrigger Attribute Trigger Source described
// in Section 9.2.1 of IVI-4.3: IviFgen Class Specification.
func (ch *Channel) SetTriggerSource(src fgen.TriggerSource) error {
if src == fgen.SoftwareTrigger {
return errors.New("software trigger not supported")
}
triggers := map[fgen.TriggerSource]string{
fgen.InternalTrigger: "1",
fgen.ExternalTrigger: "2",
}
log.Printf("Sending command TSRC%s\n", triggers[src])
return ch.Set("TSRC%s\n", triggers[src])
}