Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
HPIB
Commits
2c6e5683
Commit
2c6e5683
authored
May 06, 2018
by
Tammo Jan Dijkema
Browse files
Fix initialization
parent
c59cc9b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
camrasdevices.py
View file @
2c6e5683
...
...
@@ -4,27 +4,26 @@ from astropy.units import Quantity
import
hpib
import
serial.threaded
command_thread
=
None
class
CamrasHpibDevice
(
object
):
"""Wrapper around HPIB commands"""
command_thread
=
None
def
__init__
(
self
,
address
):
if
not
command_thread
.
is_alive
():
command_thread
.
start
()
self
.
hpib_address
=
address
if
not
command_thread
:
if
not
CamrasHpibDevice
.
command_thread
:
serial_port
=
serial
.
Serial
(
"/dev/ttyUSB0"
)
command_thread
=
serial
.
threaded
.
ReaderThread
(
serial_port
,
hpib
.
GPIBProtocol
)
command_thread
.
protocol
.
init_hpib
()
CamrasHpibDevice
.
command_thread
=
serial
.
threaded
.
ReaderThread
(
serial_port
,
hpib
.
GPIBProtocol
)
CamrasHpibDevice
.
command_thread
.
start
()
CamrasHpibDevice
.
command_thread
.
protocol
.
init_hpib
()
@
property
def
frequency
(
self
):
"""Returns the frequency of the device as an astropy Quantity.
Throws a RuntimeError if no response"""
freq_str
=
command_thread
.
protocol
.
command
(
"freq?"
,
address
=
self
.
hpib_address
)
freq_str
=
CamrasHpibDevice
.
command_thread
.
protocol
.
command
(
"freq?"
,
address
=
self
.
hpib_address
)
if
len
(
freq_str
)
==
0
:
raise
RuntimeError
(
"Camras device at address {} is not responding"
.
format
(
self
.
_hpib_address
))
return
int
(
float
(
freq_str
))
*
u
.
Hz
...
...
@@ -38,7 +37,7 @@ class CamrasHpibDevice(object):
"""
if
isinstance
(
freq
,
Quantity
):
freq
=
freq
.
to
(
u
.
Hz
).
value
command_thread
.
protocol
.
command
(
"freq {:d} Hz"
.
format
(
int
(
freq
)),
address
=
self
.
hpib_address
)
CamrasHpibDevice
.
command_thread
.
protocol
.
command
(
"freq {:d} Hz"
.
format
(
int
(
freq
)),
address
=
self
.
hpib_address
)
new_freq
=
self
.
frequency
if
new_freq
.
to
(
u
.
Hz
).
value
!=
int
(
freq
):
raise
RuntimeError
(
"Setting frequency failed: tried to set to {}, it is now {}"
.
format
(
...
...
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