/
device.go
122 lines (108 loc) · 3.31 KB
/
device.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
116
117
118
119
120
121
122
// Copyright (c) 2017-2023 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 e36xx implements the IVI driver for the Agilent/Keysight E3600 series
of power supplies.
State Caching: Not implemented
*/
package e36xx
import (
"github.com/gotmc/ivi"
"github.com/gotmc/ivi/dcpwr"
)
// Confirm that the device driver implements the IviDCPwrBase interface.
var _ dcpwr.Base = (*Device)(nil)
// Device provides the IVI driver for the Agilent/Keysight E3600 series of DC
// power supplies.
type Device struct {
inst ivi.Instrument
Channels []Channel
ivi.Inherent
}
// New creates a new AgilentE36xx IVI Instrument driver. Currently, only the
// E3631A model is supported, but in the future as other models are added, the
// New function will query the instrument to determine the model and ensure it
// is one of the supported models. If reset is true, then the instrument is
// reset.
func New(inst ivi.Instrument, reset bool) (*Device, error) {
channelNames := []string{
"P6V",
"P25V",
"N25V",
}
outputCount := len(channelNames)
channels := make([]Channel, outputCount)
for i, channelName := range channelNames {
ch := Channel{
name: channelName,
inst: inst,
}
channels[i] = ch
}
inherentBase := ivi.InherentBase{
ClassSpecMajorVersion: 4,
ClassSpecMinorVersion: 4,
ClassSpecRevision: "3.0",
GroupCapabilities: []string{
"IviDCPwrBase",
"IviDCPwrMeasurement",
},
SupportedInstrumentModels: []string{
"E3631A",
},
}
inherent := ivi.NewInherent(inst, inherentBase)
device := Device{
inst: inst,
Channels: channels,
Inherent: inherent,
}
if reset {
err := device.Reset()
return &device, err
}
return &device, nil
}
// 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 5
}
// 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 "DTE"
}
// SerialBaudRates lists the available baud rates for the RS-232 serial port
// from the fastest to the slowest.
func SerialBaudRates() []int {
return []int{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", "7E2", "7O2"}
}
// DefaultSerialDataFrame returns the default RS-232 data frame format.
func DefaultSerialDataFrame() string {
return "8N2"
}
// ChannelCount returns the number of available output channels.
//
// ChannelCount is the getter for the read-only IviDCPwrBase Attribute Output
// Channel Count described in Section 4.2.7 of IVI-4.4: IviDCPwr Class
// Specification.
func (d Device) ChannelCount() int {
return len(d.Channels)
}