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
019414d0
Commit
019414d0
authored
Feb 16, 2018
by
auke.klazema
Browse files
extracted port name validation to a method
parent
141b2752
Changes
1
Hide whitespace changes
Inline
Side-by-side
hpib.py
View file @
019414d0
...
...
@@ -24,13 +24,11 @@ class PrologixGpibUsb(PortDevice):
if
port
==
""
:
maxDeviceNum
,
port
,
portFormat
=
self
.
_set_default_platform_values
()
self
.
_validate_port
(
port
)
if
verbose
:
print
"Looking for ports such as %s in range %d on %s"
%
\
(
port
,
maxDeviceNum
,
platform
.
system
()
)
self
.
_rematch
=
re
.
search
(
r
"(/dev/tty.*[^0-9])([0-9]+$)"
,
port
)
if
not
self
.
_rematch
:
raise
ValueError
(
port
)
while
int
(
self
.
_rematch
.
group
(
2
))
<
maxDeviceNum
:
if
verbose
:
...
...
@@ -39,8 +37,8 @@ class PrologixGpibUsb(PortDevice):
self
.
_serialPort
=
serial
.
Serial
(
port
,
timeout
=
timeout
)
break
except
serial
.
SerialException
:
port
=
self
.
_rematch
.
group
(
1
)
+
\
(
portFormat
%
(
int
(
self
.
_rematch
.
group
(
2
))
+
1
))
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"
)
...
...
@@ -55,8 +53,8 @@ class PrologixGpibUsb(PortDevice):
self
.
_devices
=
[]
for
self
.
_hpib_address
in
range
(
0
,
31
):
commandStr
=
"++addr "
+
str
(
self
.
_hpib_address
)
+
chr
(
10
)
+
\
"*idn?"
+
chr
(
10
)
+
\
"++read"
+
chr
(
10
)
"*idn?"
+
chr
(
10
)
+
\
"++read"
+
chr
(
10
)
self
.
_serialPort
.
write
(
commandStr
)
returnStr
=
self
.
_serialPort
.
readline
()
if
returnStr
!=
""
:
...
...
@@ -65,6 +63,11 @@ class PrologixGpibUsb(PortDevice):
self
.
_devices
=
"Not scanned."
self
.
_hpib_address
=
-
1
def
_validate_port
(
self
,
port
):
self
.
_rematch
=
re
.
search
(
r
"(/dev/tty.*[^0-9])([0-9]+$)"
,
port
)
if
not
self
.
_rematch
:
raise
ValueError
(
port
)
def
_set_default_platform_values
(
self
):
if
platform
.
system
()
==
"Linux"
:
port
=
"/dev/ttyUSB0"
...
...
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