
Sefram
CHAPITRE 5. ADVANCED FEATURES
5.9
|
Examples
Bellow an example of a Python implementation
Listing 5.1: SCPI python implemntation exemple
i m p o r t
t i m e
i m p o r t
t e l n e t l i b
TIMEOUT = 0 . 5
# Timeout on frame r e c e i v e
PORT = 23
##################### Low l e v e l f u n c t i o n s #####################
# Remove end o f l i n e ch ar s t o p r i n t
d e f
extractCmd ( cmd ) :
cmd = cmd . r e p l a c e (
" \ n "
,
" "
)
cmd = cmd . r e p l a c e (
" \ r "
,
" "
)
r e t u r n
cmd
# Send a frame and w a i t f o r response
d e f
sendFrame ( tn , cmd ) :
cmd = cmd +
" \ n "
p r i n t
(
" >> Send : "
+ extractCmd ( cmd ) )
t n . w r i t e ( cmd . encode (
’ a s c i i ’
) )
r e s = t n . r e a d _ u n t i l ( b
’ \ n ’
, TIMEOUT ) . decode (
’ a s c i i ’
)
i f
l e n
( r e s ) == 0 :
p r i n t
(
" Timeout "
)
t i m e . s l e e p ( 1 )
e l s e
:
p r i n t
(
" << Rcv
: "
+ r e s )
r e t u r n
r e s
c l a s s
s c p i (
o b j e c t
) :
d e f
_ _ i n i t _ _ ( s e l f , i p ) :
s e l f . t n = t e l n e t l i b . T e l n e t ( i p , PORT, TIMEOUT )
d e f
runCmd ( s e l f , frame ) :
r e t u r n
sendFrame ( s e l f . tn , frame )
d e f
__del__ ( s e l f ) :
s e l f . t n . c l o s e ( )
s c p i I n s t = s c p i (
" 1 9 2 . 1 6 8 . 0 . 1 1 0 "
)
s c p i I n s t . runCmd (
’ *REM ’
)
s c p i I n s t . runCmd (
’ * IDN? ’
)
s c p i I n s t . runCmd (
’ VALID ? ’
)
s c p i I n s t . runCmd (
’ *LOC ’
)
5.10
|
User interface
The DAS interface connection state and error queue can be montitored to help debuging.
DAS
User manual
53