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
8d125a60
Commit
8d125a60
authored
Apr 13, 2018
by
Tammo Jan Dijkema
Browse files
Make compatible with python3
parent
1f9c66e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
hpib.py
View file @
8d125a60
...
@@ -2,6 +2,7 @@ import serial
...
@@ -2,6 +2,7 @@ import serial
import
time
import
time
import
re
import
re
import
platform
import
platform
import
sys
class
PortDevice
(
object
):
class
PortDevice
(
object
):
...
@@ -69,14 +70,20 @@ class PrologixGpibUsb(PortDevice):
...
@@ -69,14 +70,20 @@ class PrologixGpibUsb(PortDevice):
if
self
.
_serialPort
is
None
:
if
self
.
_serialPort
is
None
:
raise
serial
.
SerialException
(
"Cannot find port"
)
raise
serial
.
SerialException
(
"Cannot find port"
)
def
_write_serial
(
self
,
commandString
):
if
sys
.
version_info
>=
(
3
,
0
):
self
.
_serialPort
.
write
(
bytes
(
commandString
,
'utf-8'
))
else
:
self
.
_serialPort
.
write
(
commandString
)
def
_initialize_prologix_gpi
(
self
):
def
_initialize_prologix_gpi
(
self
):
self
.
_serial
Port
.
write
(
"++savecfg 0"
+
chr
(
10
))
self
.
_
write_
serial
(
"++savecfg 0"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++auto 0"
+
chr
(
10
))
self
.
_
write_
serial
(
"++auto 0"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++eoi 1"
+
chr
(
10
))
self
.
_
write_
serial
(
"++eoi 1"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++eos 2"
+
chr
(
10
))
self
.
_
write_
serial
(
"++eos 2"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++eot_enable 0"
+
chr
(
10
))
self
.
_
write_
serial
(
"++eot_enable 0"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++eot_char 0"
+
chr
(
10
))
self
.
_
write_
serial
(
"++eot_char 0"
+
chr
(
10
))
self
.
_serial
Port
.
write
(
"++read_tmo_ms 500"
+
chr
(
10
))
self
.
_
write_
serial
(
"++read_tmo_ms 500"
+
chr
(
10
))
def
_find_devices
(
self
):
def
_find_devices
(
self
):
self
.
_devices
=
[]
self
.
_devices
=
[]
...
@@ -84,7 +91,7 @@ class PrologixGpibUsb(PortDevice):
...
@@ -84,7 +91,7 @@ class PrologixGpibUsb(PortDevice):
commandStr
=
"++addr "
+
str
(
address
)
+
chr
(
10
)
+
\
commandStr
=
"++addr "
+
str
(
address
)
+
chr
(
10
)
+
\
"*idn?"
+
chr
(
10
)
+
\
"*idn?"
+
chr
(
10
)
+
\
"++read"
+
chr
(
10
)
"++read"
+
chr
(
10
)
self
.
_serial
Port
.
write
(
commandStr
)
self
.
_
write_
serial
(
commandStr
)
returnStr
=
self
.
_serialPort
.
readline
()
returnStr
=
self
.
_serialPort
.
readline
()
if
returnStr
!=
""
:
if
returnStr
!=
""
:
self
.
_devices
+=
[
address
,
returnStr
]
self
.
_devices
+=
[
address
,
returnStr
]
...
@@ -94,7 +101,7 @@ class PrologixGpibUsb(PortDevice):
...
@@ -94,7 +101,7 @@ class PrologixGpibUsb(PortDevice):
command
=
"++addr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
command
command
=
"++addr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
command
self
.
_hpib_address
=
hpib_address
self
.
_hpib_address
=
hpib_address
self
.
_serial
Port
.
write
(
command
+
chr
(
10
))
self
.
_
write_
serial
(
command
+
chr
(
10
))
def
query
(
self
,
hpib_address
,
query
,
count
=
80
):
def
query
(
self
,
hpib_address
,
query
,
count
=
80
):
if
hpib_address
!=
self
.
_hpib_address
:
if
hpib_address
!=
self
.
_hpib_address
:
...
@@ -102,13 +109,13 @@ class PrologixGpibUsb(PortDevice):
...
@@ -102,13 +109,13 @@ class PrologixGpibUsb(PortDevice):
self
.
_hpib_address
=
hpib_address
self
.
_hpib_address
=
hpib_address
query
+=
chr
(
10
)
+
"++read eoi"
+
chr
(
10
)
query
+=
chr
(
10
)
+
"++read eoi"
+
chr
(
10
)
self
.
_serial
Port
.
write
(
query
)
self
.
_
write_
serial
(
query
)
line
=
self
.
_serialPort
.
readline
()
line
=
self
.
_serialPort
.
readline
()
return
line
[:
-
1
]
return
line
[:
-
1
]
def
set_local
(
self
,
hpib_address
):
def
set_local
(
self
,
hpib_address
):
# self._commandStr = "++addr "+str(hpib_address)+chr(10)+"loc "+str(hpib_address)+chr(10)
# self._commandStr = "++addr "+str(hpib_address)+chr(10)+"loc "+str(hpib_address)+chr(10)
# self._commandCount = self._serial
Port.write
(self._commandStr)
# self._commandCount = self._
write_
serial(self._commandStr)
return
return
def
get_devices
(
self
):
def
get_devices
(
self
):
...
@@ -126,22 +133,22 @@ class GPIB_232_485CT_A(PortDevice):
...
@@ -126,22 +133,22 @@ class GPIB_232_485CT_A(PortDevice):
def
command
(
self
,
hpib_address
,
command
):
def
command
(
self
,
hpib_address
,
command
):
self
.
_commandStr
=
"wr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
command
+
chr
(
13
)
self
.
_commandStr
=
"wr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
command
+
chr
(
13
)
self
.
_commandCount
=
self
.
_serial
Port
.
write
(
self
.
_commandStr
)
self
.
_commandCount
=
self
.
_
write_
serial
(
self
.
_commandStr
)
def
query
(
self
,
hpib_address
,
query
,
count
=
80
):
def
query
(
self
,
hpib_address
,
query
,
count
=
80
):
# flushInput should not be necessary
# flushInput should not be necessary
# self._serialPort.flushInput()
# self._serialPort.flushInput()
self
.
_commandStr
=
"wr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
query
+
chr
(
13
)
self
.
_commandStr
=
"wr "
+
str
(
hpib_address
)
+
chr
(
10
)
+
query
+
chr
(
13
)
self
.
_commandCount
=
self
.
_serial
Port
.
write
(
self
.
_commandStr
)
self
.
_commandCount
=
self
.
_
write_
serial
(
self
.
_commandStr
)
self
.
_queryStr
=
"rd #"
+
str
(
count
)
+
" "
+
str
(
hpib_address
)
+
chr
(
13
)
self
.
_queryStr
=
"rd #"
+
str
(
count
)
+
" "
+
str
(
hpib_address
)
+
chr
(
13
)
self
.
_queryCount
=
self
.
_serial
Port
.
write
(
self
.
_queryStr
)
self
.
_queryCount
=
self
.
_
write_
serial
(
self
.
_queryStr
)
self
.
_returnStr
=
self
.
_serialPort
.
read
(
count
)
self
.
_returnStr
=
self
.
_serialPort
.
read
(
count
)
self
.
_returnCnt
=
int
(
self
.
_serialPort
.
readline
())
self
.
_returnCnt
=
int
(
self
.
_serialPort
.
readline
())
return
self
.
_returnStr
[:
self
.
_returnCnt
-
1
]
return
self
.
_returnStr
[:
self
.
_returnCnt
-
1
]
def
set_local
(
self
,
hpib_address
):
def
set_local
(
self
,
hpib_address
):
self
.
_commandStr
=
"loc "
+
str
(
hpib_address
)
+
chr
(
13
)
self
.
_commandStr
=
"loc "
+
str
(
hpib_address
)
+
chr
(
13
)
self
.
_commandCount
=
self
.
_serial
Port
.
write
(
self
.
_commandStr
)
self
.
_commandCount
=
self
.
_
write_
serial
(
self
.
_commandStr
)
class
HpibDevice
(
object
):
class
HpibDevice
(
object
):
...
...
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