Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
DIOT Monitoring Module
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
DIOT Monitoring Module
Commits
80b9d471
Commit
80b9d471
authored
Jun 29, 2020
by
Christos Gentsos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utils: expand the dummy set_psu script to actually control the PSU
parent
a0bb01df
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
20 deletions
+73
-20
set_psu.py
utils/set_psu.py
+73
-20
No files found.
utils/set_psu.py
View file @
80b9d471
...
...
@@ -3,6 +3,7 @@
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
io
,
os
import
argparse
def
find_tty_dev
(
dev_name
):
tty_enum
=
os
.
popen
(
'./get_tty_devs.sh'
)
.
read
()
.
strip
()
.
split
(
'
\n
'
)
...
...
@@ -21,30 +22,82 @@ else:
print
(
'couldn
\'
t find PSU TTY device'
)
exit
()
tty
=
io
.
TextIOWrapper
(
io
.
FileIO
(
os
.
open
(
psu_tty_dev
,
os
.
O_NOCTTY
|
os
.
O_RDWR
),
"r+"
))
psu_tty
=
io
.
TextIOWrapper
(
io
.
FileIO
(
os
.
open
(
psu_tty_dev
,
os
.
O_NOCTTY
|
os
.
O_RDWR
),
"r+"
),
line_buffering
=
True
,
write_through
=
True
)
def
set_read
(
tty
,
cmd
):
tty
.
write
(
cmd
+
'
\n
'
)
line
=
tty
.
readline
()
return
(
line
.
strip
())
def
psu_read
(
cmd
):
psu_
tty
.
write
(
cmd
+
'
\n
'
)
psu_tmp_line
=
psu_
tty
.
readline
()
return
(
psu_tmp_
line
.
strip
())
def
set_noread
(
tty
,
cmd
):
tty
.
write
(
cmd
+
'
\n
'
)
def
psu_write
(
cmd
):
psu_
tty
.
write
(
cmd
+
'
\n
'
)
print
(
'Device code: '
+
set_read
(
tty
,
'*IDN?'
))
print
(
)
def
psu_get_id
(
val
):
print
(
'PSU ID: '
+
psu_read
(
'*IDN?'
)
)
set_noread
(
tty
,
'VSET1:{:05.2f}'
.
format
(
12.0
))
set_noread
(
tty
,
'VSET2:{:05.2f}'
.
format
(
5.0
))
print
(
'VS1: '
+
set_read
(
tty
,
'VSET1?'
))
print
(
'IL1: '
+
set_read
(
tty
,
'ISET1?'
))
print
(
'V1: '
+
set_read
(
tty
,
'VOUT1?'
))
print
(
'I1: '
+
set_read
(
tty
,
'IOUT1?'
))
print
()
def
psu_set_v1
(
val
):
if
((
val
>=
0.0
)
and
(
val
<
13.2
)):
psu_write
(
'VSET1:{:05.2f}'
.
format
(
val
))
print
(
'VS2: '
+
set_read
(
tty
,
'VSET2?'
))
print
(
'IL2: '
+
set_read
(
tty
,
'ISET2?'
))
print
(
'V2: '
+
set_read
(
tty
,
'VOUT2?'
))
print
(
'I2: '
+
set_read
(
tty
,
'IOUT2?'
))
def
psu_set_i1
(
val
):
if
((
val
>=
0.0
)
and
(
val
<
5
)):
psu_write
(
'ISET1:{:05.2f}'
.
format
(
val
))
def
psu_get_v1
(
val
):
return
(
float
(
psu_read
(
'VOUT1?'
)))
def
psu_get_i1
(
val
):
return
(
float
(
psu_read
(
'IOUT1?'
)))
def
psu_set_v2
(
val
):
if
((
val
>=
0.0
)
and
(
val
<
5.5
)):
psu_write
(
'VSET2:{:05.2f}'
.
format
(
val
))
def
psu_set_i2
(
val
):
if
((
val
>=
0.0
)
and
(
val
<
5
)):
psu_write
(
'ISET2:{:05.2f}'
.
format
(
val
))
def
psu_get_v2
(
val
):
return
(
float
(
psu_read
(
'VOUT2?'
)))
def
psu_get_i2
(
val
):
return
(
float
(
psu_read
(
'IOUT2?'
)))
def
psu_turn_off
(
val
):
psu_set_v1
(
0
)
psu_set_v2
(
0
)
def
psu_on_default
(
val
):
psu_set_v1
(
12.0
)
psu_set_v2
(
5.0
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Do something with the PSU.'
)
parser
.
add_argument
(
'action'
,
choices
=
[
'getID'
,
'setV1'
,
'setV2'
,
'setI1'
,
'setI2'
,
'getV1'
,
'getV2'
,
'getI1'
,
'getI2'
,
'off'
,
'on_default'
],
help
=
'what to do.'
)
parser
.
add_argument
(
'value'
,
type
=
float
,
help
=
'value to set something to (set to 0 if not setting something).'
)
fn_switch
=
{
'getID'
:
psu_get_id
,
'setV1'
:
psu_set_v1
,
'setV2'
:
psu_set_v2
,
'setI1'
:
psu_set_i1
,
'setI2'
:
psu_set_i2
,
'getV1'
:
psu_get_v1
,
'getV2'
:
psu_get_v2
,
'getI1'
:
psu_get_i1
,
'getI2'
:
psu_get_i2
,
'off'
:
psu_turn_off
,
'on_default'
:
psu_on_default
}
args
=
parser
.
parse_args
()
fn_switch
.
get
(
args
.
action
)(
args
.
value
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment