Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
auke.klazema
HPIB
Commits
35e34df8
Commit
35e34df8
authored
Feb 16, 2018
by
auke.klazema
Browse files
extracted available port search to a method
parent
019414d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
hpib.py
View file @
35e34df8
...
...
@@ -30,18 +30,8 @@ class PrologixGpibUsb(PortDevice):
print
"Looking for ports such as %s in range %d on %s"
%
\
(
port
,
maxDeviceNum
,
platform
.
system
()
)
while
int
(
self
.
_rematch
.
group
(
2
))
<
maxDeviceNum
:
if
verbose
:
print
"trying "
,
port
try
:
self
.
_serialPort
=
serial
.
Serial
(
port
,
timeout
=
timeout
)
break
except
serial
.
SerialException
:
port
=
self
.
_rematch
.
group
(
1
)
+
\
(
portFormat
%
(
int
(
self
.
_rematch
.
group
(
2
))
+
1
))
self
.
_rematch
=
re
.
search
(
"(/dev/tty.*[^0-9])([0-9]+$)"
,
port
)
if
self
.
_serialPort
==
None
:
raise
serial
.
SerialException
(
"Cannot find port"
)
self
.
_find_available_port
(
maxDeviceNum
,
port
,
portFormat
,
timeout
,
verbose
)
self
.
_serialPort
.
write
(
"++savecfg 0"
+
chr
(
10
))
self
.
_serialPort
.
write
(
"++auto 0"
+
chr
(
10
))
self
.
_serialPort
.
write
(
"++eoi 1"
+
chr
(
10
))
...
...
@@ -63,6 +53,19 @@ class PrologixGpibUsb(PortDevice):
self
.
_devices
=
"Not scanned."
self
.
_hpib_address
=
-
1
def
_find_available_port
(
self
,
maxDeviceNum
,
port
,
portFormat
,
timeout
,
verbose
):
while
int
(
self
.
_rematch
.
group
(
2
))
<
maxDeviceNum
:
if
verbose
:
print
"trying "
,
port
try
:
self
.
_serialPort
=
serial
.
Serial
(
port
,
timeout
=
timeout
)
break
except
serial
.
SerialException
:
port
=
self
.
_rematch
.
group
(
1
)
+
(
portFormat
%
(
int
(
self
.
_rematch
.
group
(
2
))
+
1
))
self
.
_rematch
=
re
.
search
(
"(/dev/tty.*[^0-9])([0-9]+$)"
,
port
)
if
self
.
_serialPort
is
None
:
raise
serial
.
SerialException
(
"Cannot find port"
)
def
_validate_port
(
self
,
port
):
self
.
_rematch
=
re
.
search
(
r
"(/dev/tty.*[^0-9])([0-9]+$)"
,
port
)
if
not
self
.
_rematch
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment