/
ds345.go
115 lines (102 loc) · 2.97 KB
/
ds345.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 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 implements the IVI driver for the Stanford Research System
DS345 function generator.
State Caching: Not implemented
*/
package ds345
import (
"github.com/gotmc/ivi"
"github.com/gotmc/ivi/fgen"
)
// DS345 provides the IVI driver for a SRS DS345 function generator.
type DS345 struct {
inst ivi.Instrument
Channels []Channel
ivi.Inherent
}
// New creates a new DS345 IVI Instrument.
func New(inst ivi.Instrument, reset bool) (*DS345, error) {
channelNames := []string{
"Output",
}
outputCount := len(channelNames)
channels := make([]Channel, outputCount)
for i, ch := range channelNames {
baseChannel := fgen.NewChannel(i, ch, inst)
channels[i] = Channel{baseChannel}
}
inherentBase := ivi.InherentBase{
ClassSpecMajorVersion: 4,
ClassSpecMinorVersion: 3,
ClassSpecRevision: "5.2",
GroupCapabilities: []string{
"IviFgenBase",
"IviFgenStdfunc",
"IviFgenTrigger",
"IviFgenInternalTrigger",
"IviFgenBurst",
},
SupportedInstrumentModels: []string{
"DS345",
},
}
inherent := ivi.NewInherent(inst, inherentBase)
driver := DS345{
inst: inst,
Channels: channels,
Inherent: inherent,
}
if reset {
if err := driver.Reset(); err != nil {
return &driver, err
}
// Default to internal trigger instead of single trigger.
if _, err := driver.inst.WriteString("TSRC1\n"); err != nil {
return &driver, err
}
return &driver, nil
}
return &driver, nil
}
// Channel represents a repeated capability of an output channel for the
// function generator.
type Channel struct {
fgen.Channel
}
// AvailableCOMPorts lists the avaialble COM ports, including optional ports.
func AvailableCOMPorts() []string {
return []string{"GPIB", "RS232"}
}
// DefaultGPIBAddress lists the default GPIB interface address.
func DefaultGPIBAddress() int {
return 19
}
// SerialConfig lists whether the RS-232 serial port is configured as a DCE
// (Data Circuit-Terminating Equipment) or a DTE (Data Terminal Equipment). Computers
// running the IVI program are DTEs; therefore, use a straight through serial
// cable when connecting to DCEs and a null modem cable when connecting to DTEs.
func SerialConfig() string {
return "DCE"
}
// SerialBaudRates lists the available baud rates for the RS-232 serial port
// from the fastest to the slowest.
func SerialBaudRates() []int {
return []int{19200, 9600, 4800, 2400, 1200, 600, 300}
}
// DefaultSerialBaudRate returns the default baud rate for the RS-232 serial
// port.
func DefaultSerialBaudRate() int {
return 9600
}
// SerialDataFrames lists the available RS-232 data frame formats.
func SerialDataFrames() []string {
return []string{"8N2"}
}
// DefaultSerialDataFrame returns the default RS-232 data frame format.
func DefaultSerialDataFrame() string {
return "8N2"
}