File: srq_device.py

package info (click to toggle)
linux-gpib-user 4.3.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,752 kB
  • sloc: ansic: 10,381; perl: 1,120; xml: 375; makefile: 335; yacc: 335; tcl: 308; python: 173; php: 157; lex: 144; sh: 134; lisp: 94
file content (44 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
sys.path.append('/usr/local/lib64/python3.9/site-packages')
import gpib

board  = 1
device = 1

def query(handle, command, numbytes=100):
        gpib.write(handle,command)
        response = gpib.read(handle,numbytes)
        response = response.rstrip("\r\n")
        return response

def initialise_device(handle):         # set up device to assert SRQ/RQS
        gpib.write(handle,"*CLS")      # Clear status registers
        gpib.write(handle,"*SRE 32")   # Assert SRQ on Event
        return

def show_devid(handle):                # Show device ID
        print query(handle,"*IDN?")      
        return

print gpib.version()                   # Show package version
ud = gpib.dev(board,device)            # Open the device
gpib.config(board,gpib.IbcAUTOPOLL,1)  # Enable automatic serial polling
gpib.config(ud,gpib.IbcTMO, gpib.T30s) # Set timeout to 30 seconds
show_devid(ud);
initialise_device(ud);
gpib.write(handle,"*TST;*OPC")         # Selftest and request OPC event
# Wait for Timeout or Request Service on device
sta = gpib.wait(ud, gpib.TIMO | gpib.RQS)
if (sta & gpib.TIMO) != 0:
   print "Timed out"
else:
    print "Device asserted RQS"
    stb = gpib.serial_poll(ud)          # Read status byte
    print "stb = %#x"%(stb)
    if (stb & gpib.IbStbESB) != 0:      # Check for Event Status bit
            esr = int(query(ud,"ESR?")) # Read Event Status Register
            if (esr & 1) != 0:          # Check for operation completed
                    print "Device Operation Completed"

# done  
gpib.close(ud)