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
cd8ce260
Commit
cd8ce260
authored
May 09, 2018
by
Tammo Jan Dijkema
Browse files
Make initialization of CamrasHpibDevice thread safe
parent
bf072b26
Changes
1
Hide whitespace changes
Inline
Side-by-side
camrasdevices.py
View file @
cd8ce260
...
...
@@ -54,24 +54,27 @@ from astropy.units import Quantity
import
hpib
import
serial.threaded
import
threading
class
CamrasHpibDevice
(
object
):
"""Wrapper around HPIB commands"""
command_thread
=
None
_initialization_lock
=
threading
.
Lock
()
def
__init__
(
self
,
address
,
check_frequency
=
True
):
self
.
hpib_address
=
address
self
.
_check_frequency
=
check_frequency
if
not
CamrasHpibDevice
.
command_thread
:
serial_port
=
serial
.
Serial
(
"/dev/ttyUSB0"
)
CamrasHpibDevice
.
command_thread
=
serial
.
threaded
.
ReaderThread
(
serial_port
,
hpib
.
GPIBProtocol
)
CamrasHpibDevice
.
command_thread
.
start
()
CamrasHpibDevice
.
command_thread
.
_connection_made
.
wait
()
CamrasHpibDevice
.
command_thread
.
protocol
.
init_hpib
()
with
self
.
_initialization_lock
:
if
not
CamrasHpibDevice
.
command_thread
:
serial_port
=
serial
.
Serial
(
"/dev/ttyUSB0"
)
CamrasHpibDevice
.
command_thread
=
serial
.
threaded
.
ReaderThread
(
serial_port
,
hpib
.
GPIBProtocol
)
CamrasHpibDevice
.
command_thread
.
start
()
CamrasHpibDevice
.
command_thread
.
_connection_made
.
wait
()
CamrasHpibDevice
.
command_thread
.
protocol
.
init_hpib
()
def
command
(
self
,
command_string
,
prepend_address
=
True
):
"""Send a command to the HPIB command thread
...
...
Write
Preview
Supports
Markdown
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