From ece149f2f5f8e07b2ed295f2a07ab0f569e5d09c Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Tue, 10 Oct 2017 13:36:58 +0200 Subject: [PATCH] Closedown --- script/local.py | 94 ++++++++++++++++++++++++++++++++++- script/pio.py | 7 +-- script/tests/tests.properties | 2 +- 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/script/local.py b/script/local.py index ccec05c..cdb9398 100644 --- a/script/local.py +++ b/script/local.py @@ -117,9 +117,99 @@ class TestingTool: ret = [self.testPath, self.deviceName, returnString, testPassed] set_return( ret) -class Pio: +class Interlock: + + # data acquisition definitions + IO_READ = 1 + sIO_WRITE = 2 + IO_DIGITAL = 3 + # mode, test pattern for outputs 2-4, test pattern for output 5, expected pattern for 2-4, expected pattern for 5 + rps_beamline = 0 + rps_mode = 1 + rps_expected1 = 2 + rps_expected2 = 3 + rps_mask1 = 0x4440 # mask for outputs 2-4 + rps_mask2 = 0x0004 # mask for output 5 + def __init__(self): self.log('ecco pio') def log(self, text): - print str(text) \ No newline at end of file + print str(text) + + + def setInterlockMode(self, mode) + i = 0 + d = UDPDatagram() + msg = byte[128] + msg[0] = 50 # bytecount + msg[2] = 105 # transfer function + msg[4] = (byte) PORT1 + msg[5] = (byte) (PORT1 >>> 8) + msg[6] = 1 # message id + msg[16] = 1 # io-func reset=2 read mode=0 write mode=1 + buffer = mode.getBytes() + while i < buffer.length: + msg[28 + i] = buffer[i] + i = i+1 + + d.listenInit() + d.send(Server, msg) + mess = d.listen() + if mess == null: + return false + else: + return true + +# ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** +# class for receiving and sending a udp message +# ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** + + +class UDPDatagram: + import socket + + # the constructor + def __init__(self): + # communication with interlock server + self.serverPort = 0xBB1B # interlock server + self.thisPort = 0x8899 # this port + self.serverName = 'PROMC1' # ball server + try: + self.sock = socket.socket(socket.AF_INET, # Internet + socket.SOCK_DGRAM) # UDP + except socket.error, msg: + print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] + sys.exit() + + # sending + def _sendUDP(self, recipient, message): + try: + # get the ip address and send + ipAddress = recipient + self.sock.sendto(message, (ipAddress, PORT)) + except socket.error, msg: + print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] + sys.exit() + + def _listenInit(self): + try: + self.sock.bind('', self.ThisPort) + except socket.error, msg: + print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] + sys.exit() + print 'Socket bind complete. ' + + def _listen(self): + # now keep talking with the client + while 1: + # receive data from client (data, addr) + data, addr = self.sock.recvfrom(1024) + if not data: + print 'End of data or no data' + break + print 'Message[' + addr[0] + ':' + str(addr[1]) + '] - ' + data.strip() + + self.sock.close() + return data[28:] + diff --git a/script/pio.py b/script/pio.py index 3e05df2..1099785 100644 --- a/script/pio.py +++ b/script/pio.py @@ -10,11 +10,6 @@ global print_log, sendFeedback, sys, inspect, os, traceback import sys, inspect, os, traceback -class Pio: - def __init__(self): - self.log('ecco pio') - - def log(self, text): - print str(text) + diff --git a/script/tests/tests.properties b/script/tests/tests.properties index b451961..fad07cd 100644 --- a/script/tests/tests.properties +++ b/script/tests/tests.properties @@ -1,5 +1,5 @@ #TestingList for pshell: configuration properties -#Mon Oct 09 14:58:56 CEST 2017 +#Tue Oct 10 13:36:47 CEST 2017 customPanel= showEnabledTestsOnly=true listFilter=rps-try