Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labcode
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CST
labcode
Commits
d618a835
Commit
d618a835
authored
8 months ago
by
Alexandros Asonitis
Browse files
Options
Downloads
Patches
Plain Diff
Conversions of octal to channels and vice versA
parent
e126be73
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
TLM_tool/convert_test.ipynb
+41
-3
41 additions, 3 deletions
TLM_tool/convert_test.ipynb
TLM_tool/hp3497a_lib.py
+29
-1
29 additions, 1 deletion
TLM_tool/hp3497a_lib.py
TLM_tool/keitley_224_control_class.py
+0
-182
0 additions, 182 deletions
TLM_tool/keitley_224_control_class.py
with
70 additions
and
186 deletions
TLM_tool/convert_test.ipynb
+
41
−
3
View file @
d618a835
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
5
,
"execution_count":
3
,
"id": "dad4cac4-c0fb-438a-8928-da8332701f2c",
"id": "dad4cac4-c0fb-438a-8928-da8332701f2c",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
6
,
"execution_count":
4
,
"id": "73e839ca-fb78-47f4-8076-43676d6bb4ad",
"id": "73e839ca-fb78-47f4-8076-43676d6bb4ad",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -59,9 +59,47 @@
...
@@ -59,9 +59,47 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
5
,
"id": "b21fc931-38d2-492b-8b16-1703421366d3",
"id": "b21fc931-38d2-492b-8b16-1703421366d3",
"metadata": {},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n"
]
}
],
"source": [
"channels = hp3497a_lib.octal_to_channels(octal)\n",
"print(channels)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "9e163a6f-fa48-4e54-8216-04708184c0d6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 6, 7]\n"
]
}
],
"source": [
"channels = hp3497a_lib.octal_to_channels(303)\n",
"print(channels)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "853bdf13-e222-4ab7-b4f0-5b211220b44a",
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
"source": []
}
}
...
...
%% Cell type:code id:b3965c31-edec-4d04-856c-c4bb850bd22a tags:
%% Cell type:code id:b3965c31-edec-4d04-856c-c4bb850bd22a tags:
```
python
```
python
import
hp3497a_lib
import
hp3497a_lib
```
```
%% Cell type:code id:a4f45391-ec6d-47c2-ae1e-445097197bdb tags:
%% Cell type:code id:a4f45391-ec6d-47c2-ae1e-445097197bdb tags:
```
python
```
python
bin
=
hp3497a_lib
.
octal_to_bin
(
177777
)
bin
=
hp3497a_lib
.
octal_to_bin
(
177777
)
```
```
%% Cell type:code id:dad4cac4-c0fb-438a-8928-da8332701f2c tags:
%% Cell type:code id:dad4cac4-c0fb-438a-8928-da8332701f2c tags:
```
python
```
python
print
(
bin
)
print
(
bin
)
```
```
%% Output
%% Output
1111111111111111
1111111111111111
%% Cell type:code id:73e839ca-fb78-47f4-8076-43676d6bb4ad tags:
%% Cell type:code id:73e839ca-fb78-47f4-8076-43676d6bb4ad tags:
```
python
```
python
octal
=
hp3497a_lib
.
bin_to_octal
(
bin
)
octal
=
hp3497a_lib
.
bin_to_octal
(
bin
)
print
(
octal
)
print
(
octal
)
```
```
%% Output
%% Output
177777
177777
%% Cell type:code id:b21fc931-38d2-492b-8b16-1703421366d3 tags:
%% Cell type:code id:b21fc931-38d2-492b-8b16-1703421366d3 tags:
```
python
```
python
channels
=
hp3497a_lib
.
octal_to_channels
(
octal
)
print
(
channels
)
```
%% Output
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
%% Cell type:code id:9e163a6f-fa48-4e54-8216-04708184c0d6 tags:
```
python
channels
=
hp3497a_lib
.
octal_to_channels
(
303
)
print
(
channels
)
```
%% Output
[0, 1, 6, 7]
%% Cell type:code id:853bdf13-e222-4ab7-b4f0-5b211220b44a tags:
```
python
```
```
...
...
This diff is collapsed.
Click to expand it.
TLM_tool/hp3497a_lib.py
+
29
−
1
View file @
d618a835
...
@@ -435,15 +435,43 @@ class hp3497a(object):
...
@@ -435,15 +435,43 @@ class hp3497a(object):
# This to convert binary to octal and vise versa
# This to convert binary to octal and vise versa
def
bin_to_octal
(
bin
):
def
bin_to_octal
(
bin
):
"""
Converts Binary to Octal
"""
decimal
=
int
(
str
(
bin
),
2
)
decimal
=
int
(
str
(
bin
),
2
)
octal
=
format
(
decimal
,
'
o
'
)
octal
=
format
(
decimal
,
'
o
'
)
return
octal
return
octal
def
octal_to_bin
(
octal
):
def
octal_to_bin
(
octal
):
"""
Converts octal number to binary
"""
decimal
=
int
(
str
(
octal
),
8
)
decimal
=
int
(
str
(
octal
),
8
)
bin
=
format
(
decimal
,
'
b
'
)
bin
=
format
(
decimal
,
'
b
'
)
return
bin
return
bin
def
channels_to_octal
(
*
channels
):
"""
Converets normaly open (1) channels(0-15) to octal
"""
decimal
=
0
for
channel
in
channels
:
decimal
=
decimal
+
2
**
channel
octal
=
format
(
decimal
,
'
o
'
)
return
octal
def
octal_to_channels
(
octal
):
"""
Returns the channels in normally open position (1) as a list
"""
binary
=
str
(
octal_to_bin
(
octal
))
# convert to string
channels
=
[]
for
i
,
digit
in
enumerate
(
binary
[::
-
1
]):
if
int
(
digit
)
==
1
:
channels
.
append
(
i
)
return
channels
\ No newline at end of file
This diff is collapsed.
Click to expand it.
TLM_tool/keitley_224_control_class.py
deleted
100644 → 0
+
0
−
182
View file @
e126be73
'''
KEITHLEY 224 instrument driver
TODO: SRQ decoding
https://www.eevblog.com/forum/testgear/keithley-224-python-code/
'''
import
pyvisa
import
enum
class
Readout_Values
:
def
__init__
(
self
):
self
.
raw
=
""
self
.
current
=
0.0
self
.
overcompliance
=
False
self
.
voltage
=
0.0
self
.
time
=
0.0
# Range Commands
RANGE_LIST
=
(
'
R0
'
,
'
R5
'
,
'
R6
'
,
'
R7
'
,
'
R8
'
,
'
R9
'
,
)
def
get_available_devices
():
rm
=
pyvisa
.
ResourceManager
()
devices
=
rm
.
list_resources
()
rm
.
close
()
return
devices
def
_decode_values
(
rawdata
):
splitted
=
rawdata
.
split
(
'
,
'
)
readout
=
Readout_Values
()
readout
.
raw
=
rawdata
for
element
in
splitted
:
if
'
DCI
'
in
element
:
if
element
[
0
]
is
'
O
'
:
readout
.
overcompliance
=
True
readout
.
current
=
float
(
element
[
4
:])
if
'
V
'
in
element
:
readout
.
voltage
=
float
(
element
[
1
:])
if
'
W
'
in
element
:
readout
.
time
=
float
(
element
[
1
:])
return
readout
def
_format_e
(
n
):
a
=
'
%E
'
%
n
return
a
.
split
(
'
E
'
)[
0
].
rstrip
(
'
0
'
).
rstrip
(
'
.
'
)
+
'
E
'
+
a
.
split
(
'
E
'
)[
1
]
class
KEITHLEY_224
(
object
):
class
Ranges
(
enum
.
Enum
):
AUTO
=
0
MAN_20uA
=
1
MAN_200uA
=
2
MAN_2mA
=
3
MAN_20mA
=
4
MAN_1m01A
=
5
def
__init__
(
self
,
address
):
self
.
_address
=
address
self
.
_rm
=
pyvisa
.
ResourceManager
()
self
.
_inst
=
self
.
_rm
.
open_resource
(
address
)
self
.
_range
=
self
.
Ranges
.
AUTO
self
.
voltage
=
3.0
self
.
current
=
float
(
1e-06
)
self
.
time
=
0.05
self
.
operate
=
False
self
.
_inst
.
control_ren
(
1
)
## +++++++++++++++++++++++
def
__del__
(
self
):
self
.
operate
=
False
self
.
_inst
.
control_ren
(
0
)
## +++++++++++++++++++++++
self
.
_rm
.
close
()
def
get_measurement
(
self
):
self
.
_inst
.
timeout
=
1000
result
=
_decode_values
(
self
.
_inst
.
read
())
return
result
@property
def
range
(
self
):
return
self
.
_range
@range.setter
def
range
(
self
,
range
):
if
not
isinstance
(
range
,
self
.
Ranges
):
raise
TypeError
(
'
mode must be an instance of Ranges Enum
'
)
self
.
_range
=
range
self
.
_inst
.
write
(
RANGE_LIST
[
self
.
_range
.
value
]
+
'
X
'
)
@property
def
voltage
(
self
):
return
self
.
_voltage
@voltage.setter
def
voltage
(
self
,
voltage
):
if
(
voltage
<
1
)
or
(
voltage
>
105
):
raise
ValueError
(
'
voltage limits: 1 to 105
'
)
self
.
_voltage
=
voltage
self
.
_inst
.
write
(
'
V
'
+
_format_e
(
voltage
)
+
'
X
'
)
@property
def
current
(
self
):
return
self
.
_current
@current.setter
def
current
(
self
,
current
):
if
(
current
<
-
0.101
)
or
(
current
>
0.101
):
raise
ValueError
(
'
current limits: +/- 0.101
'
)
self
.
_current
=
current
self
.
_inst
.
write
(
'
I
'
+
_format_e
(
current
)
+
'
X
'
)
# print('I' + _format_e(current) + 'X') ## +++++++++++++++++++++++
@property
def
time
(
self
):
return
self
.
_time
@time.setter
def
time
(
self
,
time
):
if
(
time
<
0.05
)
or
(
time
>
0.9999
):
raise
ValueError
(
'
time limits: 0.05 to 0.9999 sec
'
)
self
.
_time
=
time
self
.
_inst
.
write
(
'
W
'
+
_format_e
(
time
)
+
'
X
'
)
@property
def
operate
(
self
):
return
self
.
_operate
@operate.setter
def
operate
(
self
,
operate
):
if
type
(
operate
)
is
not
type
(
True
):
raise
ValueError
(
'
operate takes a bool value
'
)
self
.
_operate
=
operate
if
operate
is
True
:
self
.
_inst
.
write
(
'
F1X
'
)
else
:
self
.
_inst
.
write
(
'
F0X
'
)
# testing the code
if
__name__
==
'
__main__
'
:
import
numpy
import
time
## instrument = KEITHLEY_224("GPIB0::15::INSTR")
##
## meas = instrument.get_measurement()
## print('Raw data: ' + str(meas.raw))
## print('Current: ' + str(meas.current))
## print('Overcompliance: ' + str(meas.overcompliance))
## print('Voltage: ' + str(meas.voltage))
## print('Time: ' + str(meas.time))
##
## instrument.operate = True
## instrument.voltage = 15
## instrument.time = 0.5
##
## time.sleep(5)
##
## for i in numpy.arange(0.001,0.015,0.001):
## instrument.current = i
## time.sleep(5.1)
##
## meas = instrument.get_measurement()
## print('Raw data: ' + str(meas.raw))
## print('Current: ' + str(meas.current))
## print('Overcompliance: ' + str(meas.overcompliance))
## print('Voltage: ' + str(meas.voltage))
## print('Time: ' + str(meas.time) + '\n\n\n')
##
## del instrument
instrument
=
KEITHLEY_224
(
"
GPIB0::15::INSTR
"
)
while
True
:
try
:
pass
except
:
del
instrument
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment