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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! KWR103 remote controllable power supply
//!
//! This crate provides remote control access to Korad KWR103 type power supplies implementing
//! both, serial/USB and ethernet/UDP based, communication channels.
//!
//! # Example
//! ```no_run
//! use kwr103::{command::*, Kwr103, TransactionError, UsbConnection};
//!
//! fn main() -> Result<(), TransactionError> {
//! // Establish USB connection
//! let mut kwr103: Kwr103 = UsbConnection::new("/dev/ttyACM0", 115200, None)?.into();
//!
//! // Adjust voltage and current settings
//! kwr103.command(Voltage(42.0))?;
//! kwr103.command(Current(1.2))?;
//!
//! // Switch output on
//! kwr103.command(Output(Switch::On))?;
//!
//! // Query status, prints e.g. "Output: On, Voltage[V]: 42.000, Current[A]: 0.131"
//! println!("{}", kwr103.query::<Status>()?);
//!
//! Ok(())
//! }
//! ```
//!
//! # Command Line Interface
//! To control the power supply from a terminal, you can use the `kwr103` command line tool. Use
//! `kwr103 --help` for the full specification.
//!
//! ```text
//! > kwr103 status
//! Output: Off, Voltage[V]: 0.000, Current[A]: 0.000
//!
//! > kwr103 output on
//! > kwr103 status
//! Output: On, Voltage[V]: 42.000, Current[A]: 0.131
//! ```
//!
//! ## Automatic connection discovery
//! The `kwr103` command line tool will attempt to automatically find the connection details for
//! the attached power supply, whether it is serial or ethernet connected.
//!
//! In case you want to specify the connection details explicitly instead, use the corresponding
//! CLI parameters, i.e.
//!
//! - `--device=<PATH>` for a serial connected power supply
//! - `--ip=<IPv4ADDR>` for an ethernet connected power supply
//!
//! **In case the automatic discovery finds more than a single power supply unit, no action will be
//! taken for safety reasons. In this case you will be prompted to specify the connection details
//! explicitly.**
pub use ;
pub use EthConnection;
pub use UsbConnection;
/// A command to be issued to the power supply.
///
/// Types implementing this trait represent commands that are intended to change settings or the
/// state of the power supply and do not trigger a response message.
///
/// ## Protocol
///
/// Most commands follow the simple syntax of
/// ```text
/// <CMD>[ID]:<VAL>\n
/// ```
/// so in order to set the output voltage to 12.0V on the power supply with device id 1 the
/// serialized payload should look like
/// `VSET01:12.0\n`.
///
/// If `device_id` is `None`, the `[ID]` field is ommitted.
///
/// Additionally, commands may even be concatenated (separated by the newline character), e.g.
/// `VSET01:42.0\nISET01:2.3\n` both sets the output voltage to 42.0V as well as the output current
/// to 2.3A
/// A query to be issued to the power supply.
///
/// Types implementing this trait represent settings or state values that can be queried from the
/// power supply, i.e. after a query has been issued, the power supply will answer with a
/// corresponding response.
///
/// ## Protocol
///
/// Communication follows a simple Query-Response schema where the query is formatted with the
/// following syntax:
/// ```text
/// <QUERY>[ID]?\n
/// ```
/// so for example a query for the output voltage setting on the power supply with id 1 serializes
/// as `VSET01?\n`, with the response following as `42.0\n` (newline terminated value).
///
/// If `device_id` is `None`, the `[ID]` field is ommitted.
///
/// Additionally, queries may even be concatenated (separated by the newline character),
/// e.g. `VSET01?\nISET01?\n` queries both the output voltage and current.
/// A type implementing `Transport` defines how to physically communicate with the power supply
/// A KWR103 type power supply
///
/// This is the main access point to control a power supply.
///
/// # Note
/// Rather than instantiating directly, use one of the [`Transport`] types specifying the
/// connection details.
///
/// ```no_run
/// use kwr103::{Kwr103, UsbConnection};
///
/// let mut kwr103 = Kwr103::from(UsbConnection::new("/dev/ttyACM0", 115200, None).unwrap());
/// ```