VmeFunctions.py 2.04 KB
Newer Older
1
def VmeWrite(Addr, Data):
2 3
    MyString = 'W '+hex(Addr)[2:].strip('L')+' '+hex(Data)[2:].strip('L')+'\n'
    fd_Out=open('../simulation/Py2V.fifo', 'w')
4 5
    fd_Out.write(MyString)
    fd_Out.close() 
6
    fd_In=open('../simulation/V2Py.fifo', 'r')
7 8 9 10 11 12 13 14 15 16
    Strings=fd_In.readlines()
    ExitCode=int(Strings[0], 16)
    if ExitCode==1 :
        print "Write Action Timed Out @ Addr ", hex(Addr)
    elif  ExitCode==1 :
        print "Bus Error during Write cycle @ Addr ", hex(Addr)
    elif  ExitCode==1 :
        print "Retry request for Write @ Addr ", hex(Addr) 
    
def VmeRead(Addr):
17 18
    MyString = 'R '+hex(Addr)[2:].strip('L')+'\n'
    fd_Out=open('../simulation/Py2V.fifo', 'w')
19 20
    fd_Out.write(MyString)
    fd_Out.close() 
21
    fd_In=open('../simulation/V2Py.fifo', 'r')
22 23 24 25
    Strings =fd_In.readlines()
    fd_In.close() 
    [ExitCode, Value] =Strings[0:2]
    ExitCode = int(ExitCode, 16)
26 27 28 29 30
    try:
        Value = int(Value, 16)
    except:
        Value = 0
        print "Read out a not a number"
31
    if (ExitCode==1):
32
        print "Read Action Timed Out @ Addr ", hex(Addr).strip('L')
33
    elif  (ExitCode==1):
34
        print "Bus Error during Read cycle @ Addr ", hex(Addr).strip('L')
35
    elif  (ExitCode==1):
36
        print "Retry request for Read @ Addr ", hex(Addr).strip('L')
37 38 39 40
    return Value 

def VmeWaitInterrupt():
    MyString = 'I\n'
41
    fd_Out=open('../simulation/Py2V.fifo', 'w')
42 43
    fd_Out.write(MyString)
    fd_Out.close() 
44
    fd_In=open('../simulation/V2Py.fifo', 'r')
45 46 47 48 49 50 51 52 53 54 55 56 57 58
    Strings=fd_In.readlines()
    fd_In.close() 
    [IntLevel, IntVector]=['0', '0']
    ExitCode=   int(Strings[0], 16)
    if (ExitCode==0):   
        [IntLevel, IntVector]=Strings[1:3]
    elif (ExitCode==1):    
        print "Timeout: no interrupt received"
    elif (ExitCode==2):    
        print "Bus Error"
    else:
        print "Unknown status response from Wait Interrupt : "+  Strings[0]
    return [int(IntLevel, 16), int(IntVector, 16)] 

59 60 61 62 63 64 65 66
def VmeReset():
    MyString = 'X\n'
    fd_Out=open('../simulation/Py2V.fifo', 'w')
    fd_Out.write(MyString)
    fd_Out.close()