Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
DIOT reliability studies project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Projects
DIOT reliability studies project
Commits
72e458ab
Commit
72e458ab
authored
Mar 28, 2022
by
Alén Arias Vázquez
😎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added variable status
parent
55536c95
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
cpx400dp.py
cpx400dp/cpx400dp.py
+25
-16
No files found.
cpx400dp/cpx400dp.py
View file @
72e458ab
...
...
@@ -9,6 +9,7 @@ class CPX400DP(object):
logging
.
basicConfig
(
format
=
'
%(asctime)
s.
%(msecs)03
d
%(name)
s-
%(levelname)-
s:
%(message)
s'
,
datefmt
=
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
,
level
=
log_level
)
self
.
name
=
name
self
.
log
=
logging
.
getLogger
(
self
.
name
)
self
.
CHAN_STATUS
=
[
False
,
False
]
try
:
self
.
serial
=
serial
.
Serial
(
devname
,
baudrate
)
self
.
log
.
info
(
"Opening device {}"
.
format
(
self
.
serial
.
name
))
...
...
@@ -28,47 +29,55 @@ class CPX400DP(object):
def
set_voltage
(
self
,
volts
,
chan
=
1
):
self
.
log
.
info
(
"Set oltage {}V in channel {}"
.
format
(
volts
,
chan
))
cmd
=
'V'
+
str
(
chan
)
+
' '
+
str
(
volts
)
+
'
\n
'
cmd
=
'V'
+
str
(
chan
)
+
' '
+
str
(
volts
)
+
'
\n
'
self
.
send_cmd
(
cmd
)
def
get_voltage
(
self
,
chan
=
1
):
cmd
=
'V'
+
str
(
chan
)
+
'O?
\n
'
cmd
=
'V'
+
str
(
chan
)
+
'O?
\n
'
self
.
send_cmd
(
cmd
)
answer
=
self
.
recv_cmd
()
self
.
log
.
info
(
"Voltage channel {}: {}V"
.
format
(
chan
,
float
(
answer
[:
-
3
])))
return
float
(
answer
[:
-
3
])
resp
=
self
.
recv_cmd
()
self
.
log
.
info
(
"Voltage channel {}: {}V"
.
format
(
chan
,
float
(
resp
[:
-
3
])))
return
float
(
resp
[:
-
3
])
def
set_current
(
self
,
amps
,
chan
=
1
):
self
.
log
.
info
(
"Set current to {}A in channel {}"
.
format
(
amps
,
chan
))
cmd
=
'I'
+
str
(
chan
)
+
' '
+
str
(
amps
)
+
'
\n
'
cmd
=
'I'
+
str
(
chan
)
+
' '
+
str
(
amps
)
+
'
\n
'
self
.
send_cmd
(
cmd
)
def
get_current
(
self
,
chan
=
1
):
cmd
=
'I'
+
str
(
chan
)
+
'O?
\n
'
cmd
=
'I'
+
str
(
chan
)
+
'O?
\n
'
self
.
send_cmd
(
cmd
)
answer
=
self
.
recv_cmd
()
self
.
log
.
info
(
"Current channel {}: {}A"
.
format
(
chan
,
float
(
answer
[:
-
3
])))
return
float
(
answer
[:
-
3
])
resp
=
self
.
recv_cmd
()
self
.
log
.
info
(
"Current channel {}: {}A"
.
format
(
chan
,
float
(
resp
[:
-
3
])))
return
float
(
resp
[:
-
3
])
def
unlock
(
self
):
cmd
=
'IFUNLOCK
\n
'
cmd
=
'IFUNLOCK
\n
'
self
.
send_cmd
(
cmd
)
def
lock
(
self
):
cmd
=
'IFLOCK
\n
'
cmd
=
'IFLOCK
\n
'
self
.
send_cmd
(
cmd
)
def
turn_on
(
self
,
chan
=
1
):
cmd
=
'OP'
+
str
(
chan
)
+
' 1
\n
'
cmd
=
'OP'
+
str
(
chan
)
+
' 1
\n
'
self
.
log
.
info
(
"Turning ON Channel {}"
.
format
(
chan
))
self
.
send_cmd
(
cmd
)
self
.
CHAN_STATUS
[
chan
-
1
]
=
True
def
turn_off
(
self
,
chan
=
1
):
cmd
=
'OP'
+
str
(
chan
)
+
' 0
\n
'
cmd
=
'OP'
+
str
(
chan
)
+
' 0
\n
'
self
.
log
.
info
(
"Turning OFF Channel {}"
.
format
(
chan
))
self
.
send_cmd
(
cmd
)
self
.
CHAN_STATUS
[
chan
-
1
]
=
False
def
setup
(
self
,
chan
=
1
,
volts
=
10.0
,
amps
=
0.3
):
def
get_status_chan
(
self
,
chan
=
1
):
cmd
=
'OP'
+
str
(
chan
)
+
'?
\n
'
self
.
send_cmd
(
cmd
)
resp
=
self
.
recv_cmd
()
self
.
log
.
info
(
"Channel {} is {}"
.
format
(
chan
,
resp
))
def
setup_chan
(
self
,
chan
=
1
,
volts
=
10.0
,
amps
=
0.3
):
self
.
set_voltage
(
volts
=
volts
,
chan
=
chan
)
self
.
set_current
(
amps
=
amps
,
chan
=
chan
)
self
.
turn_on
(
chan
=
chan
)
...
...
@@ -96,7 +105,7 @@ def main():
args
=
parser
.
parse_args
()
psu
=
CPX400DP
(
name
=
'CPX400DP'
,
devname
=
args
.
device
,
baudrate
=
args
.
baudrate
,
log_level
=
logging
.
INFO
)
if
args
.
powerup
:
psu
.
setup
(
chan
=
args
.
chan
,
volts
=
args
.
volts
,
amps
=
args
.
amps
)
psu
.
setup
_chan
(
chan
=
args
.
chan
,
volts
=
args
.
volts
,
amps
=
args
.
amps
)
else
:
psu
.
turn_off
(
chan
=
args
.
chan
)
psu
.
close
()
...
...
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