def test_run(ls_channel, fs_input_channel, logfile, iDevIdx, iModuleType, iSlotID): print "Installation Testing (Test Run) - Testing Laser Switch Channel: " + str(ls_channel) set_laser_switch_channel(ls_channel) sepiaUser.set_laser_intensity(100, iDevIdx) # set the intensity to 100% #sepiaUser.set_laser_frequency(4, iDevIdx) # this is the internal 5MHz trigger frequency ... use to check if Sepia is working properly for fs_output_channel in range(1, 15): channel_number = ((fs_input_channel - 1) * 14) + fs_output_channel fs.SetFSChannel(channel_number) # set the fibreSwitch channel sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(1) # this section of code is for generating a pulse via the NI Box, and reading the PMT value trigger_frequency = 10000 number_of_pulses = 100000 digi_trig = ni.GenerateDigitalTrigger(trigger_frequency, number_of_pulses) read_signal = ni.AcquireAnalogue() number_of_measurements = 1 voltage_signal = str(read_signal.start(number_of_measurements)) digi_trig.start() digi_trig.stop() read_signal = ni.AcquireAnalogue() a = raw_input("Generating pulse train ... press Enter to interrupt ...\n") read_signal.stop() logfile.write(str(ls_channel) + '\t' + str(channel_number) + '\t' + voltage_signal[1:-1] + '\n') sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID)
def check_safe_states(iDevIdx, iSlotID, connection): intensity,frequency_number,pulse_mode,head_id = sepiaUser.get_laser_parameters(iDevIdx) ls_channel = rs.GetActiveChannel() # Check the active channel on the laserSwitch if (intensity != 0): print 'Simple TCP/IP Run (Check Safe States) - The laser Intensity is not at SAFE value (0%)' sepiaUser.set_laser_intensity(0, iDevIdx) connection.send(sepia_wrong_set_intensity_flag) main() # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (frequency_number != 6): print 'Simple TCP/IP Run (Check Safe States) - The laser Frequency is not at SAFE value (6 - external rising edge)' sepiaUser.set_laser_frequency(6, iDevIdx) connection.send(sepia_wrong_freq_flag) main() # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (pulse_mode != 1): print 'Simple TCP/IP Run (Check Safe States) - The laser Pulse Mode is not set correctly (1 - pulse mode, NOT continuous)' connection.send(sepia_wrong_pulse_mode_flag) main() # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (ls_channel != 0): print "Simple TCP/IP Run (Check Safe States) - The Laser Switch channel is not set to SAFE value (0)" rs.SetSelectedChannel(0) rs.Execute() connection.send(relay_switch_wrong_default_flag) main() else: print "Simple TCP/IP Run (Check Safe States) - All Safe States are Correctly Set" connection.send(continue_flag) return
def set_to_safe_state(iDevIdx, iSlotID): sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # turn the laser soft-lock on sepiaUser.set_laser_intensity(0, iDevIdx) # set the laser intensity to 0% sepiaUser.set_laser_frequency(6, iDevIdx) # set the laser to trigger on the rising edge of an external pulse rs.SetSelectedChannel(0) # set the laserSwitch to channel 0 (default channel) sepiaUser.close(iDevIdx) rs.Execute() # execute the laserSwitch channel change
def initialSetLaser(ls_channel,operation_mode,intensity): iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() set_laser_switch_channel(ls_channel) sepiaUser.set_laser_intensity(intensity, iDevIdx) # set the intensity to 100% sepiaUser.set_laser_frequency(operation_mode, iDevIdx) sepiaUser.close(iDevIdx)
def set_safe_states(iDevIdx, iSlotID): #sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # turn the laser soft-lock on sepiaUser.set_laser_intensity(0, iDevIdx) # set the laser intensity to 0% sepiaUser.set_laser_frequency(6, iDevIdx) # set the laser frequency to external rising-edge trigger rs.SetSelectedChannel(0) # set the laserSwitch to channel 0 (default) sepiaUser.close(iDevIdx) rs.Execute() # execute the laserSwitch channel change from above
def check_safe_states(iDevIdx, iSlotID, connection): intensity, frequency_number, pulse_mode, head_id = sepiaUser.get_laser_parameters( iDevIdx) ls_channel = rs.GetActiveChannel( ) # Check the active channel on the laserSwitch if (intensity != 0): print 'Simple TCP/IP Run (Check Safe States) - The laser Intensity is not at SAFE value (0%)' sepiaUser.set_laser_intensity(0, iDevIdx) connection.send(sepia_wrong_set_intensity_flag) main( ) # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (frequency_number != 6): print 'Simple TCP/IP Run (Check Safe States) - The laser Frequency is not at SAFE value (6 - external rising edge)' sepiaUser.set_laser_frequency(6, iDevIdx) connection.send(sepia_wrong_freq_flag) main( ) # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (pulse_mode != 1): print 'Simple TCP/IP Run (Check Safe States) - The laser Pulse Mode is not set correctly (1 - pulse mode, NOT continuous)' connection.send(sepia_wrong_pulse_mode_flag) main( ) # Cancel the run, and only continue if a new TCP/IP (ORCA) command is sent if (ls_channel != 0): print "Simple TCP/IP Run (Check Safe States) - The Laser Switch channel is not set to SAFE value (0)" rs.SetSelectedChannel(0) rs.Execute() connection.send(relay_switch_wrong_default_flag) main() else: print "Simple TCP/IP Run (Check Safe States) - All Safe States are Correctly Set" connection.send(continue_flag) return
def set_safe_states(iDevIdx, iSlotID): sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # turn the laser soft-lock on sepiaUser.set_laser_intensity(0, iDevIdx) # set the laser intensity to 0% sepiaUser.set_laser_frequency( 6, iDevIdx) # set the laser frequency to external rising-edge trigger rs.SetSelectedChannel(0) # set the laserSwitch to channel 0 (default) sepiaUser.close(iDevIdx) rs.Execute() # execute the laserSwitch channel change from above
def set_laser_intensity(intensity): retValue = 0 try: print "Set Laser Intensity to " + str(intensity) + "%" iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() time.sleep(1.0) sepiaUser.set_laser_intensity(int(intensity), iDevIdx) time.sleep(1.0) sepiaUser.close(iDevIdx) except errorCode, Argument: retValue = "Error: " + str(errorCode) + " " + str(Argument)
def set_safe_states(): retValue = 0 try: iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() #sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # turn the laser soft-lock on sepiaUser.set_laser_intensity(0, iDevIdx) # set the laser intensity to 0% sepiaUser.set_laser_frequency(6, iDevIdx) # set the laser frequency to external rising-edge trigger rs.SetSelectedChannel(0) # set the laserSwitch to channel 0 (default) sepiaUser.close(iDevIdx) rs.Execute() # execute the laserSwitch channel change from above except errorCode, Argument: retValue = "Error: " + str(errorCode) + " " + str(Argument)
def test_run(ls_channel, fs_input_channel, iDevIdx, iModuleType, iSlotID): print "Installation Testing (Test Run) - Testing Laser Switch Channel: " + str(ls_channel) set_laser_switch_channel(ls_channel) sepiaUser.set_laser_intensity(100, iDevIdx) # set the intensity to 100% sepiaUser.set_laser_frequency(2, iDevIdx) # this is the internal 5MHz trigger frequency ... use to check if Sepia is working properly for fs_output_channel in range(1, 15): channel_number = ((fs_input_channel - 1) * 14) + fs_output_channel fs.SetFSChannel(channel_number) # set the fibreSwitch channel sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(10) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID)
def set_safe_states(iDevIdx, iSlotID): sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # turn the laser soft-lock on #print "setting laser intensity safe state" sepiaUser.set_laser_intensity(0, iDevIdx) # set the laser intensity to 0% #print "setting laser frequency safe state" sepiaUser.set_laser_frequency(6, iDevIdx) # set the laser frequency to external rising-edge trigger 6 as default #print "switching channel safe state" rs.SetSelectedChannel(safeLaserSwitchOutput) # set the laserSwitch to channel 0 (default) #print "initialising laser into safestates" sepiaUser.close(iDevIdx) #sys.exit("forced exit for testing") #time.sleep(10) #print "execute and wait" rs.Execute() # execute the laserSwitch channel change from above
def cycleFibreSwitch(fs_input_channel,ls_channel): operation_mode = 6 iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() set_to_safe_state(iDevIdx, iSlotID) iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() set_laser_switch_channel(ls_channel) iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() # re-initialise Sepia sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # soft lock on sepiaUser.set_laser_frequency(operation_mode, iDevIdx) intensity_value = 0 print "FibreSwitchInput:" + str(fs_input_channel) print "LaserChannel:" + str(ls_channel) for intensity_iterator in range(0,80): intensity_value = 100 - intensity_iterator sepiaUser.set_laser_intensity(intensity_value, iDevIdx) for fs_output_channel in range(7, 13): channel_number = ((fs_input_channel - 1) * 14) + fs_output_channel print "Intensity Value:" + str(intensity_value) +" FibreSwitchOutput:" + str(fs_output_channel) fs.SetFSChannel(channel_number) # set the fibreSwitch channel sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(5) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) time.sleep(1) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # soft lock on sepiaUser.close(iDevIdx) # close the Sepia box down... time.sleep(1)
def setLaserAndFibreSwitch(ls_channel,fs_input_channel,fs_output_channel,time_in_minutes,operation_mode,intensity): iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() set_to_safe_state(iDevIdx, iSlotID) # set all the laser parameters to safe values set_laser_switch_channel(ls_channel) sepiaUser.set_laser_intensity(intensity, iDevIdx) # set the intensity to 100% sepiaUser.set_laser_frequency(operation_mode, iDevIdx) channel_number = ((fs_input_channel - 1) * 14) + fs_output_channel # pick the correct channel number print(channel_number) fs.SetFSChannel(channel_number) # set the fibreSwitch channel laserTime = time_in_minutes*60.0 # time for program to wait before locking the laser (i.e. laser operating time) sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(laserTime) # make Python sleep while laser is working iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() # re-initialise Sepia sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # soft lock on sepiaUser.close(iDevIdx) # close the Sepia box down... time.sleep(1)
def check_safe_states(iDevIdx, iSlotID): # Get the current states of Sepia and the LaserSwitch intensity,frequency_number,pulse_mode,head_id = sepiaUser.get_laser_parameters(iDevIdx) ls_channel = rs.GetActiveChannel() if (intensity != 0): sepiaUser.set_laser_intensity(0, iDevIdx) sys.exit('Simple Run (Check Safe States) - The laser Intensity is not at SAFE value (0%)') if (frequency_number != 6): sepiaUser.set_laser_frequency(6, iDevIdx) sys.exit('Simple Run (Check Safe States) - The laser Frequency is not at SAFE value (6 - external rising edge)') if (pulse_mode != 1): sys.exit('Simple Run (Check Safe States) - The laser Pulse Mode is not set correctly (1 - pulse mode, NOT continuous)') if (ls_channel != 0): rs.SetSelectedChannel(0) rs.Execute() sepiaUser.close(iDevIdx) sys.exit('Simple Run (Check Safe States) - The Laser Switch safe-state is not correctly set ... aborting run!') # Check the laser soft-lock status lock_check = sepiaUser.get_laser_lock_status(iDevIdx, iSlotID) if (laser_lock_on_check != 1): sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) sys.exit('Simple Run (Check Safe States) - Laser Soft-lock is not enabled ... aborting run!') return
def test_run(ls_channel, fs_input_channel, logfile, iDevIdx, iModuleType, iSlotID): print "Installation Testing (Test Run) - Testing Laser Switch Channel: " + str(ls_channel) set_laser_switch_channel(ls_channel) sepiaUser.set_laser_intensity(100, iDevIdx) # set the intensity to 100% sepiaUser.set_laser_frequency(4, iDevIdx) # this is the internal 5MHz trigger frequency ... use to check if Sepia is working properly for fs_output_channel in range(1, 15): channel_number = ((fs_input_channel - 1) * 14) + fs_output_channel fs.SetFSChannel(channel_number) # set the fibreSwitch channel sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(1) # this section of code is for generating a pulse via the NI Box, and reading the PMT value trigger_frequency = 10000 number_of_pulses = 100000 digi_trig = ni.GenerateDigitalTrigger(trigger_frequency, number_of_pulses) read_signal = ni.AcquireAnalogue() number_of_measurements = 1 voltage_signal = str(read_signal.start(number_of_measurements)) digi_trig.start() digi_trig.stop()
def main(): myHost = '' # initialise the server machine ('' means: local host) myPort = 50009 # listen on a non-reserved port number conn.sockobj = conn.socket(conn.AF_INET, conn.SOCK_STREAM) # make a TCP/IP socket object conn.sockobj.settimeout(None) # No timeout on the socket conn.sockobj.setsockopt(conn.SOL_SOCKET,conn.SO_REUSEADDR,1) conn.sockobj.bind((myHost, myPort)) # bind the socket object to the specified server and port number conn.sockobj.listen(5) # begin listening, and allow 5 pending connects # Check for connection confimation from ORCA print "Simple TCP/IP Run (Main) - Checking for connection confimation from ORCA ... " while 1: # listen until process killed connection, address = conn.sockobj.accept() # wait for next client connection print 'Connection made to:' + str(address) # connection is a new socket if address : break connection.send(str(check_connection_flag)) # send signal to ORCA to check connection controlFlag = '0' controlArgument = '0' master_mode_trigger_frequency = '0' master_mode_number_of_pulses = '0' # Get the control flag connection.settimeout(5) try: while 1: controlFlag = connection.recv(1024) #print "ControlFlag = " + str(controlFlag) break except conn.timeout: connection.send(timeout_flag) main() connection.send(str(check_connection_flag)) # Get the control argument connection.settimeout(5) try: while 1: controlArgument = connection.recv(1024) break except conn.timeout: connection.send(timeout_flag) main() connection.send(str(check_connection_flag)) #connection.send(str(check_connection_flag)) #send this to signify that this is finished #main() #print "ControlFlag = " + str(controlFlag) #controlFlag = 60 try: #print 'controlFlag: ' + str(controlFlag) #print 'laser intensity flag' + str(set_laser_intensity_flag) # set the laser switch channel if (int(controlFlag) == int(set_laser_switch_flag)): print "Set the Laser switch to state" + str(controlArgument) iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() rs.SetSelectedChannel(int(controlArgument)) sepiaUser.close(iDevIdx) rs.Execute() # set safe sates elif (int(controlFlag) == int(set_safe_states_flag)): print "Setting to safe states" iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() set_safe_states(iDevIdx, iSlotID) # set fibre switch channel elif (int(controlFlag) == int(set_fibre_switch_channel_flag)): print(controlArgument) input_channel,output_channel = extractLaserFibreValues(controlArgument) print "Set the Fibre Switch to input Channel:" + str(input_channel) +" and output channel:" + str(output_channel) fs.SetIOChannels(int(input_channel), int(output_channel)) # fs.SetFSChannel(controlArgument) # set laser intensity elif (int(controlFlag) == int(set_laser_intensity_flag)): print "Set Laser Intensity to " + str(controlArgument) + "%" iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() time.sleep(1.0) sepiaUser.set_laser_intensity(int(controlArgument), iDevIdx) time.sleep(1.0) sepiaUser.close(iDevIdx) # set soft lock on elif (int(controlFlag) == int(set_laser_soft_lock_on_flag)): print "Set laser soft lock on" iDevIdx,iModuleType,iSlotID = sepiaUser.initialiseSCMModule() time.sleep(1.0) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) time.sleep(1.0) sepiaUser.close(iDevIdx) # start master mode run elif (int(controlFlag) == int(master_mode_flag)): master_mode_trigger_frequency,master_mode_number_of_pulses = extractMasterModeFromCode(controlArgument) print "Starting a Master mode sub run with trig frequency: " + str(master_mode_trigger_frequency) + "Hz and num_of_pulses:" + str(master_mode_number_of_pulses) #iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() #time.sleep(1.0) #iDevIdx2,iModuleType2,iSlotID2 = sepiaUser.initialiseSCMModule() #sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID2) #time.sleep(1.0) digi_trig = ni.GenerateDigitalTrigger(int(master_mode_trigger_frequency), int(master_mode_number_of_pulses)) digi_trig.start() digi_trig.stop() #sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID2) #time.sleep(1.0) #sepiaUser.close(iDevIdx) #sepiaUser.close(iDevIdx2) # set soft lock off elif (int(controlFlag) == int(set_laser_soft_lock_off_flag)): print "Set laser soft lock off" iDevIdx,iModuleType,iSlotID = sepiaUser.initialiseSCMModule() time.sleep(1.0) print sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) time.sleep(1.0) sepiaUser.close(iDevIdx) # set the laser frequency to high enough to see visually elif (int(controlFlag) == int(set_laser_testing_frequency_mode)): print "Setting laser to 20MHz testing Mode" iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() sepiaUser.set_laser_frequency(2, iDevIdx) # set the laser frequency to 20Mhz sepiaUser.close(iDevIdx) else: print "No command value recieved" # put all the possible options in here except: connection.send(timeout_flag) main() connection.send(str(check_connection_flag)) #send this to signify that this is finished print "Return to listening on the port" main() # return to listening on the port
iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() # need to reinitialise Sepia after turning off during the changing of the laserSwitch channel (part of set_safe_states) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) check_safe_states(iDevIdx, iSlotID, connection) # check that all devices are in their safe-states rs.SetSelectedChannel(0) # set the laserSwitch channel to 1 sepiaUser.close(iDevIdx) rs.Execute() # execute the laserSwitch channel change iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() # need to reinitialise Sepia after turning off during the changing of the laserSwitch channel (part of SetSelectedChannel) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # Set all Parameters (all must be INTEGERS) input_intensity = 100 input_frequency = 4 input_rs_channel = 1 input_fs_channel = 1 sepiaUser.set_laser_intensity(input_intensity, iDevIdx) # set the laser intensity to 100% sepiaUser.set_laser_frequency(input_frequency, iDevIdx) # set the laser frequency to Internal 5MHz sepiaUser.close(iDevIdx) fs.SetFSChannel(input_fs_channel) # set the fibreSwitch channel to 1 #sys.exit("Simple Run (Main) - Forced Exit after Set Parameters stage") check_current_states(iDevIdx, iSlotID, input_intensity, input_frequency) sepiaUser.laser_soft_lock_off(iDevIdx, iSlotID) # unlock the laser time.sleep(30) # pulse the laser for 30 seconds sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) # lock the laser again after pulsing is complete set_safe_states(iDevIdx, iSlotID) # set all laser parameter to their safe-state values iDevIdx,iModuleType,iSlotID = sepiaUser.initialise() # need to reinitialise Sepia after turning off during the changing of the laserSwitch channel (part of set_safe_states) sepiaUser.laser_soft_lock_on(iDevIdx, iSlotID) check_safe_states(iDevIdx, iSlotID, connection) # check that all devices are in their safe-states