diff --git a/config/config.properties b/config/config.properties index 2c330f7..8a5cf4f 100644 --- a/config/config.properties +++ b/config/config.properties @@ -1,4 +1,4 @@ -#Mon Jan 13 15:27:01 CET 2020 +#Wed Jan 15 14:27:45 CET 2020 imageSourcesFile={config}/imaging.properties autoSaveScanData=true simulation=false @@ -26,7 +26,7 @@ dataScanPreserveTypes=false logLevel=Info dataScanFlushRecords=true logPath={logs}/{date}_{time} -dataLayout=ch.psi.fda.LayoutFDA +dataLayout=table deviceUpdateStrategyFile={config}/update.properties terminalEnabled=false notificationLevel=null @@ -35,5 +35,5 @@ tasksFile={config}/tasks.properties createSessionFiles=true versionTrackingLogin={context}/svcusr-hlapp_robot versionTrackingRemote=git@git.psi.ch\:pshell_config/x11ma.git -dataProvider=ch.psi.fda.ProviderFDA +dataProvider=csv saveCommandStatistics=false diff --git a/config/variables.properties b/config/variables.properties index a644466..ebd2965 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,2 +1,2 @@ -#Wed Jan 15 09:15:11 CET 2020 -FileSequentialNumber=88 +#Wed Jan 15 15:13:39 CET 2020 +FileSequentialNumber=186 diff --git a/plugins/Eiger.form b/plugins/Eiger.form index 8a82844..64a12b6 100644 --- a/plugins/Eiger.form +++ b/plugins/Eiger.form @@ -1109,17 +1109,19 @@ - - - - - - - - - - - + + + + + + + + + + + + + @@ -1127,8 +1129,8 @@ - - + + @@ -1153,44 +1155,52 @@ - - - - - - + + + + + + + + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - @@ -1258,6 +1268,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
+
diff --git a/plugins/Eiger.java b/plugins/Eiger.java index ac9850d..5b81fab 100644 --- a/plugins/Eiger.java +++ b/plugins/Eiger.java @@ -60,6 +60,7 @@ public class Eiger extends Panel { final Component[] parameterControls; final ArrayList rois = new ArrayList<>(); + final DefaultTableModel modelRegions; public Eiger() { initComponents(); @@ -121,6 +122,7 @@ public class Eiger extends Panel { } } }); + modelRegions = (DefaultTableModel) tableRegions.getModel(); } //Overridable callbacks @@ -167,6 +169,9 @@ public class Eiger extends Panel { buttonImgStart.setEnabled(getState() == State.Ready); buttonImgAbort.setEnabled(getState().isProcessing()); + + buttonSpecStart.setEnabled(getState() == State.Ready); + buttonSpecAbort.setEnabled(getState().isProcessing()); } void updateRoiList() { @@ -274,6 +279,15 @@ public class Eiger extends Panel { } void runAbsSpectrum() throws Context.ContextStateException { + List ranges = new ArrayList(); + for (int i=0; i { @@ -381,6 +396,11 @@ public class Eiger extends Panel { spinnerSpecExp = new javax.swing.JSpinner(); checkSpecWithI0 = new javax.swing.JCheckBox(); checkSpecSaveSpectrum = new javax.swing.JCheckBox(); + jPanel4 = new javax.swing.JPanel(); + jScrollPane2 = new javax.swing.JScrollPane(); + tableRegions = new javax.swing.JTable(); + buttonAdd = new javax.swing.JButton(); + buttonRemove = new javax.swing.JButton(); buttonSpecStart = new javax.swing.JButton(); buttonSpecAbort = new javax.swing.JButton(); @@ -1066,6 +1086,69 @@ public class Eiger extends Panel { checkSpecSaveSpectrum.setSelected(true); checkSpecSaveSpectrum.setText("Save spectrum"); + jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Ranges")); + + tableRegions.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Start", "End", "Step" + } + ) { + Class[] types = new Class [] { + java.lang.Double.class, java.lang.Double.class, java.lang.Double.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + }); + jScrollPane2.setViewportView(tableRegions); + + buttonAdd.setText("Add"); + buttonAdd.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAddActionPerformed(evt); + } + }); + + buttonRemove.setText("Remove"); + buttonRemove.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonRemoveActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); + jPanel4.setLayout(jPanel4Layout); + jPanel4Layout.setHorizontalGroup( + jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel4Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel4Layout.createSequentialGroup() + .addComponent(buttonAdd) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE) + .addComponent(buttonRemove))) + .addContainerGap()) + ); + + jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAdd, buttonRemove}); + + jPanel4Layout.setVerticalGroup( + jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel4Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonAdd) + .addComponent(buttonRemove)) + .addContainerGap()) + ); + javax.swing.GroupLayout panelSpectrumLayout = new javax.swing.GroupLayout(panelSpectrum); panelSpectrum.setLayout(panelSpectrumLayout); panelSpectrumLayout.setHorizontalGroup( @@ -1078,41 +1161,47 @@ public class Eiger extends Panel { .addComponent(jLabel25)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(checkSpecSwitchPol) .addComponent(checkSpecWithI0) .addComponent(checkSpecSaveImages) - .addComponent(checkSpecSwitchPol) .addComponent(checkSpecSaveSpectrum) .addComponent(spinnerSpecScans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerSpecExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerSpecAvg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) ); panelSpectrumLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerSpecAvg, spinnerSpecExp, spinnerSpecScans}); panelSpectrumLayout.setVerticalGroup( panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSpectrumLayout.createSequentialGroup() + .addGroup(panelSpectrumLayout.createSequentialGroup() .addContainerGap() - .addComponent(checkSpecSaveSpectrum) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(checkSpecSaveImages) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(checkSpecWithI0) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel23) - .addComponent(spinnerSpecExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel24) - .addComponent(spinnerSpecAvg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel25) - .addComponent(spinnerSpecScans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(checkSpecSwitchPol) + .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelSpectrumLayout.createSequentialGroup() + .addComponent(checkSpecSaveSpectrum) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(checkSpecSaveImages) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(checkSpecWithI0) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel23) + .addComponent(spinnerSpecExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel24) + .addComponent(spinnerSpecAvg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(panelSpectrumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel25) + .addComponent(spinnerSpecScans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 19, Short.MAX_VALUE) + .addComponent(checkSpecSwitchPol) + .addGap(0, 11, Short.MAX_VALUE)) + .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); @@ -1135,15 +1224,16 @@ public class Eiger extends Panel { jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addGap(211, 211, 211) - .addComponent(panelSpectrum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(215, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonSpecStart) - .addGap(76, 76, 76) - .addComponent(buttonSpecAbort) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap() + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() + .addGap(0, 224, Short.MAX_VALUE) + .addComponent(buttonSpecStart) + .addGap(76, 76, 76) + .addComponent(buttonSpecAbort) + .addGap(0, 224, Short.MAX_VALUE)) + .addComponent(panelSpectrum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) ); jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonSpecAbort, buttonSpecStart}); @@ -1152,8 +1242,8 @@ public class Eiger extends Panel { jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() - .addComponent(panelSpectrum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE) + .addComponent(panelSpectrum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(33, 33, 33) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonSpecStart) .addComponent(buttonSpecAbort)) @@ -1290,10 +1380,23 @@ public class Eiger extends Panel { } }//GEN-LAST:event_buttonTriggerDetectorActionPerformed + private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed + modelRegions.addRow(new Object[]{Double.NaN, Double.NaN, Double.NaN}); + }//GEN-LAST:event_buttonAddActionPerformed + + private void buttonRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveActionPerformed + int row = tableRegions.getSelectedRow(); + if (row>=0){ + modelRegions.removeRow(row); + } + }//GEN-LAST:event_buttonRemoveActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAdd; private javax.swing.JButton buttonDefaultPath; private javax.swing.JButton buttonImgAbort; private javax.swing.JButton buttonImgStart; + private javax.swing.JButton buttonRemove; private javax.swing.JButton buttonRoiAdd; private javax.swing.JButton buttonRoiRemove; private javax.swing.JButton buttonSetPath; @@ -1346,10 +1449,12 @@ public class Eiger extends Panel { private javax.swing.JPanel jPanel10; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; + private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JLabel labelSwitching; private javax.swing.JPanel panelBeamline; @@ -1376,6 +1481,7 @@ public class Eiger extends Panel { private javax.swing.JSpinner spinnerSpecAvg; private javax.swing.JSpinner spinnerSpecExp; private javax.swing.JSpinner spinnerSpecScans; + private javax.swing.JTable tableRegions; private javax.swing.JTable tableRoi; private javax.swing.JTextField textDataPath; // End of variables declaration//GEN-END:variables diff --git a/script/devices/eiger.py b/script/devices/eiger.py index 649117b..55c9e50 100644 --- a/script/devices/eiger.py +++ b/script/devices/eiger.py @@ -19,17 +19,35 @@ def integrate_roi(source, x,y, w, h): return roi.integrate(False) +class RoiIntensitySourceListener (ImageListener): + def __init__(self, parent): + self.parent = parent + def onImage(self, origin, image, data): + self.parent.update() + def onError(self, origin, ex): + pass + class RoiIntensity(ReadonlyRegisterBase): def __init__(self, name, source, x,y, w, h): ReadonlyRegisterBase.__init__(self, name) self.source=source self.roi = x,y, w, h + self.source_listener = RoiIntensitySourceListener(self) def doRead(self): x,y, w, h = self.roi return integrate_roi(self.source, x,y, w, h) + def doSetMonitored(self, value): + if value: + self.source.addListener(self.source_listener) + else: + self.source.removeListener(self.source_listener) + + def doClose(self): + self.source.removeListener(self.source_listener) + def create_roi_devices(roi_list, add = True): rois = [] for r in roi_list: @@ -99,17 +117,6 @@ def integrate_frames(frames): ret.sum(data) return ret -def get_ip_array(ip): - """ - Returns data array of ImagePlus - """ - if type(ip.getProcessor()) == FloatProcessor: - ret = ip.getProcessor().getFloatArray() - else: - ret = ip.getProcessor().getIntArray() - ret = Convert.reshape(ret, [ip.getHeight(), ip.getWidth()]) - return ret - def average_frames(frames): ret = integrate_frames(frames) if ret is not None: diff --git a/script/templates/Eiger2Img.py b/script/templates/Eiger2Img.py index e4b212c..e2467ef 100644 --- a/script/templates/Eiger2Img.py +++ b/script/templates/Eiger2Img.py @@ -29,6 +29,7 @@ if get_exec_pars().source == CommandSource.ui: DRY_RUN=True +SHOW_IMAGES = True EXPOSURE = [EXPOSURE_1, EXPOSURE_2] AVERAGE = [int(AVERAGE_1), int(AVERAGE_2)] @@ -41,19 +42,79 @@ if METHOD == "Two_Energies": if en < 89.9 or en > 2000: raise Exception("Bad energy argument") -set_exec_pars(path= path, format="txt", layout="table", open=True) path = "{data}/{year}_{month}/{date}" + "/" + METHOD + "_{seq}%03d" +set_exec_pars(path= path, format="txt", layout="table", open=True) data_path = get_context().setup.expandPath(path) #get_context().incrementFileSequentialNumber() - -frames = [None, None, None] -def get_image_file_name(cicle=-1, frame_index=0): - if cicle < 0: - return data_path + "/" + ("%04d" % i) + ".tif" - return data_path + "/" + str(cycle) + "_" + str(MEASUREMENTS) + "_" + ("%04d" % frame_index) + ".tif" +def get_image_file_name(cycle=-1, frame_index=0, short_name=False): + root = "" if short_name else (data_path + "/") + if cycle < 0: + return root + ("%04d" % i) + ".tif" + return root + str(cycle) + "_" + str(MEASUREMENTS) + "_" + ("%04d" % frame_index) + ".tif" +""" +def getLEEM(): + global startvoltage,objective, LEEMtemp + startvoltage=getStartvoltage() + objective=getObjective() + LEEMtemp=getLEEMtemp() +""" + + + +def assert_status_ok(): + if DRY_RUN: return + assert_machine_ok() + assert_beamline_ok() + """ + getbeamline + getLEEM + Rem check status of machine + If checkRing = 3 Then + Close + Exit Sub + End If + Rem check status of the beamline + If checkbeamline = 3 Then + Close + Exit Sub + """ + +#Initialize vartiables + +active_id = 1 +current_pol=None +polID1=None +polID2=None +#rbkEnergy=energy_rbk.read() +if METHOD == "Two_Pol": + if ID == "ID1": + current_pol=POL_IDS[POL_ID_1] #get_id_pol(1) + put_id_pol(1,current_pol) + elif ID == "ID2": + current_pol=POL_IDS[POL_ID_2]#get_id_pol(2) + put_id_pol(2,current_pol) + elif ID == "ID1_ID2": + polID1=POL_IDS[POL_ID_1] + polID2=POL_IDS[POL_ID_2] + put_id_pol(1,polID1) + put_id_pol(2,polID2) + current_pol=polID1 + if SWITCHING == "Tune_Detune": + put_id_offset(2, OFFSET_ID_2-40) #detuneID2 + put_id_offset(1, OFFSET_ID_1) #tuneID2 + + elif SWITCHING == "Chopper": + set_chopper(0) + +def imageinfo(info): + pass + + + +#Beamline setting def nextpol(): global current_pol, polID1, polID2 if SWITCHING == "Normal": @@ -97,7 +158,7 @@ def switch_pol(): active_id = 1 set_chopper(0) time.sleep(1.0) - + wait_channel("X11PHS:alldone", 1) def change_energy(v): if v<91 or v>2500: @@ -106,69 +167,24 @@ def change_energy(v): return put_energy(v) -""" -def getLEEM(): - global startvoltage,objective, LEEMtemp - startvoltage=getStartvoltage() - objective=getObjective() - LEEMtemp=getLEEMtemp() -""" -def assert_status_ok(): - if DRY_RUN: return - assert_machine_ok() - assert_beamline_ok() - """ - getbeamline - getLEEM - Rem check status of machine - If checkRing = 3 Then - Close - Exit Sub - End If - Rem check status of the beamline - If checkbeamline = 3 Then - Close - Exit Sub - """ - -#Initialize vartiables - -active_id = 1 -current_pol=None -polID1=None -polID2=None -#rbkEnergy=energy_rbk.read() -if METHOD == "Two_Pol": - global current_pol - if ID == "ID1": - current_pol=POL_IDS[POL_ID_1] #get_id_pol(1) - put_id_pol(1,current_pol) - elif ID == "ID2": - current_pol=POL_IDS[POL_ID_2]#get_id_pol(2) - put_id_pol(2,current_pol) - elif ID == "ID1_ID2": - polID1=POL_IDS[POL_ID_1] - polID2=POL_IDS[POL_ID_2] - put_id_pol(1,polID1) - put_id_pol(2,polID2) - current_pol=polID1 - if SWITCHING == "Tune_Detune": - put_id_offset(2, OFFSET_ID_2-40) #detuneID2 - put_id_offset(1, OFFSET_ID_1) #tuneID2 - - elif SWITCHING == "Chopper": - set_chopper(0) - -def imageinfo(info): - pass +def save_image_file(frame, cycle=-1, frame_index=0): + if SHOW_IMAGES: + plot(frames[i].matrix, name = get_image_file_name(cycle, frame_index, True)) + if AUTO_SAVE and (frame is not None): + filename = get_image_file_name(cycle, frame_index) + save_as_tiff(frame, filename, check=True) + log(filename) + print filename + # log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0")) #Do the measurement loop for cycle in range(1, MEASUREMENTS + 1): + frames = [] if MEASUREMENTS > 1: log("") log("nround = " + str(cycle) + " / " + str(MEASUREMENTS)) @@ -188,8 +204,9 @@ for cycle in range(1, MEASUREMENTS + 1): # TODO else: ret = grab_frames(image, AVERAGE[i], roi=None, wait_next=True) - frames[i] = average_frames(ret) if AVERAGE[i] > 1 else ret[0] - imageinfo("I") + frames.append(average_frames(ret) if AVERAGE[i] > 1 else ret[0]) + imageinfo("I") + save_image_file(frames[i], cycle, i) if METHOD == "Take_Image": break @@ -199,38 +216,23 @@ for cycle in range(1, MEASUREMENTS + 1): switch_pol() if METHOD == "Two_Energies": change_energy(ENERGY_2) - wait_done() time.sleep(1) - if METHOD == "Two_Pol": - if (current_pol == 2) or (current_pol==3): + if (METHOD == "Two_Pol") or (METHOD == "Two_Energies"): + if (METHOD == "Two_Energies") or ((current_pol == 2) or (current_pol==3)): ###??? autocontrast??? - frames[2] = frames[0].copy() + frames.append(frames[0].copy()) frames[2].div(frames[1]) else: - frames[2] = frames[1].copy() - frames[2].div(frames[0]) + frames.append(frames[1].copy()) + frames[2].div(frames[0]) + save_image_file(frames[2],cycle, 2) - if METHOD == "Two_Energies": - frames[2] = frames[0].copy() - frames[2].div(frames[1]) - - if AUTO_SAVE: - for i in range(len(frames)): - filename = get_image_file_name(cycle, i) - save_as_tiff(frames[i], filename, check=True) - log(filename) - print filename - # +" "+imagetext) - # log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0")) - if METHOD == "Take_Image": - break - else: - pass # objective = getObjective() # temp = getLEEMtemp() # log(0 , "Temp : " + Format(temp,"0.00") + " OB : " + Format(objective,"0.00") + " StigmaA : " + " StigmaB : " ) # Auto average and save + if MEASUREMENTS > 1 and AUTO_SAVE == 1: for i in range(len(frames)): measures = [] @@ -240,9 +242,8 @@ if MEASUREMENTS > 1 and AUTO_SAVE == 1: #measures.append(Data(get_ip_array(ip))) measures.append(ip) #av = average_frames(measures) #Result is transposed??? - av=average_ips (measures, roi=None, as_float=True) - filename = get_image_file_name(-1, i) - save_as_tiff(av, filename, check=True) - print filename - if METHOD == "Take_Image": - break + av=average_ips (measures, roi=None, as_float=True) + save_image_file(av, -1, i) + + + \ No newline at end of file diff --git a/script/templates/EigerAbsSpec.py b/script/templates/EigerAbsSpec.py index 7c4779b..f230f76 100644 --- a/script/templates/EigerAbsSpec.py +++ b/script/templates/EigerAbsSpec.py @@ -17,28 +17,73 @@ if get_exec_pars().source == CommandSource.ui: WITH_I0 = True SWITCH_POL = False EXPOSURE = 1.0 - AVERAGE = 1 - NUMBER_SCANS =1 + AVERAGE = 2 + NUMBER_SCANS =1 + RANGES = [[500.0, 1000.0, 100.0]] -RANGES = [[500, 1000, 1]] +DRY_RUN=True + +if len(RANGES) == 0: + raise Exception("No scan range defined") + +eiger.setExposure(EXPOSURE) +set_exec_pars(path="{data}/{year}_{month}/{date}/AbsortionSpectrum_{seq}%03d", format="csv", layout="table") +tag= "AbsortionSpectrum_{seq}%03d" rois = create_roi_devices(ROI) +if AVERAGE>1: + for i in range(len(rois)): + rois[i].monitored = True + rois[i] = create_averager(rois[i], AVERAGE, -1) + rois[i].monitored = True + + +frames=[] + + class SyncEnergy(Writable): def write(self,pos): - put_energy(pos) + if not DRY_RUN: + put_energy(pos) + else: + print "Energy=" + str(pos) sync_energy=SyncEnergy() +set_device_alias(sync_energy, "Energy") #Set display name + +sensors = rois + [machine_cur] +if WITH_I0: + sensors = rois + [keithley_1a] +av=None def grab_image(position, scan): - grab_frame(image, roi=None, wait_next=True) - - -set_exec_pars(path="{data}/{year}_{month}/{date}", layout="table") - - -tscan(rois, 10, 0.1, format="csv", before_read=grab_image) -#rscan(sync_energy, rois +[machine_cur], RANGES, latency = 0.0, tag="AbsortionSpectrum_{seq}%03d", latency=0.0, before_read=grab_image) + global av + frames = grab_frames(image, AVERAGE, roi=None, wait_next=True) + av = average_frames(frames) + if SAVE_IMAGES: + filename = get_exec_pars().path + "/" + ("%05d.tif" % scan.recordIndex) + print filename + save_as_tiff(av, filename) + +class Average(ReadableMatrix): + def read(self): + return av.matrix + def getWidth(self): + return eiger.dataMatrix.getWidth() + def getHeight(self): + return eiger.dataMatrix.getHeight() +averager=Average() +set_device_alias(averager, "Image") #Set display name +sensors.append(averager) #sensors.append(eiger.getDataMatrix()) + +try: + #tscan(rois, 10, 0.1, format="csv", before_read=grab_image, passes = NUMBER_SCANS, tag=tag) + rscan(sync_energy, sensors, RANGES, latency = 0.0 , passes = NUMBER_SCANS, tag=tag, before_read=grab_image, save=SAVE_SPECTRUM) +finally: + if AVERAGE>1: + for i in range(len(rois)): + rois[i].parent.monitored = False # Remove listeners on the image diff --git a/script/test/X11MA_beamline.ipm b/script/test/X11MA_beamline.ipm new file mode 100644 index 0000000..19c7fbd --- /dev/null +++ b/script/test/X11MA_beamline.ipm @@ -0,0 +1,2346 @@ +Attribute VB_Name = "Module2" +'Option Explicit +'#uses "epics.ipm" +'#uses "X11MA_main_functions.ipm" + +Rem /* Return Codes */ +Rem #define EZCA_OK 0 +Rem #define EZCA_INVALIDARG 1 +Rem #define EZCA_FAILEDMALLOC 2 +Rem #define EZCA_CAFAILURE 3 +Rem #define EZCA_UDFREQ 4 +Rem #define EZCA_NOTCONNECTED 5 +Rem #define EZCA_NOTIMELYRESPONSE 6 +Rem #define EZCA_INGROUP 7 +Rem #define EZCA_NOTINGROUP 8 + +Rem for epcis communication +Global EpicsErrorID As Long +Global linrotID1 As Single +Global linrotID2 As Single + +Function getEnergy() As Double + Dim pv As String + pv="X11MA-PGM:rbkenergy" + r=ezcaGet(pv,ezcaDouble,1,getEnergy) +End Function + +Function putEnergy(ByVal v As Double) +Dim pv As String +Dim v1 As Double + + IDMono = 0 ' use Id + Mono + 'IDMono = 1 ' use only ID + + If IDMono = 0 Then + + Rem linrotID1=0 means normal 1-19 is rotating mode + If v>91 And v<2500 Then + If opID = 1 Then + pv="X11PHS:alldone" + v1=0 + r=ezcaPut(pv,ezcaDouble,1,v1) + pv="X11PHS-E:GO.A" + r=ezcaPut(pv,ezcaDouble,1,v) + End If + If opID=2 Then + pv="X11PHS:alldone" + v1=0 + r=ezcaPut(pv,ezcaDouble,1,v1) + pv="X11PHS-E:GO.A" + r=ezcaPut(pv,ezcaDouble,1,v) + End If + + If opID=3 Then + pv="X11PHS:alldone" + v1=0 + r=ezcaPut(pv,ezcaDouble,1,v1) + pv="X11PHS-E:GO.A" + r=ezcaPut(pv,ezcaDouble,1,v) + End If + + Else + write_logfile(1,"Energy out of range (91-2500) :"+Format(v)) + End If + End If + + If IDMono = 1 Then + If activeID = 1 Then putID1Energy(v) + If activeID = 2 Then putID2Energy(v) + If activeID = 3 Or polswitchmode= 2 Then + putID1Energy(v) + putID2Energy(v) + End If + End If + +End Function + +Function putID1Energy(ByVal v As Double) +Dim pv As String + pv="X11MA-ID1:ENERGY" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2Energy(ByVal v As Double) +Dim pv As String + pv="X11MA-ID2:ENERGY" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getID1rbkEnergy() As Double +Dim pv As String + pv="X11MA-ID1:ENERGY-READ" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1rbkEnergy) +End Function + +Function getID2rbkEnergy() As Double +Dim pv As String + pv="X11MA-ID2:ENERGY-READ" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2rbkEnergy) +End Function + +Function getID1Motor() As Double +Rem 0 = off, 1 = on +Dim pv As String + pv="X11MA-ID1-GAP:MOTOR-PWR" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1Motor) +End Function + +Function getID2Motor() As Double +Rem 0 = off, 1 = on +Dim pv As String + pv="X11MA-ID2-GAP:MOTOR-PWR" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2Motor) +End Function + +Function getID1taper() As Double +Rem 0 = error, 1 = ok +Dim pv As String + pv="X11MA-ID1-GAP:TAPER-ERR" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1taper) +End Function + +Function getID2taper() As Double +Rem 0 = error, 1 = ok +Dim pv As String + pv="X11MA-ID2-GAP:TAPER-ERR" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2taper) +End Function + +Function getID1control() As Double +Rem 0 = SLS control, 1 = experiment +Dim pv As String + pv="X11MA-ID1-GAP:SCTRL" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1control) +End Function + +Function getID2control() As Double +Rem 0 = SLS control, 1 = experiment +Dim pv As String + pv="X11MA-ID2-GAP:SCTRL" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2control) +End Function + +Function getID1status() As Double +Rem 0 = ok +Rem 1 = Warning +Rem 2 = Error +Rem 3 = Not available +Dim pv As String + pv="X11MA-ID1-USER:STATUS" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1status) +End Function + +Function getID2status() As Double +Rem 0 = ok +Rem 1 = Warning +Rem 2 = Error +Rem 3 = Not available +Dim pv As String + pv="X11MA-ID2-USER:STATUS" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2status) +End Function + +Function getID1error() As Double +Rem B0 (1) = PLC (Taper, Motor controller, Limitswitch....) +Rem B1 (2) = Encoders (cabel, not referenced) +Rem B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet) +Rem B3 (8) = Operator COntrol +Rem B4 (16)= Moving Timeout (moving longer then 120 sec) +Rem B5 (32)= Interlock (Orbit, Temperature...) +Dim pv As String + pv="X11MA-ID1-USER:ERROR-SOURCE" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID1error) +End Function + +Function getID2error() As Double +Rem B0 (1) = PLC (Taper, Motor controller, Limitswitch....) +Rem B1 (2) = Encoders (cabel, not referenced) +Rem B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet) +Rem B3 (8) = Operator COntrol +Rem B4 (16)= Moving Timeout (moving longer then 120 sec) +Rem B5 (32)= Interlock (Orbit, Temperature...) +Dim pv As String + pv="X11MA-ID2-USER:ERROR-SOURCE" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getID2error) +End Function + +Function getPolID1() As Double +Dim pv As String +Dim d As Double + pv="X11MA-ID1:MODE" + r=ezcaGet(pv,ezcaDouble,1,getPolID1) + If getPolID1=0 Then + Rem linear mode + pv="X11MA-ID1:ALPHA" + r=ezcaGet(pv,ezcaDouble,1,ID1alpha) + Select Case ID1alpha + Case 0 + getPolID1=3 + Case 90 + getPolID1=4 + Case Else + getPolID1=5 + End Select + End If +End Function + +Function getPolID2() As Double +Dim pv As String +Dim d As Double + pv="X11MA-ID2:MODE" + r=ezcaGet(pv,ezcaDouble,1,getPolID2) + If getPolID2=0 Then + Rem linear mode + pv="X11MA-ID2:ALPHA" + r=ezcaGet(pv,ezcaDouble,1,ID2alpha) + Select Case ID2alpha + Case 0 + getPolID2=3 + Case 90 + getPolID2=4 + Case Else + getPolID2=5 + End Select + End If +End Function + +Function getID1alpha() As Double +Dim pv As String + pv="X11MA-ID1:ALPHA" + r=ezcaGet(pv,ezcaDouble,1,getID1alpha) +End Function + +Function getID2alpha() As Double +Dim pv As String + pv="X11MA-ID2:ALPHA" + r=ezcaGet(pv,ezcaDouble,1,getID2alpha) +End Function + +Function putID1alpha(ByVal v As Double) +Dim pv As String + pv="X11MA-ID1:ALPHA" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2alpha(ByVal v As Double) +Dim pv As String + pv="X11MA-ID2:ALPHA" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putPolID1(ByVal n As Single) +Rem pol = 1 : Mode =1, alpha = 0 circ + +Rem pol = 2 : Mode =2, alpha = 0 circ - +Rem pol = 3 : Mode =0, alpha = 0 lin hor +Rem pol = 4 : Mode =0, alpha = 90 lin vert +Rem pol = 5 : Mode =0, alpha = ? lin rot + +Dim pv1 As String +Dim pv2 As String +Dim v1 As Double +Dim v2 As Double + + pv1="X11MA-ID1:MODE" + pv2="X11MA-ID1:ALPHA" + + Select Case n + Case 1 + v1=1 + r=ezcaPut(pv1,ezcaDouble,1,v1) + Case 2 + v1=2 + r=ezcaPut(pv1,ezcaDouble,1,v1) + Case 3 + v1=0 + v2=0 + r=ezcaPut(pv1,ezcaDouble,1,v1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + Case 4 + v1=0 + v2=90 + r=ezcaPut(pv1,ezcaDouble,1,v1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + Case 5 + v1=0 + v2=ID1alpha + r=ezcaPut(pv1,ezcaDouble,1,v1) + sleep(1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + End Select + +End Function + +Function putPolID2(ByVal n As Single) +Rem pol = 1 : Mode =1, alpha = 0 circ + +Rem pol = 2 : Mode =2, alpha = 0 circ - +Rem pol = 3 : Mode =0, alpha = 0 lin hor +Rem pol = 4 : Mode =0, alpha = 90 lin vert +Rem pol = 5 : Mode =0, alpha = ? lin rot + +Dim pv1 As String +Dim pv2 As String +Dim v1 As Double +Dim v2 As Double + + + pv1="X11MA-ID2:MODE" + pv2="X11MA-ID2:ALPHA" + + Select Case n + Case 1 + v1=1 + r=ezcaPut(pv1,ezcaDouble,1,v1) + Case 2 + v1=2 + r=ezcaPut(pv1,ezcaDouble,1,v1) + Case 3 + v1=0 + v2=0 + r=ezcaPut(pv1,ezcaDouble,1,v1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + Case 4 + v1=0 + v2=90 + r=ezcaPut(pv1,ezcaDouble,1,v1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + Case 5 + v1=0 + v2=ID2alpha + r=ezcaPut(pv1,ezcaDouble,1,v1) + sleep(1) + r=ezcaPut(pv2,ezcaDouble,1,v2) + End Select + +End Function + +'Function putlinrotmodeID1(ByVal v As Single) +' linrotID1=v +' 'addMessage 0,"lin = "+Format(v) +'End Function + +'Function putlinrotID1(ByVal v As Double) +'Dim E As Double +'Dim g As Double +'Dim c As Double +'Dim alpha As Double +'Dim alphadeg As Double +'Dim Kz0 As Double +'Dim Kx0 As Double +'Dim phi As Double +'Dim calcshift As Double +'Dim calcgap As Double +'Dim D0(19) As Double +'Dim D1(19) As Double +'Dim D2(19) As Double +'Dim D3(19) As Double +'Dim linrot_dummy(19) As Double +'Dim E_index As Double +'Dim E_b As Double +'Dim setgap As Double +'Dim setshift As Double +'Dim rot_index As Integer +'Const pi = 4*Atn(1) + + +' linrot_dummy(1)=0 +' linrot_dummy(2)=5 +' linrot_dummy(3)=10 +' linrot_dummy(4)=15 +' linrot_dummy(5)=20 +' linrot_dummy(6)=25 +' linrot_dummy(7)=30 +' linrot_dummy(8)=35 +' linrot_dummy(9)=40 +' linrot_dummy(10)=45 +' linrot_dummy(11)=50 +' linrot_dummy(12)=55 +' linrot_dummy(13)=60 +' linrot_dummy(14)=65 +' linrot_dummy(15)=70 +' linrot_dummy(16)=75 +' linrot_dummy(17)=80 +' linrot_dummy(18)=85 +' linrot_dummy(19)=90 + + ' another intermim solution until it exist in epics ..... April 2005 + +' E=v 'Energy so far only calculated between 250 and 900 + +' If E<270 Or E> 900 Then +' Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 +' Text 50,7,170,21,"value out of range",.Text1 +' OKButton 70,35,110,21 +' End Dialog +' Dim scanerror4 As UserDialog +' Dialog scanerror4 +' Exit Function +' End If + + 'transform energy to index variable +' E=E-269 + + 'separate energy +' E_index=Int(E) +' E_b=E-E_index + + 'get index for rotation angle for me lin hor = lin rot 0, for Thomas lin hor = lin rot 90 +' rot_index=Abs(linrotID1-20) + + 'read gap value + +' alphadeg=linrot_dummy(rot_index) +' +' setgap=ID1_linrot_gap(E_index,rot_index) +' setshift=ID1_linrot_shift(E_index,rot_index) + +' If E_b > 0 Then +' setgap=setgap+(ID1_linrot_gap(E_index+1,rot_index)-ID1_linrot_gap(E_index,rot_index))*E_b +' setshift=setshift+(ID1_linrot_shift(E_index+1,rot_index)-ID1_linrot_shift(E_index,rot_index))*E_b +' End If + + 'write_logfile(0,"Energy= "+Format(v)) + 'write_logfile(0,"alpha = "+Format(alphadeg)) + 'write_logfile(0,"Gap = "+Format(setgap)) + 'write_logfile(0,"shift = "+Format(setshift)) + +' putID1gap(setgap) +' putID1shift(setshift) + + +' Exit Function + + Rem JUne 2004, carbon edge + 'Const pi = 4*Atn(1) + 'Const A0=1037.16 + 'Const A1=55.0409 + 'Const A2=-.107249 + 'Const B0=893.493 + 'Const B1=48.114 + 'Const B2=-0.155832 + + Rem 0 degree + 'D0(1) = 1037.16 + 'D1(1) = 55.0409 + 'D2(1) = -.107249 + + Rem 15 degree + 'D0(4) = 936.083 + 'D1(4) = 35 + 'D2(4) = -.122725 + + Rem 30 degree + 'D0(7) = 931.841 + 'D1(7) = 28.4438 + 'D2(7) = -.131614 + + Rem 45 degree + 'D0(10) = 931.982 + 'D1(10) = 26.5728 + 'D2(10) = -.138108 + + Rem 60 degree + 'D0(13) = 928.233 + 'D1(13) = 28.1553 + 'D2(13) = -.143727 + + Rem 75 degree + 'D0(16) = 917.418 + 'D1(16) = 34.0431 + 'D2(16) = -.149344 + + Rem 90 degree + 'D0(19) = 893.493 + 'D1(19) = 48.114 + 'D2(19) = -.155832 + + + Rem July 2004, 15 degree steps + 'Const A0=967.671 + 'Const A1=55.3418 + 'Const A2=-.111755 + 'Const B0=963.21 + 'Const B1=41.6492 + 'Const B2=-0.144587 + + Rem 0 degree + 'D0(1) = 967.671 + 'D1(1) = 55.3418 + 'D2(1) = -.111755 + + Rem 15 degree + 'D0(2) = 964.34 + 'D1(2) = 36.0006 + 'D2(2) = -.122648 + + Rem 30 degree + 'D0(3) = 969.04 + 'D1(3) = 27.9542 + 'D2(3) = -.128563 + + Rem 45 degree + 'D0(4) = 971.366 + 'D1(4) = 25.0622 + 'D2(4) = -.1328 + + Rem 60 degree + 'D0(5) = 971.27 + 'D1(5) = 25.7036 + 'D2(5) = -.136564 + + Rem 75 degree + 'D0(6) = 969.012 + 'D1(6) = 30.2084 + 'D2(6) = -.140302 + + Rem 90 degree + 'D0(7) = 963.21 + 'D1(7) = 41.6492 + 'D2(7) = -.144587 + + + 'linrot_dummy(1)=0 + 'linrot_dummy(2)=15 + 'linrot_dummy(3)=30 + 'linrot_dummy(4)=45 + 'linrot_dummy(5)=60 + 'linrot_dummy(6)=75 + 'linrot_dummy(7)=90 + + Rem July 2004, fit version 2 + + 'linrot_dummy(1)=0 + 'linrot_dummy(2)=5 + 'linrot_dummy(3)=10 + 'linrot_dummy(4)=15 + 'linrot_dummy(5)=20 + 'linrot_dummy(6)=25 + 'linrot_dummy(7)=30 + 'linrot_dummy(8)=35 + 'linrot_dummy(9)=40 + 'linrot_dummy(10)=45 + 'linrot_dummy(11)=50 + 'linrot_dummy(12)=55 + 'linrot_dummy(13)=60 + 'linrot_dummy(14)=65 + 'linrot_dummy(15)=70 + 'linrot_dummy(16)=75 + 'linrot_dummy(17)=80 + 'linrot_dummy(18)=85 + 'linrot_dummy(19)=90 + +' Rem 0 deg +' D0(1)=964.52 +' D1(1)=3780.63 +' D2(1)=57.1361 +' D3(1)=-0.112269 + +' Rem 5 deg +' D0(2)=963.018 +' D1(2)=768.341 +' D2(2)=46.2253 +' D3(2)=-0.115758 + +' Rem 10 deg +' D0(3)=962.932 +' D1(3)=-458.937 +' D2(3)=39.6977 +' D3(3)=-0.119137 +' +' Rem 15 deg +' D0(4)=963.637 +' D1(4)=-972.257 +' D2(4)=35.2368 +' D3(4)=-0.122121 +' +' Rem 20 deg +' D0(5)=965.124 +' D1(5)=-1567.26 +' D2(5)=31.9063 +' D3(5)=-0.124629 + +' Rem 25 deg +' D0(6)=967.464 +' D1(6)=-2721.6 +' D2(6)=29.2988 +' D3(6)=-0.126681 + +' Rem 30 deg +' D0(7)=970.742 +' D1(7)=-4697.93 +' D2(7)=27.2086 +' D3(7)=-0.128325 +' +' Rem 35 deg +' D0(8)=974.088 +' D1(8)=-6943.2 +' D2(8)=25.6448 +' D3(8)=-0.12976 +' +' Rem 40 deg +' D0(9)=977.397 +' D1(9)=-9375.37 +' D2(9)=24.5203 +' D3(9)=-0.131037 +' +' Rem 45 deg +' D0(10)=980.557 +' D1(10)=-11887.7 +' D2(10)=23.7802 +' D3(10)=-0.132199 +' +' Rem 50 deg +' D0(11)=983.448 +' D1(11)=-14362.2 +' D2(11)=23.3933 +' D3(11)=-0.133279 +' +' Rem 55 deg +' D0(12)=985.406 +' D1(12)=-16288.2 +' D2(12)=23.4158 +' D3(12)=-0.134402 +' +' Rem 60 deg +' D0(13)=987.112 +' D1(13)=-18151 +' D2(13)=23.7566 +' D3(13)=-0.135458 +' +' Rem 65 deg +' D0(14)=977.397 +' D1(14)=-9375.37 +' D2(14)=24.5203 +' D3(14)=-0.131037 +' +' Rem 70 deg +' D0(15)=988.712 +' D1(15)=-20912.4 +' D2(15)=25.603 +' D3(15)=-0.137563 +' +' Rem 75 deg +' D0(16)=988.442 +' D1(16)=-21724.4 +' D2(16)=27.2317 +' D3(16)=-0.138646 +' +' Rem 80 deg +' D0(17)=987.331 +' D1(17)=-22117.8 +' D2(17)=29.4733 +' D3(17)=-0.139773 +' +' Rem 85 deg +' D0(18)=985.231 +' D1(18)=-22058.9 +' D2(18)=32.51 +' D3(18)=-0.140973 +' +' Rem 90 deg +' D0(19)= 982.066 +' D1(19)= -21599.7 +' D2(19)= 36.5915 +' D3(19)= -0.142255 +' +' 'addMessage 0,"lin = "+Format(linrotID1) + 'addMessage 0,"Energy= "+Format(v) + + 'calc gap +' E=v 'Energy so far only calculated between 250 and 900 +' +' If E<250 Or E> 900 Then +' Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 +' Text 50,7,170,21,"value out of range",.Text1 +' OKButton 70,35,110,21 +' End Dialog +' Dim scanerror3 As UserDialog +' Dialog scanerror3 +' Exit Function +' End If + + Rem fit version 1 June 2004 + 'alphadeg=linrot_dummy(linrotID1) + 'calcgap = 1/D2(linrotID1)*Log((D0(linrotID1)/E-1)/D1(linrotID1)) + 'calc shift + 'If linrotID1 = 7 Then + ' calcshift = 28.150 + 'Else + ' g = 2.42/0.000511 + ' c = 1.239842E-6 * 2 * g*g/(56.3/1000) + ' alpha = (90-alphadeg)/360 * 2 * pi + ' Kz0 = Sqr(2*(c/A0*(1+A1*Exp(A2*calcgap))-1)) + ' Kx0 = Sqr(2*(c/B0*(1+B1*Exp(B2*calcgap))-1)) + ' phi = 2 *Atn(1/Sqr(Tan(alpha) * Kx0/Kz0)) + ' calcshift = (phi/(2*pi)) * 56.3 + 'End If + + Rem Calculation of gap and shift for UE56 ID1 in linear mode + Rem 2nd version, Date: 22.07.04 + Rem fit model In first version: y= 1/A2*ln((A0/x-1)/A1), y=gap, x=photon energy + Rem New fit model y = 1/A3*ln((A0/x+A1/x^2-1)/A2) + Rem Gap And shift have To be known As functions from Energy (E) And + Rem polarization angle In degree (alphadeg) + +' calcgap = 1/D3(linrotID1)*Log((D0(linrotID1)/E + D1(linrotID1)/(E*E)-1)/D2(linrotID1)) +' +' alphadeg=linrot_dummy(linrotID1) +' +' If linrotID1 = 19 Then +' calcshift = 28.150 +' Else +' g = 2.42/0.000511 +' c = 1.239842E-6 * 2 * g*g/(56.3/1000) +' alpha = (90-alphadeg)/360 * 2 * pi +' enz=(D0(1)+Sqr(D0(1)^2+4*D1(1)+4*D1(1)*D2(1)*Exp(D3(1)*calcgap)))/(2*(1+D2(1)*Exp(D3(1)*calcgap))) +' Kz0 = Sqr( 2*(c/enz-1)) +' enx=(D0(19)+Sqr(D0(19)^2+4*D1(19)+4*D1(19)*D2(19)*Exp(D3(19)*calcgap)))/(2*(1+D2(19)*Exp(D3(19)*calcgap))) +' Kx0 = Sqr( 2*(c/enx-1)) +' phi = 2 *Atn(1/Sqr(Tan(alpha) * Kx0/Kz0)) +' calcshift = (phi/(2*pi)) * 56.3 +' End If +' +' +' 'addMessage 0,"Energy= "+Format(E) +' 'addMessage 0,"alpha = "+Format(alphadeg) +' 'addMessage 0,"Gap = "+Format(calcgap) +' 'addMessage 0,"shift = "+Format(calcshift) +' putID1gap(calcgap) +' putID1shift(calcshift) +'End Function + + +'Function putlinrotmodeID2(ByVal v As Single) +' linrotID2=v +' 'addMessage 0,"lin = "+Format(v) +'End Function + +Function putlinrotID2_old(ByVal v As Double) + +Exit Function + +Dim E As Double +Dim g As Double +Dim c As Double +Dim alpha As Double +Dim alphadeg As Double +Dim Kz0 As Double +Dim Kx0 As Double +Dim phi As Double +Dim calcshift As Double +Dim calcgap As Double +Dim D0(19) As Double +Dim D1(19) As Double +Dim D2(19) As Double +Dim D3(19) As Double +Dim linrot_dummy(19) As Double + Const pi = 4*Atn(1) + + + linrot_dummy(1)=0 + linrot_dummy(2)=5 + linrot_dummy(3)=10 + linrot_dummy(4)=15 + linrot_dummy(5)=20 + linrot_dummy(6)=25 + linrot_dummy(7)=30 + linrot_dummy(8)=35 + linrot_dummy(9)=40 + linrot_dummy(10)=45 + linrot_dummy(11)=50 + linrot_dummy(12)=55 + linrot_dummy(13)=60 + linrot_dummy(14)=65 + linrot_dummy(15)=70 + linrot_dummy(16)=75 + linrot_dummy(17)=80 + linrot_dummy(18)=85 + linrot_dummy(19)=90 + + ' another intermim solution until it exist in epics ..... April 2005 + + E=v 'Energy so far only calculated between 250 and 900 + + If E<270 Or E> 900 Then + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"value out of range",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror4 As UserDialog + Dialog scanerror4 + Exit Function + End If + + 'transform energy to index variable + E=E-269 + + 'separate energy + E_index=Int(E) + E_b=E-E_index + + 'get index for rotation angle for me lin hor = lin rot 0, for Thomas lin hor = lin rot 90 + rot_index=Abs(linrotID2-20) + + 'read gap value + + alphadeg=linrot_dummy(rot_index) + + setgap=ID2_linrot_gap(E_index,rot_index) + setshift=ID2_linrot_shift(E_index,rot_index) + + If E_b > 0 Then + setgap=setgap+(ID2_linrot_gap(E_index+1,rot_index)-ID2_linrot_gap(E_index,rot_index))*E_b + setshift=setshift+(ID2_linrot_shift(E_index+1,rot_index)-ID2_linrot_shift(E_index,rot_index))*E_b + End If + + 'write_logfile(0,"Energy= "+Format(v)) + 'write_logfile(0,"alpha = "+Format(alphadeg)) + 'write_logfile(0,"Gap = "+Format(setgap)) + 'write_logfile(0,"shift = "+Format(setshift)) + + putID2gap(setgap) + putID2shift(setshift) + + + Exit Function + + + + Rem JUne 2004, carbon edge + 'Const pi = 4*Atn(1) + 'Const A0=1037.16 + 'Const A1=55.0409 + 'Const A2=-.107249 + 'Const B0=893.493 + 'Const B1=48.114 + 'Const B2=-0.155832 + + Rem 0 degree + 'D0(1) = 1037.16 + 'D1(1) = 55.0409 + 'D2(1) = -.107249 + + Rem 15 degree + 'D0(4) = 936.083 + 'D1(4) = 35 + 'D2(4) = -.122725 + + Rem 30 degree + 'D0(7) = 931.841 + 'D1(7) = 28.4438 + 'D2(7) = -.131614 + + Rem 45 degree + 'D0(10) = 931.982 + 'D1(10) = 26.5728 + 'D2(10) = -.138108 + + Rem 60 degree + 'D0(13) = 928.233 + 'D1(13) = 28.1553 + 'D2(13) = -.143727 + + Rem 75 degree + 'D0(16) = 917.418 + 'D1(16) = 34.0431 + 'D2(16) = -.149344 + + Rem 90 degree + 'D0(19) = 893.493 + 'D1(19) = 48.114 + 'D2(19) = -.155832 + + + Rem July 2004, 15 degree steps + 'Const A0=967.671 + 'Const A1=55.3418 + 'Const A2=-.111755 + 'Const B0=963.21 + 'Const B1=41.6492 + 'Const B2=-0.144587 + + Rem 0 degree + 'D0(1) = 967.671 + 'D1(1) = 55.3418 + 'D2(1) = -.111755 + + Rem 15 degree + 'D0(2) = 964.34 + 'D1(2) = 36.0006 + 'D2(2) = -.122648 + + Rem 30 degree + 'D0(3) = 969.04 + 'D1(3) = 27.9542 + 'D2(3) = -.128563 + + Rem 45 degree + 'D0(4) = 971.366 + 'D1(4) = 25.0622 + 'D2(4) = -.1328 + + Rem 60 degree + 'D0(5) = 971.27 + 'D1(5) = 25.7036 + 'D2(5) = -.136564 + + Rem 75 degree + 'D0(6) = 969.012 + 'D1(6) = 30.2084 + 'D2(6) = -.140302 + + Rem 90 degree + 'D0(7) = 963.21 + 'D1(7) = 41.6492 + 'D2(7) = -.144587 + + + 'linrot_dummy(1)=0 + 'linrot_dummy(2)=15 + 'linrot_dummy(3)=30 + 'linrot_dummy(4)=45 + 'linrot_dummy(5)=60 + 'linrot_dummy(6)=75 + 'linrot_dummy(7)=90 + + Rem July 2004, fit version 2 + + linrot_dummy(1)=0 + linrot_dummy(2)=5 + linrot_dummy(3)=10 + linrot_dummy(4)=15 + linrot_dummy(5)=20 + linrot_dummy(6)=25 + linrot_dummy(7)=30 + linrot_dummy(8)=35 + linrot_dummy(9)=40 + linrot_dummy(10)=45 + linrot_dummy(11)=50 + linrot_dummy(12)=55 + linrot_dummy(13)=60 + linrot_dummy(14)=65 + linrot_dummy(15)=70 + linrot_dummy(16)=75 + linrot_dummy(17)=80 + linrot_dummy(18)=85 + linrot_dummy(19)=90 + + Rem 0 deg + D0(1)=964.52 + D1(1)=3780.63 + D2(1)=57.1361 + D3(1)=-0.112269 + + Rem 5 deg + D0(2)=963.018 + D1(2)=768.341 + D2(2)=46.2253 + D3(2)=-0.115758 + + Rem 10 deg + D0(3)=962.932 + D1(3)=-458.937 + D2(3)=39.6977 + D3(3)=-0.119137 + + Rem 15 deg + D0(4)=963.637 + D1(4)=-972.257 + D2(4)=35.2368 + D3(4)=-0.122121 + + Rem 20 deg + D0(5)=965.124 + D1(5)=-1567.26 + D2(5)=31.9063 + D3(5)=-0.124629 + + Rem 25 deg + D0(6)=967.464 + D1(6)=-2721.6 + D2(6)=29.2988 + D3(6)=-0.126681 + + Rem 30 deg + D0(7)=970.742 + D1(7)=-4697.93 + D2(7)=27.2086 + D3(7)=-0.128325 + + Rem 35 deg + D0(8)=974.088 + D1(8)=-6943.2 + D2(8)=25.6448 + D3(8)=-0.12976 + + Rem 40 deg + D0(9)=977.397 + D1(9)=-9375.37 + D2(9)=24.5203 + D3(9)=-0.131037 + + Rem 45 deg + D0(10)=980.557 + D1(10)=-11887.7 + D2(10)=23.7802 + D3(10)=-0.132199 + + Rem 50 deg + D0(11)=983.448 + D1(11)=-14362.2 + D2(11)=23.3933 + D3(11)=-0.133279 + + Rem 55 deg + D0(12)=985.406 + D1(12)=-16288.2 + D2(12)=23.4158 + D3(12)=-0.134402 + + Rem 60 deg + D0(13)=987.112 + D1(13)=-18151 + D2(13)=23.7566 + D3(13)=-0.135458 + + Rem 65 deg + D0(14)=977.397 + D1(14)=-9375.37 + D2(14)=24.5203 + D3(14)=-0.131037 + + Rem 70 deg + D0(15)=988.712 + D1(15)=-20912.4 + D2(15)=25.603 + D3(15)=-0.137563 + + Rem 75 deg + D0(16)=988.442 + D1(16)=-21724.4 + D2(16)=27.2317 + D3(16)=-0.138646 + + Rem 80 deg + D0(17)=987.331 + D1(17)=-22117.8 + D2(17)=29.4733 + D3(17)=-0.139773 + + Rem 85 deg + D0(18)=985.231 + D1(18)=-22058.9 + D2(18)=32.51 + D3(18)=-0.140973 + + Rem 90 deg + D0(19)= 982.066 + D1(19)= -21599.7 + D2(19)= 36.5915 + D3(19)= -0.142255 + + 'addMessage 0,"lin = "+Format(linrotID1) + 'addMessage 0,"Energy= "+Format(v) + + 'calc gap + E=v 'Energy so far only calculated between 250 and 900 + + If E<250 Or E> 900 Then + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"value out of range",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror3 As UserDialog + Dialog scanerror3 + Exit Function + End If + + Rem fit version 1 June 2004 + 'alphadeg=linrot_dummy(linrotID2) + 'calcgap = 1/D2(linrotID2)*Log((D0(linrotID2)/E-1)/D1(linrotID2)) + 'calc shift + 'If linrotID2 = 7 Then + ' calcshift = 28.150 + 'Else + ' g = 2.42/0.000511 + ' c = 1.239842E-6 * 2 * g*g/(56.3/1000) + ' alpha = (90-alphadeg)/360 * 2 * pi + ' Kz0 = Sqr(2*(c/A0*(1+A1*Exp(A2*calcgap))-1)) + ' Kx0 = Sqr(2*(c/B0*(1+B1*Exp(B2*calcgap))-1)) + ' phi = 2 *Atn(1/Sqr(Tan(alpha) * Kx0/Kz0)) + ' calcshift = (phi/(2*pi)) * 56.3 + 'End If + + Rem Calculation of gap and shift for UE56 ID1 in linear mode + Rem 2nd version, Date: 22.07.04 + Rem fit model In first version: y= 1/A2*ln((A0/x-1)/A1), y=gap, x=photon energy + Rem New fit model y = 1/A3*ln((A0/x+A1/x^2-1)/A2) + Rem Gap And shift have To be known As functions from Energy (E) And + Rem polarization angle In degree (alphadeg) + + calcgap = 1/D3(linrotID2)*Log((D0(linrotID2)/E + D1(linrotID2)/(E*E)-1)/D2(linrotID2)) + + alphadeg=linrot_dummy(linrotID2) + + If linrotID2 = 19 Then + calcshift = 28.150 + Else + g = 2.42/0.000511 + c = 1.239842E-6 * 2 * g*g/(56.3/1000) + alpha = (90-alphadeg)/360 * 2 * pi + enz=(D0(1)+Sqr(D0(1)^2+4*D1(1)+4*D1(1)*D2(1)*Exp(D3(1)*calcgap)))/(2*(1+D2(1)*Exp(D3(1)*calcgap))) + Kz0 = Sqr( 2*(c/enz-1)) + enx=(D0(19)+Sqr(D0(19)^2+4*D1(19)+4*D1(19)*D2(19)*Exp(D3(19)*calcgap)))/(2*(1+D2(19)*Exp(D3(19)*calcgap))) + Kx0 = Sqr( 2*(c/enx-1)) + phi = 2 *Atn(1/Sqr(Tan(alpha) * Kx0/Kz0)) + calcshift = (phi/(2*pi)) * 56.3 + End If + + + 'addMessage 0,"Energy= "+Format(E) + 'addMessage 0,"alpha = "+Format(alphadeg) + 'addMessage 0,"Gap = "+Format(calcgap) + 'addMessage 0,"shift = "+Format(calcshift) + putID2gap(calcgap) + putID2shift(calcshift) +End Function + +'Function getlinearMode() As Double +'Dim pv As String + 'pv="X11MA-ID1:POLAR" +' pv="X11MA-ID1:ALPHA" +' r=ezcaGet(pv,ezcaDouble,1,getlinearMode) +'End Function + +'Function putlinearMode(ByVal v As Double) +'Dim pv As String + 'pv="X11MA-ID1:POLAR" +' pv="X11MA-ID1:ALPHA" +' r=ezcaPut(pv,ezcaDouble,1,v) +'End Function + +Function donemove() As Double +Rem 1: done move +Rem 0: moving +Dim pv As String + sleep_f(1) 'in order to reduce trafic on the IOC + pv="X11PHS:alldone" + r=ezcaGet(pv,ezcaDouble,1,donemove) + 'donemove=1 +End Function + +Function injection() As Double +Rem 0 no injection +Rem 1 injection +Dim pv As String + Rem checking for top-up injection + + pv="ARIMA-KIN:TRG-ENABLE" + r=ezcaGet(pv,ezcaDouble,1,injection) + + Rem checking for big injection (no real top-up) + 'If getRingstatus=2 Or getRingstatus=3 Then + ' injection=1 + 'Else + ' injection=0 + 'End If +End Function + +Function getRingstatus() As Double +Rem ACOAU-ACCU:OP-MODE kann Werte zwischen 0 und 5 annehmen: +Rem # rule from 24.8.04 +Rem If (PCT beam current <0.09) -> State 0: "Machine Down" +Rem Else If (GUN Trigger OFF) -> State 1: "Inj. Stopped" +Rem Else If (INJ_MODE == Normal) -> State 2: "Accumulating." +Rem Else If !(reached Top-Up Current) -> State 3: "Accumulating" +Rem Else If (OP-READY == Wait) -> State 4: "Top-up ready" +Rem Else If (OFB off) -> State 5: "Light-Available" (former State 4) +Rem Else -> State 6: "Light Available" (former State 5) + +Dim pv As String + pv="ACOAU-ACCU:OP-MODE" + EpicsErrorID=ezcaGet(pv,ezcaDouble,1,getRingstatus) +End Function + +Function keithley_new_read (v As Double,ByRef Keithley1a As Double,ByRef Keithley2a As Double, ByRef Keithley3a As Double) As Integer +Rem for the new hardware trigger and new Keithley phyton program +Rem v = 0 Keithley1 +Rem v = 1 Keithley2 +Rem v = 2 Keithley 1+2 +Rem v = 3 Keithley 1+2+3 + +Dim pv1 As String +Dim pv2 As String +Dim pv3 As String + +Keithley1a=0.0 +Keithley2a=0.0 +Keithley3a=0.0 + + +Rem official channel names are X11MA-KEI10:READOUT but there is a converter +pv1="X11Keithley1-read" +pv2="X11Keithley2-read" +pv3="X11Keithley3-read" + + Select Case v + Case 0 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + Case 1 + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Case 2 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Keithley3a=Keithley2a/Keithley1a + 'r=ezcaGet(pv3,ezcaDouble,1,Keithleynorm) + Case 3 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithley3a) + End Select + +End Function + +Function keithley_analog_trigger +Rem trigger ADC +Dim v As Double +pv="X11MA-ES1-10ADC:TRG.PROC" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley_analog_done() As Double +Rem returns 0 if done, 1 if still reading +'pv="X11MA-ES1-10ADC:BUSY" +pv="X11MA-ES1:CADC1BUSY" + keithley_analog_done=1 + r=ezcaGet(pv,ezcaDouble,1,keithley_analog_done) +End Function + +Function keithley1_trigger_doinit() As Double +Dim v As Double +Rem set Keithley1 waiting for trigger +pv="X11MA-KEI10:DOINIT" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley2_trigger_doinit() As Double +Rem set Keithley2 waiting for trigger +Dim v As Double +pv="X11MA-KEI11:DOINIT" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley1_new_trigger + Rem hardware trigger via box +Dim v As Double +pv="X11MA-KEI10:DOTRIGGER" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley2_new_trigger + Rem hardware trigger via box +Dim v As Double +pv="X11MA-KEI11:DOTRIGGER" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley1_new_fetch + Rem hardware trigger via box +Dim v As Double +pv="X11MA-KEI10:DOFETCH" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function +Function keithley2_new_fetch + Rem hardware trigger via box +Dim v As Double +pv="X11MA-KEI11:DOFETCH" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley1_new_done() As Double +Rem returns 0 if done, 1 if busy +pv="X11MA-KEI10:BUSY" + keithley1_new_done=0 + r=ezcaGet(pv,ezcaDouble,1,keithley1_new_done) +End Function + +Function keithley2_new_done() As Double +Rem returns 0 if done, 1 if busy +pv="X11MA-KEI11:BUSY" + keithley2_new_done=0 + r=ezcaGet(pv,ezcaDouble,1,keithley2_new_done) +End Function + +Function get_keithley1_mode() As Double +Rem v=0 def setting +Rem v=1 pull curr fast +Rem v=2 pull curr medi +Rem v=3 pull curr slow +Rem v=4 trig setting +Rem v=5 trigger extern +Rem v=6 trigger TLIN +Rem v=7 trigger BUS +Rem v=8 pol volt medi +Rem v=9 not running + +pv="X11MA-KEI10:USER_MODE" + r=ezcaGet(pv,ezcaDouble,1,get_keithley1_mode) + If get_keithley1_mode = 0 Then get_keithley1_mode=9 +End Function + +Function get_keithley2_mode() As Double +Rem v=0 def setting +Rem v=1 pull curr fast +Rem v=2 pull curr medi +Rem v=3 pull curr slow +Rem v=4 trig setting +Rem v=5 trigger extern +Rem v=6 trigger TLIN +Rem v=7 trigger BUS +Rem v=8 pol volt medi +Rem v=9 not running + +pv="X11MA-KEI11:USER_MODE" + r=ezcaGet(pv,ezcaDouble,1,get_keithley2_mode) + If get_keithley2_mode = 0 Then get_keithley2_mode=9 +End Function + +Function get_keithley3_mode() As Double +Rem v=0 def setting +Rem v=1 pull curr fast +Rem v=2 pull curr medi +Rem v=3 pull curr slow +Rem v=4 trig setting +Rem v=5 trigger extern +Rem v=6 trigger TLIN +Rem v=7 trigger BUS +Rem v=8 pol volt medi +Rem v=9 not running + +pv="X11MA-KEI12:USER_MODE" + r=ezcaGet(pv,ezcaDouble,1,get_keithley3_mode) + If get_keithley3_mode = 0 Then get_keithley3_mode=9 +End Function + +Function keithley_trigger (v As Double) As Integer +Rem trigger keithley +Rem v=0 keithley1 +Rem v=1 keithley2 +Rem v=2 keithley1+2 + +Dim pv As String +Dim pv1 As String + trigger_keithley=0 + pv="X11Keithleys:GO.PROC" + pv1="X11Keithleys:OPT" + r=ezcaPut(pv1,ezcaDouble,1,v) + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function keithley_read(v As Double,ByRef Keithley1a As Double,ByRef Keithley2a As Double,ByRef Keithleynorma As Double) As Integer +Rem v = 0 : Keithley1 +Rem v = 1 : Keithley2 +Rem v = 2 : Keithley 1 + 2 +Rem v = 3 : Keithley1 + 2 + 3 +Rem v = 4 : Keithley1 + 2, norm, 4 analog + +Dim pv1 As String +Dim pv2 As String +Dim pv3 As String +Dim pv4 As String +Dim pv5 As String +Dim pv6 As String +Dim pv7 As String +Dim pv8 As String + + pv1="X11Keithley1-read" + pv2="X11Keithley2-read" + pv3="X11Keithleys:NORM" + pv4="X11Keithley3-read" + + Rem additional analog, new system + pv5="X11MA-ES1:CADC1" + pv6="X11MA-ES1:CADC2" + pv7="X11MA-ES1:CADC3" + pv8="X11MA-ES1:CADC4" + + Keithley1a=0.0 + Keithley2a=0.0 + Keithleynorma=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + + Select Case v + Case 0 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + Case 1 + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Case 2 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithleynorma) + Case 3 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv4,ezcaDouble,1,Keithleynorma) + Case 4 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithleynorma) + r=ezcaGet(pv5,ezcaDouble,1,Analog1) + r=ezcaGet(pv6,ezcaDouble,1,Analog2) + r=ezcaGet(pv7,ezcaDouble,1,Analog3) + r=ezcaGet(pv8,ezcaDouble,1,Analog4) + End Select + +End Function + +Function keithley_read_XFMR(v As Double,ByRef Keithley1a As Double,ByRef Keithley2a As Double,ByRef Keithleynorma As Double, ByRef Analog1 As Double, ByRef Analog2 As Double, ByRef Analog3 As Double, ByRef Analog4 As Double) As Integer +Rem v = 0 : Keithley1 +Rem v = 1 : Keithley2 +Rem v = 2 : Keithley 1 + 2 +Rem v = 3 : Keithley1 + 2 + 3 +Rem v = 4 : Keithley1 + 2, norm, 4 analog + +Dim pv1 As String +Dim pv2 As String +Dim pv3 As String +Dim pv4 As String +Dim pv5 As String +Dim pv6 As String +Dim pv7 As String +Dim pv8 As String + + pv1="X11Keithley1-read" + pv2="X11Keithley2-read" + pv3="X11Keithleys:NORM" + pv4="X11Keithley3-read" + + Rem additional analog + 'pv5="X11MA-ES1-KEITH4:V" + 'pv6="X11MA-ES1-KEITH5:V" + 'pv7="X11MA-ES1-KEITH6:V" + 'pv8="X11MA-ES1-KEITH7:V" + + Rem additional analog, new system + pv5="X11MA-ES1:CADC1" + pv6="X11MA-ES1:CADC2" + pv7="X11MA-ES1:CADC3" + pv8="X11MA-ES1:CADC4" + + Keithley1a=0.0 + Keithley2a=0.0 + Keithleynorma=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + + Select Case v + Case 0 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + Case 1 + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Case 2 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithleynorma) + Case 3 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv4,ezcaDouble,1,Keithleynorma) + Case 4 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithleynorma) + r=ezcaGet(pv5,ezcaDouble,1,Analog1) + r=ezcaGet(pv6,ezcaDouble,1,Analog2) + r=ezcaGet(pv7,ezcaDouble,1,Analog3) + r=ezcaGet(pv8,ezcaDouble,1,Analog4) + End Select + +End Function + +Function keithley_done() As Double +Rem returns 1 if done, 0 if still reading +pv="X11Keithleys:alldone" + keithley_done=0 + r=ezcaGet(pv,ezcaDouble,1,keithley_done) +End Function + +Function putADC_integration(ByVal v As Double) +Dim pv As String + pv="X11MA-ES1-10ADC:AVG" + 'pv="X11MA-ES1:BUFFER_6_0" + 'v=v*10 '(Input In ms) + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getADC_integration() As Double +Dim pv As String + pv="X11MA-ES1-10ADC:AVG" + 'pv="X11MA-ES1:BUFFER_6_0" + r=ezcaGet(pv,ezcaDouble,1,getADC_integration) + 'getADC_integration=getADC_integration/10 '(ms) +End Function + +Function keithley_analog(v As Double, ByRef Keithley1a As Double, ByRef Keithley2a As Double, ByRef Keithleynorma As Double, ByRef Analog1 As Double, ByRef Analog2 As Double, ByRef Analog3 As Double, ByRef Analog4 As Double) As Integer +Rem v = 0 : Keithley1 +Rem v = 1 : Keithley2 +Rem v = 2 : Keithley 1 + 2 +Rem v = 3 : Keithley1 + 2 + 3 + + Rem change for X-FMR to Io and TEY Analog new A/D converter 25.11.2008 + 'pv1="X11MA-ES1:CADC5" + 'pv2="X11MA-ES1:CADC6" + 'pv3="X11MA-ES1:CADC7" + + Rem change for normal XMCD to Io and TEY Analog new A/D converter 25.11.2008 + pv1="X11MA-ES1:CADC1" + pv2="X11MA-ES1:CADC2" + pv3="X11MA-ES1:CADC3" + + 'pv1="X11MA-ES1-KEITH1:V" + 'pv2="X11MA-ES1-KEITH2:V" + 'pv3="X11MA-ES1-KEITH3:V" + + Rem additional analog + pv5="X11MA-ES1:CADC1" + pv6="X11MA-ES1:CADC2" + pv7="X11MA-ES1:CADC3" + pv8="X11MA-ES1:CADC4" + + Keithley1a=0.0 + Keithley2a=0.0 + Keithleynorma=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + + Select Case v + Case 0 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + Case 1 + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Case 2 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Keithleynorma=Keithley2a/Keithley1a + Case 3 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + r=ezcaGet(pv3,ezcaDouble,1,Keithleynorma) + Case 4 + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Keithleynorma=Keithley2a/Keithley1a + r=ezcaGet(pv5,ezcaDouble,1,Analog1) + r=ezcaGet(pv6,ezcaDouble,1,Analog2) + r=ezcaGet(pv7,ezcaDouble,1,Analog3) + r=ezcaGet(pv8,ezcaDouble,1,Analog4) + + End Select + +End Function + +Function getUmon() As Double +Dim pv As String + pv="X11MA-ES1-PEEM:UMON" + 'pv="X11MA-ES1-PEEM:UMONraw" for the not calibrated + r=ezcaGet(pv,ezcaDouble,1,getUmon) +End Function + +Function getImon() As Double +Dim pv As String + pv="X11MA-ES1-PEEM:IMON" + 'pv="X11MA-ES1-PEEM:IMONraw" for the not calibrated + r=ezcaGet(pv,ezcaDouble,1,getImon) +End Function + +Function putXMCDMag (ByVal v As Double) +Dim ps As String + pv="X11MA-XMCD:I-SETraw" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getXMCDMag() As Double +Dim pv As String + pv="X11MA-XMCD:Ireadout" + r=ezcaGet(pv,ezcaDouble,1,getXMCDMag) +End Function + +Function putIDmotors(v As Double) As Integer +Rem 0 = off, 1 = on, 2 = auto + pv="X11MA-ID1:ONOFF" + r=ezcaPut(pv,ezcaDouble,1,v) + pv="X11MA-ID2:ONOFF" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getID1offset() As Double + Dim pv As String + pv="X11MA-ID1:ENERGY-OFFS" + r=ezcaGet(pv,ezcaDouble,1,getID1offset) +End Function + +Function getID2offset() As Double +Dim pv As String + pv="X11MA-ID2:ENERGY-OFFS" + r=ezcaGet(pv,ezcaDouble,1,getID2offset) +End Function + +Function getID1gap() As Double + Dim pv As String + pv="X11MA-ID1-GAP:READ" + r=ezcaGet(pv,ezcaDouble,1,getID1gap) +End Function + +Function getID2gap() As Double +Dim pv As String + pv="X11MA-ID2-GAP:READ" + r=ezcaGet(pv,ezcaDouble,1,getID2gap) +End Function + +Function getID1shift() As Double + Dim pv As String + pv="X11MA-ID1-SHIFT:READ" + r=ezcaGet(pv,ezcaDouble,1,getID1shift) +End Function + +Function getID2shift() As Double +Dim pv As String + pv="X11MA-ID2-SHIFT:READ" + r=ezcaGet(pv,ezcaDouble,1,getID2shift) +End Function + +Function putID1offset(ByVal v As Double) +Dim pv As String + pv="X11MA-ID1:ENERGY-OFFS" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2offset(ByVal v As Double) +Dim pv As String + pv="X11MA-ID2:ENERGY-OFFS" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID1gap(ByVal v As Double) + Dim pv As String + pv="X11MA-ID1-GAP:SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2gap(ByVal v As Double) +Dim pv As String + pv="X11MA-ID2-GAP:SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID1shift(ByVal v As Double) + Dim pv As String + pv="X11MA-ID1-SHIFT:SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2shift(ByVal v As Double) +Dim pv As String + pv="X11MA-ID2-SHIFT:SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID1harmonic(ByVal v As Double) +Rem 0 : not existing +Rem 1 : 1st +Rem 2 : 2nd +Rem 3 : 3rd +Rem 4 : 4th +Rem 5 : 5th and so on, in use up to 3 + Dim pv As String + pv="X11MA-ID1:HARMONIC" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putID2harmonic(ByVal v As Double) +Rem 0 : not existing +Rem 1 : 1st +Rem 2 : 2nd +Rem 3 : 3rd +Rem 4 : 4th +Rem 5 : 5th and so on, in use up to 3 + Dim pv As String + pv="X11MA-ID2:HARMONIC" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getID1harmonic() As Double +Rem 0 : not existing +Rem 1 : 1st +Rem 2 : 2nd +Rem 3 : 3rd +Rem 4 : 4th +Rem 5 : 5th and so on, in use up to 3 + Dim pv As String + pv="X11MA-ID1:HARMONIC" + r=ezcaGet(pv,ezcaDouble,1,getID1harmonic) +End Function + +Function getID2harmonic() As Double +Rem 0 : not existing +Rem 1 : 1st +Rem 2 : 2nd +Rem 3 : 3rd +Rem 4 : 4th +Rem 5 : 5th and so on, in use up to 3 + Dim pv As String + pv="X11MA-ID2:HARMONIC" + r=ezcaGet(pv,ezcaDouble,1,getID2harmonic) +End Function + +Function opengapID1() +Dim pv As String +Dim v As Double + pv="X11MA-ID1-GAP:OPEN" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function opengapID2() +Dim pv As String +Dim v As Double + pv="X11MA-ID2-GAP:OPEN" + v=1 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putChopper(ByVal v As Double) +Rem 0 : "closed" +Rem 1 : "opened" +Dim pv As String + pv="X11MA-ES1-CHOPP:TRG" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getChopper() As Double +Rem 0 : "closed" +Rem 1 : "opened" +Dim pv As String + pv="X11MA-ES1-CHOPP:TRG" + r=ezcaGet(pv,ezcaDouble,1,getChopper) +End Function + +Function getgirder(ByRef po1 As Double, ByRef po2 As Double,ByRef po3 As Double,ByRef po4 As Double,ByRef po5 As Double) As Double +Dim pv(5) As String + + pv(1)="X11MA-HG:X1" + pv(2)="X11MA-HG:Y1" + pv(3)="X11MA-HG:PITCH1" + pv(4)="X11MA-HG:YAW1" + pv(5)="X11MA-HG:ROLL1" + + r=ezcaGet(pv(1),ezcaDouble,1,po1) + r=ezcaGet(pv(2),ezcaDouble,1,po2) + r=ezcaGet(pv(3),ezcaDouble,1,po3) + r=ezcaGet(pv(4),ezcaDouble,1,po4) + r=ezcaGet(pv(5),ezcaDouble,1,po5) + +End Function + +Function putgirder_all(ByVal po1 As Double, ByVal po2 As Double,ByVal po3 As Double,ByVal po4 As Double,ByVal po5 As Double) +Dim pv(5) As String + + pv(1)="X11MA-HG:X_SET" + pv(2)="X11MA-HG:Y_SET" + pv(3)="X11MA-HG:PITCH_SET" + pv(4)="X11MA-HG:YAW_SET" + pv(5)="X11MA-HG:ROLL_SET" + + r=ezcaPut(pv(1),ezcaDouble,1,po1) + r=ezcaPut(pv(2),ezcaDouble,1,po2) + r=ezcaPut(pv(3),ezcaDouble,1,po3) + r=ezcaPut(pv(4),ezcaDouble,1,po4) + r=ezcaPut(pv(5),ezcaDouble,1,po5) + +End Function + +'Function putgirder_rel(ByVal po1 As Double, ByVal po2 As Double,ByVal po3 As Double,ByVal po4 As Double,ByVal po5 As Double) +'Dim pv(5) As String +'Dim pv1 As String +'Dim v As Double + +' pv(1)="ARIAL-GIR:DDX.VAL" +' pv(2)="ARIAL-GIR:DDY.VAL" +' pv(3)="ARIAL-GIR:DDROLL.VAL" +' pv(4)="ARIAL-GIR:DDPITCH.VAL" +' pv(5)="ARIAL-GIR:DDYAW.VAL" +' pv1="ARIAL-GIR:CFD.VAL" +' +' r=ezcaPut(pv(1),ezcaDouble,1,po1) +' r=ezcaPut(pv(2),ezcaDouble,1,po2) +' r=ezcaPut(pv(3),ezcaDouble,1,po3) +' r=ezcaPut(pv(4),ezcaDouble,1,po4) +' r=ezcaPut(pv(5),ezcaDouble,1,po5) +' +' Rem calculate abs value +' v=1 +' r=ezcaPut(pv1,ezcaDouble,1,v) +' +'End Function + +Function putgirder_x(ByVal v As Double) +Dim pv As String + pv="X11MA-HG:X_SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putgirder_y(ByVal v As Double) +Dim pv As String + pv="X11MA-HG:Y_SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +'Function putgirder_x_rel(ByVal v As Double) +'Dim pv As String +'Dim pv1 As String +' +' pv="ARIAL-GIR:DDX.VAL" +' pv1="ARIAL-GIR:CFD.VAL" +' r=ezcaPut(pv,ezcaDouble,1,v) +' Rem calculate abs value +' v=1.0 +' r=ezcaPut(pv1,ezcaDouble,1,v) +'End Function + +'Function move_girder() +'Dim pv As String +'Dim v As Double +' +' pv="ARIAL-GIR:MVALL_3.VAL" +' v=1.0 +' r=ezcaPut(pv,ezcaDouble,1,v) +' +'End Function + +Function stop_girder() +Dim pv As String +Dim v As Double + + pv="X11MA-HG:MOVE_STOP.PROC" + v=0 + 'r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function done_girder() As Double +Rem 0 = no motor is moving +Rem 1 = one or more motors are moving + + Dim pv As String + Dim v As Double + + pv="X11MA-HG:MOVN" + r=ezcaGet(pv,ezcaDouble,1,done_girder) + +End Function + +Function PHS_mode(ByVal v As Double) +Rem set PGM + ID mode +Rem 0: PGM +Rem 1: PGM+ID1 +Rem 2: PGM+ID2 +Rem 3: PGM+ID1+ID2 + +Dim pv As String + + pv="X11PHS-E:OPT" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getPhaseBump() As Double +Dim pv As String + pv="X11MA-ID-PHASE:SOFTBUMP-RB" + r=ezcaGet(pv,ezcaDouble,1,getPhaseBump) +End Function + +Function putPhaseBump(ByVal v As Double) +Dim pv As String + pv="X11MA-ID-PHASE:BUMP" + If Abs(v)<3 Then + r=ezcaPut(pv,ezcaDouble,1,v) + Else + write_logfile(1,"Current for Phasebump to high (-3 to 3 A) :"+Format(v)) + End If +End Function + +Function donePhaseBump() As Double +Dim pv As String + pv="X11MA-ID-PHASE:BUMP-DONE" + r=ezcaGet(pv,ezcaDouble,1,donePhaseBump) + 'donemove=1 +End Function + +Function getXBPM1(ByRef po1 As Double, ByRef po2 As Double) As Double +Dim pv(2) As String + + pv(1)="X11MA-FE-XBPM1:posH" + pv(2)="X11MA-FE-XBPM1:posV" + + r=ezcaGet(pv(1),ezcaDouble,1,po1) + r=ezcaGet(pv(2),ezcaDouble,1,po2) + +End Function + +Function getXBPM2(ByRef po1 As Double, ByRef po2 As Double) As Double +Dim pv(2) As String + + pv(1)="X11MA-FE-XBPM2:posH" + pv(2)="X11MA-FE-XBPM2:posV" + + r=ezcaGet(pv(1),ezcaDouble,1,po1) + r=ezcaGet(pv(2),ezcaDouble,1,po2) + +End Function + +Function getID1Bergoz(ByRef po1 As Double, ByRef po2 As Double,ByRef po3 As Double,ByRef po4 As Double) As Double +Dim pv(4) As String + + pv(1)="X11MA-ID1-FBPMU:X" + pv(2)="X11MA-ID1-FBPMU:Y" + pv(3)="X11MA-ID1-FBPMD:X" + pv(4)="X11MA-ID1-FBPMD:Y" + + r=ezcaGet(pv(1),ezcaDouble,1,po1) + r=ezcaGet(pv(2),ezcaDouble,1,po2) + r=ezcaGet(pv(3),ezcaDouble,1,po3) + r=ezcaGet(pv(4),ezcaDouble,1,po4) + +End Function + +Function getID2Bergoz(ByRef po1 As Double, ByRef po2 As Double,ByRef po3 As Double,ByRef po4 As Double) As Double +Dim pv(4) As String + + pv(1)="X11MA-ID2-FBPMU:X" + pv(2)="X11MA-ID2-FBPMU:Y" + pv(3)="X11MA-ID2-FBPMD:X" + pv(4)="X11MA-ID2-FBPMD:Y" + + r=ezcaGet(pv(1),ezcaDouble,1,po1) + r=ezcaGet(pv(2),ezcaDouble,1,po2) + r=ezcaGet(pv(3),ezcaDouble,1,po3) + r=ezcaGet(pv(4),ezcaDouble,1,po4) + +End Function + +Function getVG10() As Integer +Dim pv As String +Dim DVal As Double + pv="X11MA-OP-VG10:OPEN" + r=ezcaGet(pv,ezcaDouble,1,DVal) + getVG10 = DVal +End Function + +Function putVG10(ByVal v As Double) +Rem 0 : "closed" +Rem 1 : "opened" +Dim pv As String + pv="X11MA-EPS-VG10:SET" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getMainPressure() As Double +Dim pv As String + pv="X11MA-ES1-MAIN:PRESSURE" + r=ezcaGet(pv,ezcaDouble,1,getMainPressure) +End Function + +Function getGascell() As Double +Dim pv As String + pv="X11MA-OP-GCMT1:PRESSURE" + r=ezcaGet(pv,ezcaDouble,1,getGascell) +End Function + +Function putCMURy(ByVal v As Double) +Dim pv As String + pv="X11MA-OP-CM:Ry" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getCMURy() As Double +Dim pv As String + pv="X11MA-OP-CM:oRy" + r=ezcaGet(pv,ezcaDouble,1,getCMURy) +End Function + +Function getCM1() As Double +Rem chicane Magnet value for Phasebump +Dim pv As String + pv="X11MA-ID-CM1A:I-SET" + r=ezcaGet(pv,ezcaDouble,1,getCM1) +End Function + +Function getCM2() As Double +Rem chicane Magnet value for Phasebump +Dim pv As String + pv="X11MA-ID-CM2A:I-SET" + r=ezcaGet(pv,ezcaDouble,1,getCM2) +End Function + +Function getCM3() As Double +Rem chicane Magnet value for Phasebump +Dim pv As String + pv="X11MA-ID-CM3A:I-SET" + r=ezcaGet(pv,ezcaDouble,1,getCM3) +End Function + +Function getHP() As Double +Rem chicane Magnet value for Phasebump +Dim pv As String + pv="X11MA-CM2-HP1:BX" + r=ezcaGet(pv,ezcaDouble,1,getHP) +End Function + +Function getFEcenterHor() As Double +Rem FrontEnd center horizontal +Dim pv As String + pv="X11MA-FE-SH:ctr" + r=ezcaGet(pv,ezcaDouble,1,getFEcenterHor) +End Function + +Function putFEcenterHor(ByVal v As Double) +Rem FrontEnd center horizontal +Dim pv As String + pv="X11MA-FE-SH:ctr" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getFEcenterVer() As Double +Rem FrontEnd center vertical +Dim pv As String + pv="X11MA-FE-SV:ctr" + r=ezcaGet(pv,ezcaDouble,1,getFEcenterVer) +End Function + +Function putFEcenterVer(ByVal v As Double) +Rem FrontEnd center vertical +Dim pv As String + pv="X11MA-FE-SV:ctr" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function done_FE() As Double +Rem FrontEnd center horizontal, right panel, done move +Rem 0: moving +Rem 1: stopped +Dim pv1,pv2,pv3,pv4 As String +Dim v1 As Double +Dim v2 As Double +Dim v3 As Double +Dim v4 As Double + sleep_f(1) + pv1="X11MA-FE-SH1:TR2.DMOV" + pv2="X11MA-FE-SH1:TR1.DMOV" + pv3="X11MA-FE-SV1:TR2.DMOV" + pv4="X11MA-FE-SV1:TR1.DMOV" + r=ezcaGet(pv1,ezcaDouble,1,v1) + r=ezcaGet(pv2,ezcaDouble,1,v2) + r=ezcaGet(pv3,ezcaDouble,1,v3) + r=ezcaGet(pv4,ezcaDouble,1,v4) + v1=v1+v2+v3+v4 + If v1=4 Then done_FE=1 Else done_FE=0 +End Function + +Function getTBTsetField() As Double +Rem Strasbourg XMCD chamber +Rem set value for Magnetic field +Dim pv As String + pv="X11MA-LSCI632:MFIELD" + r=ezcaGet(pv,ezcaDouble,1,getTBTsetField) +End Function + +Function getTBTrdkField() As Double +Rem Strasbourg XMCD chamber +Rem readback value for Magnetic field +Dim pv As String + pv="X11MA-LSCI632:RBKMFIELD" + r=ezcaGet(pv,ezcaDouble,1,getTBTrdkField) +End Function + +Function getTBTdone() As Double +Rem Strasbourg XMCD chamber +Rem done setting field +Rem 0: Done +Rem 1: Busy +Dim pv As String + pv="X11MA-LSCI632:busy" + r=ezcaGet(pv,ezcaDouble,1,getTBTdone) +End Function + +Function putTBTdone(ByVal v As Double) +Rem Strasbourg XMCD chamber +Rem done setting field +Rem 0: Done +Rem 1: Busy +Dim pv As String + pv="X11MA-LSCI632:busy" + r=ezcaPut(pv,ezcaDouble,1,getTBTdone) +End Function + +Function putTBTsetField(ByVal v As Double) +Rem Strasbourg XMCD chamber +Rem set value for Magnetic field +Dim pv As String + pv="X11MA-LSCI632:MFIELD" + r=ezcaPutCallback(pv,ezcaDouble,1,v) +End Function + +Function ackTBTwarning +Rem Strasbourg XMCD chamber +Rem acknowledgement that Turbo is switched off +Dim pv As String +Dim v As Double + v=0 + pv="X11MA-LSCI632:WARNING" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function startTBTset +Rem Strasbourg XMCD chamber +Rem sets the Magnetic field to the value defined with putTBTsetField +Rem 1. switch heater +Rem 2. wait 20 sec +Rem 3. sets current +Rem 4. switch heater + +Dim pv As String +Dim v As Double + v=1 + pv="X11MA-LSCI632:setfield-go.PROC" + r=ezcaPutCallback(pv,ezcaDouble,1,v) +End Function + +Function startTBTscan +Rem Strasbourg XMCD chamber +Rem sets the Magnetic field to the value defined with putTBTsetField +Rem 1. switch heater when used the first time, otherwise direct +Rem 2. wait 20 sec +Rem 3. sets current +Rem 4. not swichting the heater +Rem Note that one has to switch the heater later manualy + +Dim pv As String +Dim v As Double + v=1 + pv="X11MA-LSCI632:scanfield-go.PROC" + r=ezcaPutCallback(pv,ezcaDouble,1,v) +End Function + +Function putTBTstring(ByVal v As Double) +Rem Strasbourg XMCD chamber +Rem set value for Magnetic field +Dim pv As String + pv="X11MA-LSCI632:MFIELD" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +'Function setTBT_PSH_off +Rem Strasbourg XMCD chamber +Rem Set the GPIB message in the sin_new channel +Rem Send the command +'Dim pv As String +'Dim v As String +' v="s PSH 0" + Chr$(0) +Chr$(13) + Chr$(10) +' pv="X11MA-LSCI632:sin_new" +' r=ezcaPut(pv,ezcaString,1,v) + +'Dim v2 As Double +' v2=1 +' pv="X11MA-LSCI632:clr-go.PROC" +' r=ezcaPutCallback(pv,ezcaDouble,1,v2) +'End Function + +Function putAnalog1(ByVal v As Double) +Dim pv As String + pv="X11MA-ES1-AO1:V" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putOTF_autoname(ByVal v As Double) +Rem YYMMDD for the otf scan files names +Dim pv As String + pv="X11MA-OTF:FTSTAMP" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getOTF_autonum() +Rem number for the otf scan file names +Dim pv As String + pv="X11MA-OTF:FID" + r=ezcaGet(pv,ezcaDouble,1,OTF_autonum) +End Function + +Function putOTF_autonum(ByVal v As Double) +Rem number for the otf scan file names +Dim pv As String + pv="X11MA-OTF:FID" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putOTF_path(ByVal vs As String) +Rem not working +Dim pv As String + pv="X11MA-OTF:FNAME" + r=ezcaPut(pv,ezcaString,1,vs) +End Function + +Function getOTF_path() As String +Rem not working +Dim pv As String + pv="X11MA-OTF:FNAME" + r=ezcaGet(pv,ezcaString,1,getOTF_path) +End Function + +Function putOTF_Estart(ByVal v As Double) +Rem start energy for otf +Dim pv As String + pv="X11MA-OTF:E1" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putOTF_Eend(ByVal v As Double) +Rem end energy for otf +Dim pv As String + pv="X11MA-OTF:E2" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putOTF_time(ByVal v As Double) +Rem time for otf scan in minutes +Dim pv As String + pv="X11MA-OTF:TIME" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function startOTF +Rem start otf scan +Rem 0 = "Stop" +Rem 1 = "Start" or "moving" +Dim v As Integer +Dim pv As String + pv="X11MA-OTF:GO" + v=1 + r=ezcaPut(pv,ezcaShort,1,v) +End Function + +Function stopOTF +Rem start otf scan +Rem 0 = "Stop" +Rem 1 = "Start" or "moving" +Dim v As Integer +Dim pv As String + pv="X11MA-OTF:GO" + v=0 + r=ezcaPut(pv,ezcaShort,1,v) +End Function + +Function getOTF_done() As Double +Rem status of otf scan +Rem 0 = "Done" +Rem 1 = "Moving" +Dim pv As String + pv="X11MA-OTF:GO" + r=ezcaGet(pv,ezcaDouble,1,getOTF_done) +End Function + +Function getOTF_analog(ByRef Keithley1a As Double,ByRef Keithley2a As Double,ByRef Keithleynorma As Double) As Integer + +Dim pv1 As String +Dim pv2 As String +Dim pv3 As String +Dim pv4 As String +Dim pv5 As String +Dim pv6 As String +Dim pv7 As String +Dim pv8 As String + + pv1="X11MA-ES1:CADC1" + pv2="X11MA-ES1:CADC2" + + Keithley1a=0.0 + Keithley2a=0.0 + Keithleynorma=0.0 + + r=ezcaGet(pv1,ezcaDouble,1,Keithley1a) + r=ezcaGet(pv2,ezcaDouble,1,Keithley2a) + Keithleynorma=Keithley2a/Keithley1a + +End Function + +Function putMono_integration(ByVal v As Double) +Dim pv As String + pv="X11MA-PGM:CERBK.N" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function putMono_speed_normal +Dim pv As String + pv="X11MA:m1.VELO" + v=0.01 + r=ezcaPut(pv,ezcaDouble,1,v) + pv="X11MA:m2.VELO" + v=0.01 + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function getMono_integration() As Double +Dim pv As String + 'pv="X11MA-PGM:CERBK.N" + 'r=ezcaGet(pv,ezcaDouble,1,getMono_integration) +End Function + +Function open_chopper +Rem for fast chopper from RESOXS group +Dim pv As String +Dim v As Double + v=0 + pv="X11MA-ES-PP:BO8" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function + +Function close_chopper +Rem for fast chopper from RESOXS group +Dim pv As String +Dim v As Double + v=1 + pv="X11MA-ES-PP:BO8" + r=ezcaPut(pv,ezcaDouble,1,v) +End Function diff --git a/script/test/X11MA_main_functions.ipm b/script/test/X11MA_main_functions.ipm new file mode 100644 index 0000000..b0bd5c0 --- /dev/null +++ b/script/test/X11MA_main_functions.ipm @@ -0,0 +1,3295 @@ +Attribute VB_Name = "Module1" +'Option Explicit +'#uses "X11MA_beamline.ipm" +'#uses "X11MA_LEEM.ipm" +'#uses "X11MA_LJ.ipm" +'#uses "epics.ipm" +'#uses "sls_log.ipm" +'#uses "sls_plot.ipm" + +Rem global variables +Rem for saving +Global autopath As String +Global autoname As String +Global autonum As Integer +Global configpath As String + +Global autoexpo(2) As Long +Global autoaver(2) As Long +Global autosave As Long +Global autoenergy(2) As Double +Global autocontrast As Single +Global autoseq As Long +Global sensi_image As String +Global autoscale As Single +Global autocycles As Long + +Rem for stack +Global energym(20)As Double +Global estepm(20) As Double +Global stackfilepath As String +Global estepmCheck(20) As Integer + +Rem for beamline +Global setEnergy As Double +Global rbkEnergy As Double +Global avrbkenergy As Double +Global Polarisation As Double +Global Polarisationstring As String +'Global linearMode As Double +Global activeID As Single +Global opID As Single +Global polswitchmode As Single +Global polstring(5) As String +Global linrotstring As String +Global switchstring(3) As String +Global linrotstringID1(19) As String +Global linrotstringID2(19) As String +Global linrotalphadegID1(19) As Single +'Global linrotID1 As Single +'Global linrotID2 As Single +Global polID1 As Single +Global polID2 As Single +Global pol As Single +Global ID1offset As Double +Global ID2offset As Double +Global IDswitching As String +Global ID1rbkEnergy As Double +Global ID2rbkEnergy As Double +Global ID1alpha As Double +Global ID2alpha As Double +Global ID1harmonic As Double +Global ID2harmonic As Double + +Rem for linear rot scan +Global E1,E2,E3 As Double +Global E4 As Double +Global E5 As Double +Global E6 As Double +Global E7 As Double +Global E8 As Double +Global E9 As Double +Global E10 As Double +Global setRotstep As Single + +Global ID1_linrot_gap (631,19) As Double +Global ID1_linrot_shift (631,19) As Double +Global ID1_linrot_offset(90) As Double +Global ID2_linrot_gap (631,19) As Double +Global ID2_linrot_shift (631,19) As Double +Global ID2_linrot_offset(90) As Double + + +Rem for XMCD (small one) +Global setXMCDMag As Double +Global rbkXMCDMag As Double + +Rem for Strassbourg XMCD +Global rbkTBTMag As Double +Global setTBTMag As Double +Global Const maxTBT = 7.0 +Global TBTTemperature As Double +Global timer0 As Double + +Global L2edge As Double +Global L3edge As Double +Global En1 As Double +Global En2 As Double +Global En3 As Double +Global En4 As Double +Global En5 As Double +Global CE1 As Double +Global CE2 As Double +Global CE3 As Double +Global CE4 As Double +Global CE5 As Double +Global Saturation_Field As Double +Global Measurement_Field As Double + +Rem for measurment +Global noint As Integer +Global KeithleyMode As Integer +Global KeithleyNo As Double +Global VG10 As Integer +Global do_checkbeamline As Integer +Global do_checkring As Integer +Global KeithleyDelay As Integer +Global ScanDelay As Integer +Global noADC As Integer + +Rem for LEEM200 +Global startvoltage As Double +Global objective As Double +Global LEEMtemp As Double + +Rem for girder +Global x_from As Double +Global x_to As Double +Global x_d As Double + +Rem for time_scan +Global timespan As Single +Global MCP_Delay As Double +Global MCP_Delay_Fine As Double +Global PulsePicker_Delay As Double +Global PulsePicker_Delay_Fine As Double +Global Laser_Initial_Delay As Double + +Rem for Phasebump +Global Phstart As Double +Global Phend As Double +Global Phstep As Double +Global Phset As Double + +Rem for calculating focus +Global calcstartSV As Double +Global calcstartOB As Double +Global calcSV As Double +Global calcOB As Double + + +Sub mkdirs(path As String) + Dim d As String + Dim c As String + + On Error Resume Next + + d="" + For i=1 To Len(path) + c=Mid(path,i,1) + If c = "\" And i <> 3 Then + MkDir d + End If + d=d+c + Next i + MkDir d + On Error GoTo 0 +End Sub + +Sub init_def + Polstring(1)="circ +" + Polstring(2)="circ -" + Polstring(3)="lin hor" + Polstring(4)="lin vert" + Polstring(5)="lin rot" + + linrotstringID1(0)="" ' for circ or ver or hor + linrotstringID1(1)=" 0" + linrotstringID1(2)=" 5" + linrotstringID1(3)=" 10" + linrotstringID1(4)=" 15" + linrotstringID1(5)=" 20" + linrotstringID1(6)=" 25" + linrotstringID1(7)=" 30" + linrotstringID1(8)=" 35" + linrotstringID1(9)=" 40" + linrotstringID1(10)=" 45" + linrotstringID1(11)=" 50" + linrotstringID1(12)=" 55" + linrotstringID1(13)=" 60" + linrotstringID1(14)=" 65" + linrotstringID1(15)=" 70" + linrotstringID1(16)=" 75" + linrotstringID1(17)=" 80" + linrotstringID1(18)=" 85" + linrotstringID1(19)=" 90" + + linrotstringID2(0)="" ' for circ or ver or hor + linrotstringID2(1)=" 0" + linrotstringID2(2)=" 5" + linrotstringID2(3)=" 10" + linrotstringID2(4)=" 15" + linrotstringID2(5)=" 20" + linrotstringID2(6)=" 25" + linrotstringID2(7)=" 30" + linrotstringID2(8)=" 35" + linrotstringID2(9)=" 40" + linrotstringID2(10)=" 45" + linrotstringID2(11)=" 50" + linrotstringID2(12)=" 55" + linrotstringID2(13)=" 60" + linrotstringID2(14)=" 65" + linrotstringID2(15)=" 70" + linrotstringID2(16)=" 75" + linrotstringID2(17)=" 80" + linrotstringID2(18)=" 85" + linrotstringID2(19)=" 90" + + ID1_linrot_offset(0)= 0 + ID1_linrot_offset(5)= 1 + ID1_linrot_offset(10)= 2 + ID1_linrot_offset(15)= 2.5 + ID1_linrot_offset(20)= 2.5 + ID1_linrot_offset(25)= 2.5 + ID1_linrot_offset(30)= 2.5 + ID1_linrot_offset(35)= 2.5 + ID1_linrot_offset(40)= 2.5 + ID1_linrot_offset(45)= 2.5 + ID1_linrot_offset(50)= 2.5 + ID1_linrot_offset(55)= 2.5 + ID1_linrot_offset(60)= 2.5 + ID1_linrot_offset(65)= 2.5 + ID1_linrot_offset(70)= 2.5 + ID1_linrot_offset(75)= 2 + ID1_linrot_offset(80)= 1 + ID1_linrot_offset(85)= 0 + ID1_linrot_offset(90)= 0 + + ID2_linrot_offset(0)= 0 + ID2_linrot_offset(5)= 5 + ID2_linrot_offset(10)= 8 + ID2_linrot_offset(15)= 10 + ID2_linrot_offset(20)= 11 + ID2_linrot_offset(25)= 12 + ID2_linrot_offset(30)= 12 + ID2_linrot_offset(35)= 12 + ID2_linrot_offset(40)= 12 + ID2_linrot_offset(45)= 11 + ID2_linrot_offset(50)= 10 + ID2_linrot_offset(55)= 9 + ID2_linrot_offset(60)= 8 + ID2_linrot_offset(65)= 7 + ID2_linrot_offset(70)= 6 + ID2_linrot_offset(75)= 4 + ID2_linrot_offset(80)= 3 + ID2_linrot_offset(85)= 0 + ID2_linrot_offset(90)= 0 + + + switchstring(1)="normal" + switchstring(2)="tune/detune" + switchstring(3)="chopper" + + 'Rem default is measure Keithley1+2+Norm + 'KeithleyNo=2 + + Current_job=0 + Jobsrunning=False + + noint=1 + noADC=100 + +End Sub + +Sub getbeamline + rbkEnergy=getEnergy() + + Select Case opID + Case 1 + polID1=getPolID1() + pol=polID1 + If pol=5 Then linrotstring=CStr(ID1alpha) Else linrotstring="" + 'ID1rbkEnergy=getID1rbkEnergy() + Case 2 + polID2=getPolID2() + pol=polID2 + If pol=5 Then linrotstring=CStr(ID2alpha) Else linrotstring="" + 'ID2rbkEnergy=getID2rbkEnergy() + Case 3 + polID1=getPolID1() + polID2=getPolID2() + 'ID1rbkEnergy=getID1rbkEnergy() + 'ID2rbkEnergy=getID2rbkEnergy() + If activeID=1 Then pol=polID1 + If activeID=2 Then pol=polID2 + If activeID=3 Then pol=polID1 + If pol=5 Then + If activeID=1 Then linrotstring=CStr(ID1alpha) Else linrotstring="" + If activeID=2 Then linrotstring=CStr(ID2alpha) Else linrotstring="" + If activeID=3 Then linrotstring=CStr(ID1alpha) Else linrotstring="" + End If + Case Else + polID1=getPolID1() + polID2=getPolID2() + 'ID1rbkEnergy=getID1rbkEnergy() + 'ID2rbkEnergy=getID2rbkEnergy() + pol=polID1 + End Select + +End Sub + +Function checkRing() As Integer +Rem 0 Ring ok +Rem 1 Ring FB off +Rem 2 Ring down +Rem 3 cancel was pressed + +Dim ID1status As Integer +Dim ID2status As Integer +Dim Ringstatus As Integer +Dim status As Boolean +Dim oldRingstatus As Integer + +If do_checkring=1 Then + ID1status=getID1control + ID2status=getID2control + Ringstatus=getRingstatus + status=False + oldRingstatus=Ringstatus + checkRing=0 + + If Ringstatus=5 Then + write_logfile(1,"FB off") + addKeyVal "status","FB off" + checkRing=1 + End If + + If Ringstatus=0 Then + write_logfile(1,"Machine down") + addKeyVal "status","M down" + checkRing=2 + End If + + If checkRing>0 Then + Do + ID1status=getID1control + ID2status=getID2control + Ringstatus=getRingstatus + If oldRingstatus<>Ringstatus Then + Select Case Ringstatus + Case 0 + write_logfile(1,"Machine down") + checkRing=2 + addKeyVal "status","M down" + oldRingstatus=Ringstatus + Case 1 + write_logfile(1,"Inj. Stopped") + checkRing=2 + oldRingstatus=Ringstatus + Case 2 + write_logfile(1,"Accumulating.") + checkRing=2 + oldRingstatus=Ringstatus + Case 3 + write_logfile(1,"Accumulating") + checkRing=2 + oldRingstatus=Ringstatus + Case 4 + write_logfile(1,"Top-up ready, Gap still open") + checkRing=2 + oldRingstatus=Ringstatus + Case 5 + write_logfile(1,"Light-Available, no OFB") + checkRing=2 + oldRingstatus=Ringstatus + Case 6 + write_logfile(1,"Light Available") + checkRing=2 + oldRingstatus=Ringstatus + End Select + End If + If Ringstatus =6 And ID1status=1 And ID2status=1 Then + status=True + End If + If cancelmacro() = 0 Then + status=True + checkRing=3 + End If + sleep(1) + Loop While status=False + Select Case checkRing + Case 2 + write_logfile(1,"wait 120 s") + addKeyVal "status","waiting" + sleep(120) + write_logfile(0,"continue") + Case 1 + write_logfile(1,"wait 10 s") + addKeyVal "status","waiting" + sleep(10) + write_logfile(0,"continue") + End Select + End If +End If +End Function + +Sub getLEEM + startvoltage=getStartvoltage() + objective=getObjective() + LEEMtemp=getLEEMtemp() +End Sub + +Sub getXMCD + rbkXMCDMag=getXMCDMag() +End Sub + +Sub getTBT + rbkTBTMag=getTBTrdkField() +End Sub + +Sub updatelog +Rem updates the infos in the log window + addKeyVal "Energy",Format(rbkEnergy,"0.000") + addKeyVal "Polarization",Polstring(pol)+" "+linrotstring + addKeyVal "activeID",Format(activeID) + addKeyVal "IDswitching",switchstring(polswitchmode) + addKeyVal "Objective", Format(objective,"0.0") + addKeyVal "SV", Format(startvoltage,"0.00") +End Sub + +Function write_logfile(a As Integer, message As String) + addMessage a,message + If FileExists(autopath) Then + Open autopath+"logfile.log" For Append As #5 + Else + Open "C:\IpWin5\X11MAconfig\logfile.log" For Append As #5 + End If + Print #5, Format(Date())+" "+Format(Time())+" "+message + Close #5 +End Function + +Sub startMacro(n As String) +Rem sets log window active +Dim value As Double + addMessage 0,"" ' otherwise program crashes when log window not open + 'write on log + write_logfile(0,"start macro "+n) + 'addMessage 0,"start macro "+n + addKeyVal "Status",n+" running" + updatelog + 'active log + setRunning 1 +End Sub + +Sub stopMacro +Rem set log window passive +Dim value As Double +'write on log + write_logfile(0,"stop macro") + 'addMessage 0,"stop macro" + addKeyVal "Status","Macro done" + addKeyVal "Energy","done" + addKeyVal "Polarization","done" + addKeyVal "activeID","done" + addKeyVal "IDswitching","done" + addKeyVal "Objective","done" + addKeyVal "SV","done" + 'active log + setRunning 0 +End Sub + +Function cancelmacro() As Integer +Rem if macro stoped by canelbutton, writes macro stoped + cancelmacro=isRunning() + If cancelmacro =0 Then + Begin Dialog UserDialog 10,10,130,63,"Message" ' %GRID:10,7,1,1 + Text 20,7,90,14,"Macro stoped",.Text1 + OKButton 10,28,90,21 + End Dialog + Dim scanstoped As UserDialog + Dialog scanstoped + 'MsgBox "Scan canceled" + 'info on X11MA log window + stopMacro + End If +End Function + +Function checkbeamline() As Integer +Rem 0 beamline ok +Rem 1 beamline error +Rem 2 +Rem 3 cancel was pressed + +Dim ID1status As Integer +Dim ID2status As Integer +Dim ID1error As Integer +Dim ID2error As Integer +Dim ID1error_old As Integer +Dim ID2error_old As Integer +Dim status As Boolean +Dim message(5) As String + + If do_checkbeamline = 1 Then + ID1error_old=0 + ID2error_old=0 + checkbeamline=0 + message(5)= "Interlock" + message(4)= "Moving timeout" + message(3)= "Operator control" + message(2)= "Feedforward error" + message(1)= "Encoder error" + message(0)= "PLC error" + + + Do + Select Case opID + Case 1 + ID1status=getID1status + ID2status=0 + If ID1status = 0 Then status = True + Case 2 + ID1status=0 + ID2status=getID2status + If ID2status = 0 Then status = True + Case 3 + ID1status=getID1status + ID2status=getID2status + If (ID1status = 0) And (ID2status = 0) Then status = True + End Select + + If ID1status >= 1 Then + ID1error=getID1error + If ID1error<>ID1error_old Then + checkbeamline=1 + status = False + ID1error_old=ID1error + + For bit=5 To 0 Step -1 + ID1test=ID1error/(2^bit) + If ID1test >= 1 Then + write_logfile(1,"ID1 "+message(bit)) + ID1error=ID1error-(2^bit) + End If + Next bit + End If + End If + + If ID2status >= 1 Then + ID2error=getID2error + If ID2error<>ID2error_old Then + checkbeamline=1 + status = False + ID2error_old=ID2error + + For bit=5 To 0 Step -1 + ID2test=ID2error/(2^bit) + If ID2test >= 1 Then + write_logfile(1,"ID2 "+message(bit)) + ID2error=ID2error-(2^bit) + End If + Next bit + End If + End If + If cancelmacro() = 0 Then + status=True + checkbeamline=3 + End If + sleep(1) + Loop While status=False + End If + +End Function + +Sub loadstackfile +Rem load setting (energy and steps) for stack from *_stack.txt +Dim Iname As String *255 +Dim i As Integer +Dim selectfile As Integer + 'Selectfile = IpStGetName("Select file","C:\IpWin4\X11MAconfig","*stack.txt",Iname) + Selectfile = IpStGetName("Select file",configpath,"*.scn",Iname) + If Selectfile = 0 Then Exit Sub + Open Iname For Input As#1 + For i = 1 To 20 + Input #1, energym(i) + Input #1, estepm(i) + Input #1, estepmCheck(i) + If EOF(1) Then + Close + Exit Sub + End If + Next i + Close #1 +End Sub + +Sub savestackfile +Rem save setting (energy and steps) for stack in *_stack.txt +Dim Iname As String *200 +Dim selectfile As Integer +Dim i As Integer + Selectfile = IpStGetName("save as *.scn",configpath,"*.scn",Iname) + If Selectfile = 0 Then Exit Sub + tt= InStrRev(Iname,".") + If tt = 0 Then + tt=InStr(Iname,vbNullChar) + Iname=Left(Iname,tt-1)+".scn" + Else + Iname=Left(Iname,tt-1)+".scn" + End If + Open Iname For Output As#1 + For i = 1 To 20 + Write #1, energym(i) + Write #1, estepm(i) + Write #1, estepmCheck(i) + Next i + Close #1 +End Sub + +Sub saveX11MAstack +Rem saves actual settings of stack + Dim i As Integer + Open "C:\IPWin5\X11MAconfig\X11MA_stack.scn" For Output As#1 + For i = 1 To 20 + Write #1, energym(i) + Write #1, estepm(i) + Write #1, estepmCheck(i) + Next i + Close #1 +End Sub + +Sub loadX11MAstack +Rem load last settings of stack + Dim i As Integer + Open "C:\IPWin5\X11MAconfig\X11MA_stack.scn" For Input As#1 + For i = 1 To 20 + Input #1, energym(i) + Input #1, estepm(i) + Input #1, estepmCheck(i) + If EOF(1) Then + Close + Exit Sub + End If + Next i + Close #1 +End Sub + +Sub saveX11MA_PEEMconfig +Rem saves setting for automatic saving of images + Open "C:\IPWin5\X11MAconfig\X11MA_PEEM.txt" For Output As#3 + Write #3, autopath + Write #3, autoname + Write #3, autoexpo(1) + Write #3, autoexpo(2) + Write #3, autoaver(1) + Write #3, autoaver(2) + Write #3, autosave + Write #3, autoenergy(1) + Write #3, autoenergy(2) + Write #3, autocontrast + Write #3, configpath + Write #3, sensi_image + Write #3, opID + Write #3, polswitchmode + Write #3, ID1offset + Write #3, ID2offset + Write #3, noint + Write #3, KeithleyMode + Write #3, VG10 + Write #3, L3edge + Write #3, L2edge + Write #3, E1 + Write #3, E2 + Write #3, E3 + Write #3, E4 + Write #3, E5 + Write #3, E6 + Write #3, E7 + Write #3, E8 + Write #3, E9 + Write #3, E10 + Write #3, setRotstep + Write #3, do_checkbeamline + Write #3, do_checkring + Close #3 +End Sub + +Sub loadX11MA_PEEMconfig +Rem load settings for automatic saving of images + Open "C:\IPWin5\X11MAconfig\X11MA_PEEM.txt" For Input As#3 + Input #3, autopath + Input #3, autoname + Input #3, autoexpo(1) + Input #3, autoexpo(2) + Input #3, autoaver(1) + Input #3, autoaver(2) + Input #3, autosave + Input #3, autoenergy(1) + Input #3, autoenergy(2) + Input #3, autocontrast + Input #3, configpath + Input #3, sensi_image + Input #3, opID + Input #3, polswitchmode + Input #3, ID1offset + Input #3, ID2offset + Input #3, noint + Input #3, KeithleyMode + Input #3, VG10 + Input #3, L3edge + Input #3, L2edge + Input #3, E1 + Input #3, E2 + Input #3, E3 + Input #3, E4 + Input #3, E5 + Input #3, E6 + Input #3, E7 + Input #3, E8 + Input #3, E9 + Input #3, E10 + Input #3, setRotstep + Input #3, do_checkbeamline + Input #3, do_checkring + Close #3 +End Sub + +Sub saveX11MA_XMCDconfig +Rem saves setting for automatic saving of images + Open "C:\IPWin5\X11MAconfig\X11MA_XMCD.txt" For Output As#3 + Write #3, autopath + Write #3, autoname + 'Write #3, autoexpo(1) + 'Write #3, autoexpo(2) + 'Write #3, autoaver(1) + 'Write #3, autoaver(2) + Write #3, autosave + 'Write #3, autoenergy(1) + 'Write #3, autoenergy(2) + 'Write #3, autocontrast + Write #3, configpath + 'Write #3, sensi_image + Write #3, opID + Write #3, polswitchmode + Write #3, ID1offset + Write #3, ID2offset + Close #3 +End Sub + +Sub loadX11MA_XMCDconfig +Rem load settings for automatic saving of images + Open "C:\IPWin5\X11MAconfig\X11MA_XMCD.txt" For Input As#3 + Input #3, autopath + Input #3, autoname + 'Input #3, autoexpo(1) + 'Input #3, autoexpo(2) + 'Input #3, autoaver(1) + 'Input #3, autoaver(2) + Input #3, autosave + 'Input #3, autoenergy(1) + 'Input #3, autoenergy(2) + 'Input #3, autocontrast + Input #3, configpath + 'Input #3, sensi_image + Input #3, opID + Input #3, polswitchmode + Input #3, ID1offset + Input #3, ID2offset + Close #3 +End Sub + +'Function find_next_file_Backup(prefix As String, suffix As String) +' f = Dir$(prefix + "_*." + suffix) +' mx = 0 +' Do While f <> "" +' nb = CInt(Mid(f, Len(f) - (Len(suffix) + 3), 3)) +' If nb > mx Then mx = nb +' f = Dir$ +' Loop +' mx = mx + 1 + +' t=Left(prefix,InStrRev(prefix,"\")) +' mkdirs("C:\cache"+Right(t,Len(t)-2)) +' f = Dir$("C:\cache"+Right(prefix,Len(prefix)-2) + "_*." + suffix) +' mx2 = 0 +' Do While f <> "" +' nb = CInt(Mid(f, Len(f) - (Len(suffix) + 3), 3)) +' If nb > mx2 Then mx2 = nb +' f = Dir$ +' Loop +' mx2 = mx2 + 1 + +' If mx2 > mx Then mx=mx2 + +' find_next_file = prefix + "_" + Format(mx, "000") + "." + suffix +'End Function + +Function find_next_file(prefix As String, suffix As String) + f = Dir$(prefix + "_*." + suffix) + mx = 0 + Do While f <> "" + 'nb = CInt(Mid(f, Len(f) - (Len(suffix) + 3), 3)) + nb= CInt( Mid( Right ( f, Len(f) - InStr(f,"_") ), 1, 3 ) ) ' Changed by Loic in case of problem comment this line and uncomment the line up + If nb > mx Then mx = nb + f = Dir$ + Loop + mx = mx + 1 + + t=Left(prefix,InStrRev(prefix,"\")) + mkdirs("C:\cache"+Right(t,Len(t)-2)) + f = Dir$("C:\cache"+Right(prefix,Len(prefix)-2) + "_*." + suffix) + mx2 = 0 + Do While f <> "" + 'nb = CInt(Mid(f, Len(f) - (Len(suffix) + 3), 3)) + nb= CInt( Mid( Right ( f, Len(f) - InStr(f,"_") ), 1, 3 ) ) ' Changed by Loic in case of problem comment this line and uncomment the line up + If nb > mx2 Then mx2 = nb + f = Dir$ + Loop + mx2 = mx2 + 1 + + If mx2 > mx Then mx=mx2 + + autonum=CInt(mx) + + find_next_file = prefix + "_" + Format(mx, "000") + "." + suffix +End Function + +Sub imageinfo(inftxt As String) +Rem save infos of beamline in image +Rem I:E photonenergy scan +Rem I:S startvoltage scan (photoemission) +Rem I:M "manual" scan +Rem I:O objective scan +Rem I:I single image +Rem I:T time resovled + IpWsChangeDescription(INF_TITLE,"E:"+Format(setEnergy,"0.000")+" P:"+Polstring(pol)+" "+linrotstring+" I:"+inftxt) + IpWsChangeDescription(INF_DESCRIPTION,"Polarisation "+Polarisationstring) + IpWsChangeDescription(INF_Artist,"SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0")) +End Sub + +Function SelectImage_X11MA(message As String, Image1 As Integer) As Boolean +Rem ask user to select one image with message, returns true if successful +Dim pt As pointapi + selectImage_X11MA = False + Image1 = IpDocClick(message+" select",pt) + If Image1 < 0 Then Exit Function + selectImage_X11MA = True +End Function + +Function Select2Images_X11MA(Image1 As Integer, Image2 As Integer) As Boolean +Rem Asks user to select two images +Rem Returns True if successful +Dim pt As pointapi + Select2Images_X11MA = False + Image1 = IpDocClick("Select first image", pt) + If Image1 < 0 Then Exit Function + Image2 = IpDocClick("Select second image", pt) + If Image2 < 0 Then Exit Function + Select2Images_X11MA = True +End Function + +Function Divide2Images(ByVal Image1 As Integer, ByVal Image2 As Integer, ByVal Scale As Single, ByVal Enhance As Single, ByVal DoFlatten As Boolean) As Integer +Rem Divides Image1 / Image2 (*Gray), scales Image1 by Scale or autoscales if Scale = 0.0, +Rem Enhances contrast by Enhance, flattens if DoFLatten = True +Rem Returns ID +Dim tmp As Integer +Dim Gray As Single + tmp = ScaleImage(Image1, Image2, Scale, True) + Gray = (GetWhiteValue(Image2) + 1) / 2 + ret = IpOpImageArithmetics(Image2, Gray, OPA_DIV, False) + 'If DoFlatten Then ret = Flatten(tmp, False) + ret = EnhanceImageContrast(tmp, Enhance, 0) + Divide2Images = tmp +End Function + +Function Add2Images(ByVal Image1 As Integer, ByVal Image2 As Integer, ByVal Scale As Single, ByVal Enhance As Single, ByVal DoFlatten As Boolean) As Integer +Dim tmp As Integer +Dim Gray As Single + tmp = IpOpNumberArithmetics(1.0, OPA_MULT, 1) + Gray = (GetWhiteValue(Image2) + 1) / 2 + ret = IpOpImageArithmetics(Image2, 0, OPA_ADD, False) + 'If DoFlatten Then ret = Flatten(tmp, False) + ret = IpAppSelectDoc(tmp) + Add2Images = tmp +End Function + +Function Subtract2Images(ByVal Image1 As Integer, ByVal Image2 As Integer, ByVal Scale As Single, ByVal Enhance As Single, ByVal DoFlatten As Boolean) As Integer +Rem Subtracts Image1 - Image2 (+Gray), scales Image1 by Scale or autoscales if Scale = 0.0, +Rem Enhances contrast by Enhance +Rem Returns ID +Dim tmp As Integer +Dim Gray As Single + tmp = ScaleImage(Image1, Image2, Scale, True) + Gray = (GetWhiteValue(Image2) + 1) / 2 + ret = IpOpImageArithmetics(Image2, Gray, OPA_SUB, False) + 'If DoFlatten Then ret = Flatten(tmp, False) + ret = EnhanceImageContrast(tmp, Enhance, 0) + Subtract2Images = tmp +End Function + +Function Subtract2ImagesNoGray(ByVal Image1 As Integer, ByVal Image2 As Integer, ByVal Scale As Single, ByVal Enhance As Single, ByVal DoFlatten As Boolean) As Integer +Rem Subtracts Image1 - Image2 scales Image1 by Scale or autoscales if Scale = 0.0, +Rem Enhances contrast by Enhance +Rem Returns ID +Dim tmp As Integer +Dim Gray As Single + tmp = ScaleImage(Image1, Image2, Scale, True) + ret = IpOpImageArithmetics(Image2, 0, OPA_SUB, False) + 'If DoFlatten Then ret = Flatten(tmp, False) + ret = EnhanceImageContrast(tmp, Enhance, 0) + Subtract2ImagesNoGray = tmp +End Function + +Function ScaleImage(ByVal Image As Integer, ByVal Reference As Integer, ByVal Scale As Single, ByVal New_Image As Boolean) As Integer +Rem Scales Image to same brightness as Reference if Scale < 0.01 and Reference >= 0, else uses fixed value Scale +Rem Creates new image if New_Image = True +Rem Returns ID +ReDim stats(10) As Single + If (Scale < 0.0001) And (Reference >= 0) Then + ret = IpAppSelectDoc(Reference) + ret = IpHstCreate() + ret = IpHstGet(GETSTATS, 0, stats(0)) + ret = IpHstDestroy() + Scale = stats(2) / ((GetWhiteValue(Reference) + 1) / 2) + ret = IpAppSelectDoc(Image) + ret = IpHstCreate() + ret = IpHstGet(GETSTATS, 0, stats(0)) + ret = IpHstDestroy() + Scale = Scale / (stats(2) / ((GetWhiteValue(Image) + 1) / 2)) + Else + ret = IpAppSelectDoc(Image) + End If + ScaleImage = IpOpNumberArithmetics(Scale, OPA_MULT, New_Image) +End Function + +Function Asymmetry2Images(ByVal Image1 As Integer, ByVal Image2 As Integer, ByVal Scale As Single, ByVal Enhance As Single, ByVal DoFlatten As Boolean) As Integer +Rem Calculates asymmetry (Image1-Image2+Gray)/(Image1+Image2-Gray), scales Image1 by Scale or autoscales if Scale = 0.0, +Rem Enhances contrast by Enhance, flattens if DoFLatten = True +Rem Returns ID +Dim tmp1 As Integer +Dim tmp2 As Integer +Dim tmp3 As Integer +Dim range(2) As Single +Dim Info As IPDOCINFO + ret = IpDocGet(GETDOCINFO, Image1, Info) + tmp2 = ScaleImage(Image1, Image2, Scale, True) + tmp1 = IpWsConvertImage(IMC_FLOAT, CONV_DIRECT, 0, 0, 0, 0) + CloseImage(tmp2) + ret = IpAppSelectDoc(Image2) + tmp2 = IpWsConvertImage(IMC_FLOAT, CONV_DIRECT, 0, 0, 0, 0) + + tmp3 = IpOpImageArithmetics(tmp1, 0, OPA_ADD, True) + ret = IpAppSelectDoc(tmp1) + tmp1 = IpOpImageArithmetics(tmp2, 0, OPA_SUB, False) + tmp1 = IpOpImageArithmetics(tmp3, 100*Enhance, OPA_DIV, False) + + CloseImage(tmp2) + CloseImage(tmp3) + range(0)=-100 + range(1)=100 + IpDrSet(DR_FRANGE, 1, range(0)) + tmp2 = IpWsConvertImage(Info.Class, CONV_SCALE, 0, 0, 0, 0) + If DoFlatten Then ret = Flatten(tmp2, False) + CloseImage(tmp1) + Asymmetry2Images = tmp2 +End Function + +Function EnhanceImageContrast(ByVal Image As Integer, ByVal Factor As Single, ByVal New_Image As Boolean) As Integer +Rem Enhances contrast of Image by Factor +Rem Creates new image if New_Image = True +Rem Returns ID +Dim Gray As Single +ReDim stats(10) As Single + If (Factor > 0.01) And (Factor < 100) Then + ret = IpAppSelectDoc(Image) + Gray = (GetWhiteValue(Image) + 1) / 2 + ret = IpHstGet(GETSTATS, 0, stats(0)) + ret = IpHstDestroy() + IpOpNumberArithmetics(Gray-stats(0), OPA_ADD, 0) + If Factor >= 1.0 Then + EnhanceImageContrast = IpOpNumberArithmetics(Gray * (1.0 - 1.0/Factor), OPA_SUB, New_Image) + ret = IpOpNumberArithmetics(Factor, OPA_MULT, 0) + Else + ret = IpOpNumberArithmetics(Factor, OPA_MULT, 0) + EnhanceImageContrast = IpOpNumberArithmetics(Gray * (1.0 - Factor), OPA_Add, New_Image) + End If + Else + EnhanceImageContrast = -1 + End If +End Function + +Function GetWhiteValue(Image As Integer) As Single +Rem Returns pixel value corresponding to White for Image +Dim Info As IPDOCINFO + ret = IpDocGet(GETDOCINFO, Image, Info) + If Info.Class = IMC_GRAY16 Then + GetWhiteValue = 65535.0 + ElseIf Info.Class = IMC_GRAY12 Then + GetWhiteValue = 4095.0 + Else + GetWhiteValue = 255.0 + End If +End Function + +Function definescan(lolimit As Integer, uplimit As Integer) As Boolean +Rem ask user for the region of the scan, returns True when done +Dim doneinput As Boolean + + definescan = True + loadX11MAstack + + Do + 'define scan + Begin Dialog UserDialog 1000,100,390,320,"define spectrum" ' %GRID:10,8,1,1 + + Text 220,0,60,16,"Step",.Text3 + TextBox 120,16,90,16,.energy1 + TextBox 120,40,90,16,.energy2 + TextBox 120,64,90,16,.energy3 + TextBox 120,88,90,16,.energy4 + TextBox 120,112,90,16,.energy5 + TextBox 120,136,90,16,.energy6 + TextBox 120,160,90,16,.energy7 + TextBox 120,184,90,16,.energy8 + TextBox 120,208,90,16,.energy9 + TextBox 120,232,90,16,.energy10 + TextBox 220,24,60,16,.Step1 + TextBox 220,56,60,16,.Step2 + TextBox 220,80,60,16,.Step3 + TextBox 220,104,60,16,.Step4 + TextBox 220,128,60,16,.Step5 + TextBox 220,152,60,16,.Step6 + TextBox 220,176,60,16,.Step7 + TextBox 220,200,60,16,.Step8 + TextBox 220,224,60,16,.Step9 + CheckBox 290,24,90,16,CheckBox1,.CheckBox1 + CheckBox 290,56,90,16,CheckBox2,.CheckBox2 + CheckBox 290,80,90,16,CheckBox3,.CheckBox3 + CheckBox 290,104,90,16,CheckBox4,.CheckBox4 + CheckBox 290,128,90,16,CheckBox5,.CheckBox5 + CheckBox 290,152,90,16,CheckBox6,.CheckBox6 + CheckBox 290,176,90,16,CheckBox7,.CheckBox7 + CheckBox 290,200,90,16,CheckBox8,.CheckBox8 + CheckBox 290,224,90,16,CheckBox9,.CheckBox9 + Text 290,0,80,16,"Click to use",.Text1 + Text 130,0,80,16,"Energy",.Text2 + PushButton 380,312,10,8,"enterkey",.PushButton1 + OKButton 130,288,90,24 + CancelButton 250,288,90,24 + PushButton 90,256,100,24,"load setings",.PushButton2 + PushButton 220,256,90,24,"save settings",.PushButton3 + + + End Dialog + Dim dlg As UserDialog + + dlg.energy1=Format(energym(1)) + dlg.energy2=Format(energym(2)) + dlg.energy3=Format(energym(3)) + dlg.energy4=Format(energym(4)) + dlg.energy5=Format(energym(5)) + dlg.energy6=Format(energym(6)) + dlg.energy7=Format(energym(7)) + dlg.energy8=Format(energym(8)) + dlg.energy9=Format(energym(9)) + dlg.energy10=Format(energym(10)) + + dlg.step1=Format(estepm(1)) + dlg.step2=Format(estepm(2)) + dlg.step3=Format(estepm(3)) + dlg.step4=Format(estepm(4)) + dlg.step5=Format(estepm(5)) + dlg.step6=Format(estepm(6)) + dlg.step7=Format(estepm(7)) + dlg.step8=Format(estepm(8)) + dlg.step9=Format(estepm(9)) + + dlg.CheckBox1=Format(estepmCheck(1)) + dlg.CheckBox2=Format(estepmCheck(2)) + dlg.CheckBox3=Format(estepmCheck(3)) + dlg.CheckBox4=Format(estepmCheck(4)) + dlg.CheckBox5=Format(estepmCheck(5)) + dlg.CheckBox6=Format(estepmCheck(6)) + dlg.CheckBox7=Format(estepmCheck(7)) + dlg.CheckBox8=Format(estepmCheck(8)) + dlg.CheckBox9=Format(estepmCheck(9)) + + r=Dialog(dlg,1) + doneinput=True + If r = 0 Then + definescan=False + Exit Function + End If + + If r=1 Then + doneinput=False + End If + + ' "internal save" input + n=0 + n=n+string2double(dlg.energy1,energym(1)) + n=n+string2double(dlg.step1,estepm(1)) + estepmCheck(1)=CInt(dlg.CheckBox1) + n=n+string2double(dlg.energy2,energym(2)) + n=n+string2double(dlg.step2,estepm(2)) + estepmCheck(2)=CInt(dlg.CheckBox2) + n=n+string2double(dlg.energy3,energym(3)) + n=n+string2double(dlg.step3,estepm(3)) + estepmCheck(3)=CInt(dlg.CheckBox3) + n=n+string2double(dlg.energy4,energym(4)) + n=n+string2double(dlg.step4,estepm(4)) + estepmCheck(4)=CInt(dlg.CheckBox4) + n=n+string2double(dlg.energy5,energym(5)) + n=n+string2double(dlg.step5,estepm(5)) + estepmCheck(5)=CInt(dlg.CheckBox5) + n=n+string2double(dlg.energy6,energym(6)) + n=n+string2double(dlg.step6,estepm(6)) + estepmCheck(6)=CInt(dlg.CheckBox6) + n=n+string2double(dlg.energy7,energym(7)) + n=n+string2double(dlg.step7,estepm(7)) + estepmCheck(7)=CInt(dlg.CheckBox7) + n=n+string2double(dlg.energy8,energym(8)) + n=n+string2double(dlg.step8,estepm(8)) + estepmCheck(8)=CInt(dlg.CheckBox8) + n=n+string2double(dlg.energy9,energym(9)) + n=n+string2double(dlg.step9,estepm(9)) + estepmCheck(9)=CInt(dlg.CheckBox9) + n=n+string2double(dlg.energy10,energym(10)) + + If n<> 0 Then + Begin Dialog UserDialog 260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"type in numbers!",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror5 As UserDialog + Dialog scanerror5 + doneinput=False + End If + + If r = 2 Then + loadstackfile + doneinput=False + End If + + If r= 3 Then + savestackfile + doneinput=False + End If + + noregion = 0 + For i = 1 To 9 + If estepmCheck(i) = 1 Then + noregion=noregion+1 + 'If estepm(i)<=0 Then definescan=False + If energym(i)uplimit Then definescan=False + If energym(i+1)uplimit Then definescan=False + End If + Next i + + If noregion = 0 Then + Begin Dialog UserDialog 260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"No energy range selected",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror3 As UserDialog + Dialog scanerror3 + doneinput=False + End If + + If definescan = False Then + Begin Dialog UserDialog 260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"wrong energy or step size",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror4 As UserDialog + Dialog scanerror4 + doneinput=False + End If + Loop While doneinput=False + saveX11MAstack +End Function + +Function definescan_otf(lolimit As Integer, uplimit As Integer) As Boolean +Rem ask user for the region of the otf scan, returns True when done +Dim doneinput As Boolean + + definescan_otf = True + loadX11MAstack + + Do + 'define scan + Begin Dialog UserDialog 1000,100,390,112,"define spectrum" ' %GRID:10,8,1,1 + + Text 230,8,120,16,"Time (minutes)",.Text3 + TextBox 30,24,90,16,.energy1 + TextBox 130,24,90,16,.energy2 + TextBox 240,24,60,16,.Step1 + Text 30,8,80,16,"Start Energy",.Text2 + Text 130,8,80,16,"End Energy",.Text4 + PushButton 380,104,10,8,"enterkey",.PushButton1 + OKButton 140,88,90,24 + CancelButton 240,88,90,24 + PushButton 90,56,100,24,"load setings",.PushButton2 + PushButton 210,56,90,24,"save settings",.PushButton3 + + + End Dialog + Dim dlg As UserDialog + + dlg.energy1=Format(energym(1)) + dlg.energy2=Format(energym(2)) + + dlg.step1=Format(estepm(1)) + + r=Dialog(dlg,1) + doneinput=True + If r = 0 Then + definescan_otf=False + Exit Function + End If + + If r=1 Then + doneinput=False + End If + + ' "internal save" input + n=0 + n=n+string2double(dlg.energy1,energym(1)) + n=n+string2double(dlg.step1,estepm(1)) + n=n+string2double(dlg.energy2,energym(2)) + + If n<> 0 Then + Begin Dialog UserDialog 260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"type in numbers!",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror5 As UserDialog + Dialog scanerror5 + doneinput=False + End If + + If r = 2 Then + loadstackfile + doneinput=False + End If + + If r= 3 Then + savestackfile + doneinput=False + End If + + noregion = 1 + If estepm(1)<=0 Then definescan_otf=False + If energym(1)uplimit Then definescan_otf=False + If energym(2)uplimit Then definescan_otf=False + + If definescan_otf = False Then + Begin Dialog UserDialog 260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"wrong energy or step size",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror4 As UserDialog + Dialog scanerror4 + doneinput=False + End If + Loop While doneinput=False + saveX11MAstack +End Function + +Function ExpandName(s As String, n As Integer, ext As String) As String +Rem Expands filename s with number n and extension ext and adds ".TIF" +Rem Returns new filename +Dim t As String + t = s + If n<10 Then + t = t + "00" + Else + If n<100 Then t = t + "0" + End If + ExpandName = t + Mid$(Str$(n),2) + ext + ".TIF" +End Function + +Function FileExists(f As String) As Boolean +Rem Tests whether filename f already exists +Rem Returns True if f exists +Dim p As String +Dim n As String +Dim x As Integer +Dim Iname As String * 255 +Dim i As Integer + x = 0 + i = InStrRev(f, "\") + p = Left(f, i) + n = Mid(f, i+1) + FileExists = IpStSearchDir(p, n, x, Iname) +End Function + +Sub ini_switchID + + ID1os=getID1offset + ID2os=getID2offset + + If ID1os=ID1offset Then activeID=1 Else activeID=2 + + PHS_mode(3) + +End Sub + +Sub switchID + + If activeID = 1 Then + Rem detuneID1 + putID1offset(ID1offset-40) + Rem tuneID2 + putID2offset(ID2offset) + activeID=2 + Else + Rem detuneID2 + putID2offset(ID2offset-40) + Rem tuneID1 + putID1offset(ID1offset) + activeID=1 + End If + +End Sub +Function nextpol As Single + Select Case polswitchmode + Case 1 'Normal + If pol=1 Then nextpol=2 'circ+ -> circ- + If pol=2 Then nextpol=1 'circ+ -> circ- + If pol=3 Then nextpol=4 'lin hor -> lin vert + If pol=4 Then nextpol=3 'lin vert -> lin hor + If pol=5 Then nextpol=5 'lin rot -> lin rot + Case 2 'tune/detuned + If activeID=1 Then nextpol=polID2 + If activeID=2 Then nextpol=polID1 + End Select +End Function +Sub switchpol_new + +Dim newpol As Single +Dim v As Double +Dim chop As Double + + newpol=nextpol + + Select Case opID + Case 1 'ID1 only + putPolID1(newpol) + Case 2 'ID2 only + putPolID2(newpol) + Case 3 'ID1+ID2 + If polswitchmode=1 Then 'normal + putPolID1(newpol) + putPolID2(newpol) + End If + If polswitchmode = 2 Then 'tune/detuned + If activeID = 1 Then + Rem detuneID1 + putID1offset(ID1offset-40) + Rem tuneID2 + putID2offset(ID2offset) + activeID=2 + Else + Rem detuneID2 + putID2offset(ID2offset-40) + Rem tuneID1 + putID1offset(ID1offset) + activeID=1 + End If + End If + If polswitchmode = 3 Then 'chopper + If activeID = 1 Then + chop=1 + activeID = 2 + putChopper(chop) + Else + chop=0 + activeID = 1 + putChopper(chop) + End If + + End If + Case Else 'Error + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"go to config beamline",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror5 As UserDialog + Dialog scanerror5 + End Select + + sleep_f(1) +End Sub + +'Set all the ID's in use in detuned mode +Sub set_IDs_in_detune + Select Case opID + Case 1 'ID1 only + putID1offset(ID1offset-40) + Case 2 'ID2 only + putID2offset(ID2offset-40) + Case 3 'ID1+ID2 + If polswitchmode=1 Then 'normal + putID1shift(0) + putID2shift(0) + Else 'tune/detuned + If activeID = 1 Then + putID1offset(ID1offset-40) + Else + putID2offset(ID2offset-40) + End If + End If + + End Select + + sleep_f(1) +End Sub + +Sub correct_sensi +Dim image1 As Integer +Dim image2 As Integer + If selectImage_X11MA("select image",image1) Then + IpWsLoad(sensi_image, "TIF") + ret = IpDocGet(GETACTDOC, 0, Image2) + ret=Divide2Images(image1,image2,0,1,False) + ret=IpDocCloseEx(Image2) + End If +End Sub + +Sub config_beamline +Dim ListopID(4) As String +Dim Listswitchmode(3) As String +Dim ListactiveID(3) As String +Dim Listharmonic(5) As String +Dim doneinput As Boolean + + ListopID(1)="ID1" + ListopID(2)="ID2" + ListopID(3)="ID1+ID2" + ListopID(4)="open gap" + + Listswitchmode(1)="Normal" + Listswitchmode(2)="tune/detune" + Listswitchmode(3)="chopper" + + ListactiveID(1)="ID1" + ListactiveID(2)="ID2" + ListactiveID(3)="ID1+ID2" + + Listharmonic(1)="1" + Listharmonic(3)="3" + + loadX11MA_PEEMconfig + getbeamline + + Do + Begin Dialog UserDialog 800,100,830,238,"config_beamline" ' %GRID:10,7,1,1 + OKButton 80,203,90,21 + CancelButton 190,203,90,21 + Text 390,210,70,14,"offset ID1",.Text1 + TextBox 470,203,90,21,.ID1offset + Text 610,210,70,14,"offset ID2",.Text2 + TextBox 690,203,90,21,.ID2offset + ComboBox 80,21,90,70,ListopID(),.ListopID + Text 30,21,50,14,"use ID:",.Text3 + Text 220,21,70,14,"switching mode:",.Text4 + ComboBox 290,21,90,70,Listswitchmode(),.Listswitchmode + Text 430,21,50,14,"ID1:",.Text5 + ComboBox 480,21,90,70,Polstring(),.PolID1 + Text 650,21,30,14,"ID2:",.Text6 + ComboBox 690,21,90,70,Polstring(),.PolID2 + TextBox 480,91,90,21,.ID1alpha + TextBox 690,91,90,21,.ID2alpha + Text 410,91,70,14,"Alpha ID1",.Text7 + Text 610,91,70,14,"Alpha ID2",.Text8 + ComboBox 480,119,90,70,Listharmonic(),.harmonicID1 + ComboBox 690,119,90,70,Listharmonic(),.harmonicID2 + Text 380,126,90,14,"harmonic ID1",.Text9 + Text 600,119,90,14,"harmonic ID2",.Text10 + 'ListBox 480,91,90,56,linrotstringID1(),.linrotID1 + 'ListBox 670,91,90,56,linrotstringID2(),.linrotID2 + End Dialog + + Dim dlg As UserDialog + dlg.ID1offset=Format(ID1offset) + dlg.ID2offset=Format(ID2offset) + dlg.ListopID=ListopID(opID) + dlg.Listswitchmode=Listswitchmode(polswitchmode) + dlg.PolID1=Polstring(polID1) + dlg.PolID2=Polstring(polID2) + dlg.ID1alpha=Format(ID1alpha) + dlg.ID2alpha=Format(ID2alpha) + dlg.harmonicID1=Format(getID1harmonic) + dlg.harmonicID2=Format(getID2harmonic) + + + If JobsRunning=False Then + r=Dialog(dlg) + Else + r=-1 + + dlg.ListopID = Jobs(Current_job,2) + dlg.Listswitchmode = Jobs(Current_job,3) + dlg.PolID1 = Jobs(Current_job,4) + dlg.PolID2 = Jobs(Current_job,5) + dlg.ID1alpha = Jobs(Current_job,6) + dlg.ID2alpha = Jobs(Current_job,7) + dlg.ID1offset = Jobs(Current_job,8) + dlg.ID2offset = Jobs(Current_job,9) + dlg.harmonicID1 = Jobs(Current_job,10) + dlg.harmonicID2 = Jobs(Current_job,11) + + End If + + If r=0 Then + stopMacro + Exit Sub + End If + + ID1offset=CDbl(dlg.ID1offset) + ID2offset=CDbl(dlg.ID2offset) + ID1alpha=CDbl(dlg.ID1alpha) + ID2alpha=CDbl(dlg.ID2alpha) + + Rem find new harmonic + For i = 1 To 5 + If dlg.harmonicID1=Listharmonic(i) Then ID1harmonic = i + If dlg.harmonicID2=Listharmonic(i) Then ID2harmonic = i + Next i + + Rem set harmonic + putID1harmonic(ID1harmonic) + putID2harmonic(ID2harmonic) + + If r=-1 Then + doneinput=True + End If + + ' putIDmotors(0) 'off + + For i=1 To 5 + If dlg.PolID1=Polstring(i) Then putpolID1(i) + sleep_f(1) + If dlg.PolID2=Polstring(i) Then putpolID2(i) + sleep_f(1) + Next i + + 'sleep(2) + Rem ID1 as active ID + If dlg.ListopID=ListopID(1) Then + PHS_mode(1) + sleep_f(1) + activeID=1 + opID=1 + polswitchmode=1 + putID2offset(ID2offset) + sleep_f(1) + putID1offset(ID1offset) + sleep(1) + Rem set harmonic + putID1harmonic(ID1harmonic) + opengapID2 + End If + + Rem ID2 as active ID + If dlg.ListopID=ListopID(2) Then + PHS_mode(2) + sleep_f(1) + activeID=2 + opID=2 + polswitchmode=1 + putID2offset(ID2offset) + sleep_f(1) + putID1offset(ID1offset) + sleep(1) + Rem set harmonic + putID2harmonic(ID2harmonic) + opengapID1 + End If + + Rem ID1+ID2 as active IDs + If dlg.ListopID=ListopID(3) Then + PHS_mode(3) + sleep_f(1) + activeID=3 + opID=3 + polswitchmode=1 + putID2offset(ID2offset) + sleep_f(1) + putID1offset(ID1offset) + sleep_f(1) + Rem set harmonic + putID1harmonic(ID1harmonic) + putID2harmonic(ID2harmonic) + End If + + Rem open gaps + If dlg.ListopID=ListopID(4) Then + ' putIDmotors(2) + opengapID1 + sleep_f(1) + opengapID2 + stopmacro + write_logfile(0,"open gaps") + Exit Sub + End If + + 'sleep(5) + + Rem normal switching + If dlg.Listswitchmode=Listswitchmode(1) Then + polswitchmode=1 + End If + + Rem tune/detune switching + If dlg.Listswitchmode=Listswitchmode(2) Then + polswitchmode=2 + activeID = 1 + opID=3 + putID2offset(ID2offset-40) + sleep_f(1) + putID1offset(ID1offset) + End If + + Rem chopper + If dlg.Listswitchmode=Listswitchmode(3) Then + polswitchmode=3 + activeID = 1 + opID=3 + putID2offset(ID2offset) + sleep_f(1) + putID1offset(ID1offset) + End If + + 'putlinrotmodeID1(0) + 'putlinrotmodeID2(0) + + Rem linear rot mode ID1 + If dlg.PolID1=Polstring(5) And opID=1 Then + 'putpolID1(3) 'set to linear mode for feedforward table + putpolID1(5) 'set to linear mode for feedforward table + sleep(3) + 'putID1alpha(ID1alpha) + 'PHS_mode(0) + opID=1 + activeID =1 + 'putlinrotmodeID1(dlg.linrotID1+1) + 'linrotID1=dlg.linrotID1 + 'If setEnergy=0 Then setEnergy=rbkEnergy + 'putlinrotID1(setEnergy) + putID1offset(ID1_linrot_offset(ID1alpha)) + End If + + Rem linear rot mode ID2 + If dlg.PolID2=Polstring(5) And opID=2 Then + 'putpolID2(3) 'set to linear mode for feedforward table + putpolID2(5) 'set to linear mode for feedforward table + sleep(3) + 'putID2alpha(ID2alpha) + 'PHS_mode(0) + opID=2 + activeID =2 + 'putlinrotmodeID2(dlg.linrotID2+1) + 'linrotID1=dlg.linrotID1 + 'If setEnergy=0 Then setEnergy=rbkEnergy + 'putlinrotID2(setEnergy) + putID2offset(ID2_linrot_offset(ID2alpha)) + End If + + Rem linear rot mode ID1+ID2 + If dlg.PolID1=Polstring(5) And dlg.PolID2=Polstring(5) Then + 'putpolID1(3) 'set to linear mode for feedforward table + putpolID1(5) 'set to linear mode for feedforward table + sleep(3) + 'putID1alpha(ID1alpha) + 'PHS_mode(0) + opID=3 + activeID =3 + 'putlinrotmodeID1(dlg.linrotID1+1) + 'linrotID1=dlg.linrotID1 + 'If setEnergy=0 Then setEnergy=rbkEnergy + 'putlinrotID1(setEnergy) + putID1offset(ID1_linrot_offset(ID1alpha)) + 'putpolID2(3) 'set to linear mode for feedforward table + putpolID2(5) 'set to linear mode for feedforward table + sleep(3) + 'putID2alpha(ID2alpha) + 'PHS_mode(0) + 'putlinrotmodeID2(dlg.linrotID2+1) + 'linrotID1=dlg.linrotID1 + 'If setEnergy=0 Then setEnergy=rbkEnergy + 'putlinrotID2(setEnergy) + putID2offset(ID2_linrot_offset(ID2alpha)) + End If + + + If dlg.ListopID="" Or dlg.Listswitchmode="" Then + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"Select mode and ID",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror3 As UserDialog + Dialog scanerror3 + doneinput=False + End If + + Loop While doneinput=False + ' putIDmotors(2) 'auto + saveX11MA_PEEMconfig + + Rem write logfile + getbeamline + write_logfile(0,"activeID :"+CStr(activeID)+" Polarization :"+Polstring(pol)+" "+linrotstring+" IDswitching :"+switchstring(polswitchmode)) + +End Sub + +Sub config_measure +Dim ListKeithleyMode(10) As String +Dim ListKeithleyNo(5) As String +Dim ListKeithley_set_mode(10) As String + + ListKeithleyMode(0) = "use GBIP, without injection test, no average of energy readback" + ListKeithleyMode(1) = "use GBIP, pause while injection, no average of energy readback" + ListKeithleyMode(2) = "use GBIP, without injection test, average of energy readback" + ListKeithleyMode(3) = "use A/D, without injection test, no average of energy readback" + ListKeithleyMode(4) = "use A/D, without injection test, average of energy readback" + ListKeithleyMode(5) = "use A/D, pause while injection, average of energy readback" + ListKeithleyMode(6) = "use A/D, pause while injection, no average of energy readback" + ListKeithleyMode(7) = "trigger Keithley extern, injection test" + ListKeithleyMode(8) = "trigger analog ADC, injection test, no average of energy readback" + + ListKeithleyNo(0) = "Keithely1" + ListKeithleyNo(1) = "Keithely2" + ListKeithleyNo(2) = "Keithely1+2+norm" + ListKeithleyNo(3) = "Keithely1+2+3" + ListKeithleyNo(4) = "Keithely1+2+norm+4Analog" + + ListKeithley_set_mode(0) = "def setting" + ListKeithley_set_mode(1) = "pull curr fast" + ListKeithley_set_mode(2) = "pull curr medi" + ListKeithley_set_mode(3) = "pull curr slow" + ListKeithley_set_mode(4) = "trig setting" + ListKeithley_set_mode(5) = "trigger extern" + ListKeithley_set_mode(6) = "trigger TLIN" + ListKeithley_set_mode(7) = "trigger BUS" + ListKeithley_set_mode(8) = "pol volt medi" + ListKeithley_set_mode(9) = "not running" + + + loadX11MA_PEEMconfig + getbeamline + + Do + Begin Dialog UserDialog 800,100,970,189,"config_measure" ' %GRID:10,7,1,1 + ListBox 140,14,480,70,ListKeithleyMode(),.KeithleyMode + Text 30,14,90,14,"Keithley Mode",.Text1 + Text 110,105,130,14,"no of reading",.Text2 + Text 90,126,140,14,"(10 about 1 sec)",.Text3 + TextBox 250,105,90,21,.noint + OKButton 400,147,90,21 + CancelButton 520,147,90,21 + CheckBox 400,91,270,14,"Check beamline status",.do_checkbeamline + CheckBox 400,112,160,14,"Check ring status",.do_checkring + ListBox 670,14,260,70,ListKeithleyNo(),.KeithleyNo + Text 140,154,90,14,"Integration time ADC",.Text4 + TextBox 250,147,90,21,.noADC + TextBox 790,98,130,21,.Keithley1_set + TextBox 790,126,130,21,.Keithley2_set + TextBox 790,154,130,21,.Keithley3_set + Text 720,105,60,14,"Keithley1",.Text5 + Text 720,133,60,14,"Keithley2",.Text6 + Text 720,154,60,14,"Keithley3",.Text7 + + End Dialog + + Dim dlg As UserDialog + dlg.noint=Format(noint) + dlg.noADC=Format(noADC) + dlg.KeithleyMode=KeithleyMode + dlg.KeithleyNo=KeithleyNo + dlg.Keithley1_set=ListKeithley_set_mode(get_keithley1_mode) + dlg.Keithley2_set=ListKeithley_set_mode(get_keithley2_mode) + dlg.Keithley3_set=ListKeithley_set_mode(get_keithley3_mode) + dlg.do_checkbeamline=do_checkbeamline + dlg.do_checkring=do_checkring + + r=Dialog(dlg) + If r=0 Then + stopMacro + Exit Sub + End If + + If r=-1 Then + doneinput=True + End If + + noint=CInt(dlg.noint) + KeithleyMode=CInt(dlg.KeithleyMode) + KeithleyNo=CInt(dlg.KeithleyNo) + do_checkbeamline=CInt(dlg.do_checkbeamline) + do_checkring=CInt(dlg.do_checkring) + noADC=CInt(dlg.noADC) + + Rem put integration time to ADC + putADC_integration(noADC) + + Loop While doneinput=False + saveX11MA_PEEMconfig +End Sub + +Function string2double(ByRef n As String, ByRef d As Double) As Integer +Rem returns 0 if okay, 1 if error + + On Error GoTo nostring + d=CDbl(n) + + GoTo yesString + + nostring: + string2double=1 + GoTo done + + yesstring: + string2double=0 + + done: + On Error GoTo 0 + +End Function + +Function string2long(ByRef n As String, ByRef d As Long) As Integer +Rem returns 0 if okay, 1 if error + + On Error GoTo nostring + d=CDbl(n) + + GoTo yesString + + nostring: + string2long=1 + GoTo done + + yesstring: + string2long=0 + + done: + On Error GoTo 0 + +End Function + +Sub wronginput + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"type in numbers!",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror5 As UserDialog + Dialog scanerror5 +End Sub + +Sub wrongvalue + Begin Dialog UserDialog 1000,100,260,77 ' %GRID:10,7,1,1 + Text 50,7,170,21,"value out of range",.Text1 + OKButton 70,35,110,21 + End Dialog + Dim scanerror3 As UserDialog + Dialog scanerror3 +End Sub + +Function date2name As String +Dim n As String + n="" + n=Format(Date,"yy") + n=n+Format(Date,"mm") + n=n+Format(Date,"dd") + date2name=n +End Function + +Function averKeithley(t As Integer,ByRef Keithley1 As Double,ByRef Keithley2 As Double,ByRef Keithleynorm As Double) As Integer +Rem 1: okay +Rem 2: injection + +Dim Keithley(3) As Double +Dim Analog(4) As Double +'Dim Injection_test As Single +Dim rEnergy As Double + + 'KeithleyMode = 0 ' use GBIP non test + 'KeithleyMode = 1 'use GBIP break while injection + 'KeithleyMode = 2 ' use GBIP, without injection test, user energy readback + 'KeithleyMode = 3 ' use A/D signal no injection test + 'KeithleyMode = 4 ' use A/D signal without injection test, use energy readback + 'KeithleyMode = 5 ' use A/D signal with injection test, use energy readback + 'KeithleyMode = 6 ' use A/D signal with injection test, no average of energy + 'KeithleyMode = 7 ' new hardware trigger + 'KeithleyMode = 8 ' new trigger for analog + + 'KeithleyNo = 0 ' read Keithley1 + 'KeithleyNo = 1 ' read Keithley2 + 'KeithleyNo = 2 ' read Keithley1+2+Norm this is the default + 'KeithleyNo = 3 ' read Keithley1+2+3 + 'KeithleyNo = 4 ' read Keithley1+2+Norm + 4 analog only in XFMR + + Rem one empty read due to keithley bufferproblem + 'keithley_read(2,keithley(1),keithley(2),keithley(3)) + + Select Case KeithleyMode + + Case 0 + Rem one empty read due to keithley bufferproblem + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley=1 + avrbkenergy=getEnergy + + Case 1 + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Else + addKeyVal "Status","injection" + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + i=0 + averKeithley=2 + addKeyVal "Status","measuring" + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley=1 + avrbkenergy=getEnergy + Case 2 + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + rEnergy=rEnergy+getEnergy + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + avrbkenergy=rEnergy/t + averKeithley=1 + Case 3 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + sleep_f(1) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley=1 + avrbkenergy=getEnergy + Case 4 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + rEnergy=rEnergy+getEnergy + sleep_f(1) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + avrbkenergy=rEnergy/t + averKeithley=1 + + Case 5 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + rEnergy=rEnergy+getEnergy + sleep_f(1) + Else + addKeyVal "Status","injection" + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + rEnergy=0 + averKeithley=0 + i=0 + averKeithley=2 + addKeyVal "Status","measuring" + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + avrbkenergy=rEnergy/t + averKeithley=1 + + Case 6 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + sleep_f(1) + Else + addKeyVal "Status","injection" + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + i=0 + averKeithley=2 + addKeyVal "Status","measuring" + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley=1 + avrbkenergy=getEnergy + + Case 7 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + addKeyVal "Status","measuring" + + For i=1 To t + If injection() = 0 Then + Rem start trigger + keithley1_trigger_doinit + keithley2_trigger_doinit + sleep_f(2) + keithley1_new_trigger + 'keithley2_new_trigger + sleep_f(1) + + Rem wait for result + tstart=Int(Timer())+30 + Do While True + If cancelmacro() = 0 Then Exit Function + 'If injection()= 0 Then Exit Do + If keithley1_new_done = 0 And keithley2_new_done = 0 Then Exit Do + Rem timeout + tnow=Int(Timer()) + If tstart < tnow Then + write_logfile(1,"timeout Keithley at: "+Format(setEnergy)) + keithley2_new_trigger + 'keithley1_new_fetch + 'keithley2_new_fetch + Exit Do + End If + Loop + + Rem read keithley + sleep_f(2) + keithley_new_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + + Rem calculate + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Else + addKeyVal "Status","injection" + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_new_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + i=0 + averKeithley=2 + addKeyVal "Status","measuring" + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley=1 + avrbkenergy=getEnergy + + Case 8 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + For i=1 To t + 'If injection() = 0 Then + Rem start trigger + Do + addKeyVal "Status","measuring" + averKeithley=0 + keithley_analog_trigger + sleep_f(1) + + Rem wait for result + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 1 Then + averKeithley=2 + addKeyVal "Status","injection" + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + 'i=0 + sleep_f(5) + End If + If keithley_analog_done = 0 Then Exit Do + Loop + Loop While averKeithley=2 + + Rem read ADC signals + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + 'sleep_f(1) + 'Else + ' addKeyVal "Status","injection" + ' Rem signal for FMR that injection + ' putChopper(1) + ' Do While True + ' If cancelmacro() = 0 Then Exit Function + ' If injection()= 0 Then Exit Do + ' Loop + ' sleep_f(2) + ' keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + ' Keithley1=0.0 + ' Keithley2=0.0 + ' Keithleynorm=0.0 + ' Analog1=0.0 + ' Analog2=0.0 + ' Analog3=0.0 + ' Analog4=0.0 + ' averKeithley_XFMR=0 + ' i=0 + ' averKeithley_XFMR=2 + ' addKeyVal "Status","measuring" + ' Rem signal for FMR that injection done + ' putChopper(0) + 'End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + averKeithley=1 + avrbkenergy=getEnergy + + + End Select +End Function + +Function averKeithley_XFMR(t As Integer,ByRef Keithley1 As Double,ByRef Keithley2 As Double,ByRef Keithleynorm As Double, ByRef Analog1 As Double, ByRef Analog2 As Double, ByRef Analog3 As Double, ByRef Analog4 As Double) As Integer + +Rem 1: okay +Rem 2: injection + +Dim Keithley(3) As Double +Dim Analog(4) As Double + +'Dim Injection_test As Single +Dim rEnergy As Double + + 'KeithleyMode = 0 ' use GBIP non test + 'KeithleyMode = 1 'use GBIP break while injection + 'KeithleyMode = 2 ' use GBIP, without injection test, user energy readback + 'KeithleyMode = 3 ' use A/D signal no injection test + 'KeithleyMode = 4 ' use A/D signal without injection test, use energy readback + 'KeithleyMode = 5 ' use A/D signal with injection test, use energy readback + 'KeithleyMode = 6 ' use A/D signal with injection test, no average of energy + 'KeithleyMode = 7 ' new hardware trigger + 'KeithleyMode = 8 ' new trigger for analog + + 'KeithleyNo = 0 ' read Keithley1 + 'KeithleyNo = 1 ' read Keithley2 + 'KeithleyNo = 2 ' read Keithley1+2+Norm this is the default + 'KeithleyNo = 3 ' read Keithley1+2+3 + 'KeithleyNo = 4 ' read Keithley1+2+Norm + 4 analog only in XFMR + + Rem one empty read due to keithley bufferproblem + 'keithley_read(2,keithley(1),keithley(2),keithley(3)) + + Select Case KeithleyMode + + Case 0 + Rem one empty read due to keithley bufferproblem + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + + addKeyVal "Status","measuring" + For i=1 To t + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + + averKeithley_XFMR=1 + avrbkenergy=getEnergy + + Case 1 + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + Else + addKeyVal "Status","injection" + Rem signal for FMR that injection + putChopper(1) + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + averKeithley_XFMR=0 + i=0 + averKeithley_XFMR=2 + addKeyVal "Status","measuring" + Rem signal for FMR that injection stopped + putChopper(1) + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + averKeithley_XFMR=1 + avrbkenergy=getEnergy + Case 2 + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_read_XFMR(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + rEnergy=rEnergy+getEnergy + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + avrbkenergy=rEnergy/t + averKeithley_XFMR=1 + Case 3 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + sleep_f(1) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + averKeithley_XFMR=1 + avrbkenergy=getEnergy + Case 4 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + rEnergy=rEnergy+getEnergy + sleep_f(1) + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + avrbkenergy=rEnergy/t + averKeithley_XFMR=1 + + Case 5 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + rEnergy=0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + rEnergy=rEnergy+getEnergy + sleep_f(1) + Else + addKeyVal "Status","injection" + Rem signal for FMR that injection + putChopper(1) + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + rEnergy=0 + averKeithley_XFMR=0 + i=0 + averKeithley_XFMR=2 + addKeyVal "Status","measuring" + Rem signal for FMR that injection done + putChopper(0) + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + avrbkenergy=rEnergy/t + averKeithley_XFMR=1 + + Case 6 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + For i=1 To t + If injection() = 0 Then + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + sleep_f(1) + Else + addKeyVal "Status","injection" + Rem signal for FMR that injection + putChopper(1) + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + averKeithley_XFMR=0 + i=0 + averKeithley_XFMR=2 + addKeyVal "Status","measuring" + Rem signal for FMR that injection done + putChopper(0) + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + averKeithley_XFMR=1 + avrbkenergy=getEnergy + + Case 7 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + + For i=1 To t + If injection() = 0 Then + Rem start trigger + keithley1_trigger_doinit + keithley2_trigger_doinit + sleep_f(1) + keithley1_new_trigger + keithley2_new_trigger + sleep_f(1) + + Rem wait for result + Do While True + If cancelmacro() = 0 Then Exit Function + 'If injection()= 0 Then Exit Do + If keithley1_new_done = 0 And keithley2_new_done = 0 Then Exit Do + Loop + + Rem read keithley + keithley_new_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + + Rem calculate + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Else + addKeyVal "Status","injection" + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 0 Then Exit Do + Loop + sleep_f(2) + keithley_new_read(KeithleyNo,keithley(1),keithley(2),keithley(3)) + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + i=0 + averKeithley_XFMR=2 + addKeyVal "Status","measuring" + End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + averKeithley_XFMR=1 + avrbkenergy=getEnergy + + Case 8 + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + averKeithley_XFMR=0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + addKeyVal "Status","measuring" + For i=1 To t + 'If injection() = 0 Then + Rem start trigger + Do + addKeyVal "Status","measuring" + averKeithley_XFMR=0 + keithley_analog_trigger + sleep_f(1) + + Rem wait for result + Do While True + If cancelmacro() = 0 Then Exit Function + If injection()= 1 Then + averKeithley_XFMR=2 + addKeyVal "Status","injection" + Keithley1=0.0 + Keithley2=0.0 + Keithleynorm=0.0 + Analog1=0.0 + Analog2=0.0 + Analog3=0.0 + Analog4=0.0 + 'i=0 + sleep_f(5) + End If + If keithley_analog_done = 0 Then Exit Do + Loop + Loop While averKeithley_XFMR=2 + + Rem read ADC signals + keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + + Keithley1=Keithley1+keithley(1) + Keithley2=Keithley2+keithley(2) + Keithleynorm=Keithleynorm+keithley(3) + Analog1=Analog1+Analog(1) + Analog2=Analog2+Analog(2) + Analog3=Analog3+Analog(3) + Analog4=Analog4+Analog(4) + 'sleep_f(1) + 'Else + ' addKeyVal "Status","injection" + ' Rem signal for FMR that injection + ' putChopper(1) + ' Do While True + ' If cancelmacro() = 0 Then Exit Function + ' If injection()= 0 Then Exit Do + ' Loop + ' sleep_f(2) + ' keithley_analog(KeithleyNo,keithley(1),keithley(2),keithley(3), analog(1), analog(2), analog(3), analog(4)) + ' Keithley1=0.0 + ' Keithley2=0.0 + ' Keithleynorm=0.0 + ' Analog1=0.0 + ' Analog2=0.0 + ' Analog3=0.0 + ' Analog4=0.0 + ' averKeithley_XFMR=0 + ' i=0 + ' averKeithley_XFMR=2 + ' addKeyVal "Status","measuring" + ' Rem signal for FMR that injection done + ' putChopper(0) + 'End If + Next i + Keithley1=Keithley1/t + Keithley2=Keithley2/t + Keithleynorm=Keithleynorm/t + Analog1=Analog1/t + Analog2=Analog2/t + Analog3=Analog3/t + Analog4=Analog4/t + averKeithley_XFMR=1 + avrbkenergy=getEnergy + + End Select +End Function + +'Function averKeithley3(t As Integer,ByRef Keithley1 As Double,ByRef Keithley2 As Double,ByRef Keithleynorm As Double) As Integer +Rem 1: okay +Rem 2: injection +Rem read 3 Keithleys + + +'Dim Keithley(3) As Double +'Dim Injection_test As Single +'Dim rEnergy As Double + + 'KeithleyMode = 0 ' use GBIP non test + 'KeithleyMode = 1 'use GBIP break while injection + 'KeithleyMode = 2 ' use GBIP, without injection test, user energy readback + 'KeithleyMode = 3 ' use A/D signal no injection test + 'KeithleyMode = 4 ' use A/D signal without injection test, use energy readback + 'KeithleyMode = 5 ' use A/D signal with injection test, use energy readback + 'KeithleyMode = 6 ' use A/D signal with injection test, no average of energy + 'KeithleyMode = 7 ' new hardware trigger + + + Rem one empty read due to keithley bufferproblem + 'keithley_read(3,keithley(1),keithley(2),keithley(3)) + +' Select Case KeithleyMode + +' Case 0 +' Rem one empty read due to keithley bufferproblem +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' averKeithley3=1 +' avrbkenergy=getEnergy +' +' Case 1 +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' If injection() = 0 Then +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' Else +' addKeyVal "Status","injection" +' Do While True +' If cancelmacro() = 0 Then Exit Function +' If injection()= 0 Then Exit Do +' Loop +' sleep_f(2) +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' i=0 +' averKeithley3=2 +' addKeyVal "Status","measuring" +' End If +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' averKeithley3=1 +' avrbkenergy=getEnergy +' Case 2 +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' rEnergy=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' rEnergy=rEnergy+getEnergy +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' avrbkenergy=rEnergy/t +' averKeithley3=1 +' Case 3 +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' keithley_analog(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' sleep_f(1) +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' averKeithley3=1 +' avrbkenergy=getEnergy +' Case 4 +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' rEnergy=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' keithley_analog(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' rEnergy=rEnergy+getEnergy +' sleep_f(1) +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' avrbkenergy=rEnergy/t +' averKeithley3=1 +' +' Case 5 +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' rEnergy=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' If injection() = 0 Then +' keithley_analog(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' rEnergy=rEnergy+getEnergy +' sleep_f(1) +' Else +' addKeyVal "Status","injection" +' Do While True +' If cancelmacro() = 0 Then Exit Function +' If injection()= 0 Then Exit Do +' Loop +' sleep_f(2) +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' rEnergy=0 +' averKeithley3=0 +' i=0 +' averKeithley3=2 +' addKeyVal "Status","measuring" +' End If +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' avrbkenergy=rEnergy/t +' averKeithley3=1 +' +' Case 6 +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' addKeyVal "Status","measuring" +' For i=1 To t +' If injection() = 0 Then +' keithley_analog(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=Keithley1+keithley(1) +' Keithley2=Keithley2+keithley(2) +' Keithleynorm=Keithleynorm+keithley(3) +' sleep_f(1) +' Else +' addKeyVal "Status","injection" +' Do While True +' If cancelmacro() = 0 Then Exit Function +' If injection()= 0 Then Exit Do +' Loop +' sleep_f(2) +' keithley_read(3,keithley(1),keithley(2),keithley(3)) +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' i=0 +' averKeithley3=2 +' addKeyVal "Status","measuring" +' End If +' Next i +' Keithley1=Keithley1/t +' Keithley2=Keithley2/t +' Keithleynorm=Keithleynorm/t +' averKeithley3=1 +' avrbkenergy=getEnergy +' +' Case 7 +' Keithley1=0.0 +' Keithley2=0.0 +' Keithleynorm=0.0 +' averKeithley3=0 +' addKeyVal "Status","measuring" +' +' Rem start trigger +' put_keithley1_new_busy +' put_keithley2_new_busy +' keithley_new_trigger +' +' Rem wait for result +' Do While True +' If cancelmacro() = 0 Then Exit Function +' 'If injection()= 0 Then Exit Do +' If keithley1_new_done = 1 And keithley2_new_done Then Exit Do +' Loop +' +' Rem read keithley +' keithley_new_read(3,keithley(1),keithley(2),keithley(3)) +' +' Keithley1=keithley(1) +' Keithley2=keithley(2) +' Keithleynorm=Keithley1/Keithley2 +' averKeithley3=1 +' avrbkenergy=getEnergy +' +' End Select +'End Function + + +Sub AverageSeq() +Rem Calculates multiple images from image stack in selected areas AOI1, AOI2, ... + +Dim images As Integer +Dim anz As Integer + + + 'startMacro("average Sequenz") + 'LoadConfig + + ret = SelectImage_X11MA ("Select Sequence", images) + ret = IpSeqGet(SEQ_NUMFRAMES,anz) + ret = IPSeqAverage(0,anz) + 'stopMacro +End Sub + +Function AddSeq() As Integer +Rem adds the images of a sequence into on image +Dim tmp As Integer +Dim Image1 As Integer +Dim Image2 As Integer +Dim images As Integer +Dim anz As Integer + + Seq1 = SelectImage_X11MA ("Select Sequence", images) + ret = IpSeqGet(SEQ_NUMFRAMES,anz) + Image1 = IpSeqExtractFrames (0,1) + ret = IpAppSelectDoc(Image1) + For n = 0 To anz + ret = IpAppSelectDoc(Seq1) + Image2 = IpSeqExtractFrames (n,1) + ret = IpAppSelectDoc(Image1) + Image3 = IpOpImageArithmetics(Image2, 0, OPA_ADD, 1) + IpDocCloseEx(Image1) + IpDocCloseEx(Image2) + Image1=Image3 + Next n +End Function + +Function AddSeq_smart() As Integer +Rem adds the images of a sequence into one image until the max intensity is 2500, then into a next image etc +Dim tmp As Integer +Dim Image1 As Integer +Dim Image2 As Integer +Dim Image3 As Integer +Dim Image_result(100) As Integer +Dim images As Integer +Dim Seq1 As Integer +Dim anz As Integer +Dim max(10) As Single +Dim result As Integer + + result = 0 + Seq1 = SelectImage_X11MA ("Select Sequence", images) + ret = IpSeqGet(SEQ_NUMFRAMES,anz) + Image1 = IpSeqExtractFrames (0,1) + ret = IpAppSelectDoc(Image1) + For n = 0 To anz + ret = IpAppSelectDoc(Seq1) + Image2 = IpSeqExtractFrames (n,1) + ret = IpAppSelectDoc(Image1) + Image3 = IpOpImageArithmetics(Image2, 0, OPA_ADD, 1) + IpDocCloseEx(Image1) + IpDocCloseEx(Image2) + ret = IpAppSelectDoc(Image3) + IpHstCreate() + ret = IpHstGet(GETSTATS, 0, max(0)) + IpHstDestroy() + Image1=Image3 + If max(4) > 2500 Then + Image_Result(result)=Image1 + result=result + 1 + ret = IpAppSelectDoc(Seq1) + Image1 = IpSeqExtractFrames (n,1) + ret = IpAppSelectDoc(Image1) + n=n+1 + End If + Next n + Image_Result(result)=Image1 + For n = 0 To result-2 + ret = IpAppSelectDoc(Image_Result(n+1)) + ret = IpWsCopyFrames(0,1) + ret = IpDocCloseEx(Image_Result(n+1)) + ret = IpAppSelectDoc(Image_Result(0)) + ret = IpWsPasteFrames(-1) + Next n + ret = IpAppSelectDoc(Image_Result(0)) + ret = IpSeqGet(SEQ_NUMFRAMES,anz) + ret = IPSeqAverage(0,anz) + +End Function + +Sub CalcMultShiftsSeq() +Rem Calculates multiple images from image stack in selected areas AOI1, AOI2, ... +Dim n As Integer +Dim tmp As Integer +Dim refimage As Integer +Dim i As Integer +Dim ab As Integer +Dim Iname As String * 255 +Dim s As String +Dim t As String *255 +Dim ext As String +Dim r As RECT +Dim deltax As Integer +Dim deltay As Integer +Dim resultt As String +Dim anz As Integer +Dim Image As Integer + + +startMacro("CalcMultShifts") + +message ="Select Sequence uses active AOI" +Image = selectImage(message) +If Image <0 Then + Exit Sub +End If + + +ret = IpAoiManager(AOIADD,"RAOI") + +IpSeqGet (SEQ_NUMFRAMES, anz) +IpSeqSet (SEQ_ACTIVEFRAME, 0) + +IpAoiShow(FRAME_NONE) +IpSeqSet (SEQ_APPLY, 0) ' current frame +refimage = IpWsDuplicate() + +If refimage < 0 Then + Exit Sub +End If + + + +ret = IpStGetName("Save As",Path,"*.DAT", Iname) +If ret = 0 Then + Exit Sub +End If +t = Iname +i = InStr(1,t,".DAT") +If i = 0 Then t = t + ".DAT" +Open t For Output As #1 + +resultt = "0" + Chr(9) + "0" + Chr(9) + "0" +Print #1, resultt + +For i = 1 To (anz-1) + + IpAppSelectDoc(Image) + 'ret = IpAoiManager(AOISET,"AOI") + + IpSeqSet (SEQ_ACTIVEFRAME, i) + + IpAoiShow(FRAME_NONE) + IpSeqSet (SEQ_APPLY, 0) ' current frame + + + tmp = IpWsDuplicate() + + ret = FastAutoAlign(refimage, tmp, deltax, deltay, 1) + + + 'ret = FastAutoAlign(refimage, tmp, deltax, deltay, 0) + + ret = IpDocClose() + + resultt = Str(i) + Chr(9) + Str(deltax) + Chr(9) + Str (deltay) + Print #1, resultt + +Next i + +Close #1 + +IpAppSelectDoc(Image) +ret = IpSeqSet(SEQ_APPLY, 1) ' set back to apply for all +stopMacro +End Sub + +Sub CalcMultShiftsSeqRef() +Rem Calculates multiple images from image stack in selected areas AOI1, AOI2, ... +Dim n As Integer +Dim tmp As Integer +Dim refimage As Integer +Dim i As Integer +Dim ab As Integer +Dim Iname As String * 255 +Dim s As String +Dim t As String *255 +Dim ext As String +Dim r As RECT +Dim deltax As Integer +Dim deltay As Integer +Dim resultt As String +Dim anz As Integer +Dim Image As Integer + + +startMacro("CalcMultShifts") + + + + +message ="Select Sequence uses active AOI" +Image = selectImage(message) +If Image <0 Then + Exit Sub +End If + + +ret = IpAoiManager(AOIADD,"RAOI") + +IpSeqGet (SEQ_NUMFRAMES, anz) +IpSeqSet (SEQ_ACTIVEFRAME, 0) + +'IpAoiShow(FRAME_NONE) +'IpSeqSet (SEQ_APPLY, 0) ' current frame +'refimage = IpWsDuplicate() + +message ="Select Reference image" +refimage = selectImage(message) +If refimage <0 Then + Exit Sub +End If + +If refimage < 0 Then + Exit Sub +End If + + + +ret = IpStGetName("Save As",Path,"*.DAT", Iname) +If ret = 0 Then + Exit Sub +End If +t = Iname +i = InStr(1,t,".DAT") +If i = 0 Then t = t + ".DAT" +Open t For Output As #1 + +'resultt = "0" + Chr(9) + "0" + Chr(9) + "0" +'Print #1, resultt + +For i = 0 To (anz-1) + + IpAppSelectDoc(Image) + 'ret = IpAoiManager(AOISET,"AOI") + + IpSeqSet (SEQ_ACTIVEFRAME, i) + + IpAoiShow(FRAME_NONE) + IpSeqSet (SEQ_APPLY, 0) ' current frame + + + tmp = IpWsDuplicate() + + ret = FastAutoAlign(refimage, tmp, deltax, deltay, 1) + + + 'ret = FastAutoAlign(refimage, tmp, deltax, deltay, 0) + + ret = IpDocClose() + + resultt = Str(i) + Chr(9) + Str(deltax) + Chr(9) + Str (deltay) + Print #1, resultt + +Next i + +Close #1 + +IpAppSelectDoc(Image) +ret = IpSeqSet(SEQ_APPLY, 1) ' set back to apply for all +stopMacro +End Sub + +Sub setIDalpha(ByVal v As Double) + Select Case opID + Case 1 + putID1alpha(v) + sleep_f(1) + putID1offset(ID1_linrot_offset(v)) + Case 2 + putID2alpha(v) + sleep_f(1) + putID2offset(ID2_linrot_offset(v)) + Case 3 + putID1alpha(v) + sleep_f(1) + putID1offset(ID1_linrot_offset(v)) + putID2alpha(v) + sleep_f(1) + putID2offset(ID2_linrot_offset(v)) + End Select +End Sub + +Function checkVG10() As Integer +Rem check whether VG10 is open, open it when closed +Rem returns 1 when it is closed +Dim statusVG10 As Single +checkVG10=0 +statusVG10 = getVG10() +If statusVG10 = 0 Then + checkVG10=1 + putVG10(0) + sleep(1) + putVG10(1) + write_logfile(1,"VG10 was closed") + sleep(1) +End If +End Function + +Function focus_algo(ByVal startOb As Double, ByVal startSV As Double, ByVal SV As Double) As Double +Rem function for focus change with changing startvoltage +Rem fit from Eletra +Rem focus = startfocus + A * startvoltage^pow + +Const y0 As Double = 1650 +Const A As Double = 5.9924 +Const pow As Double = 0.34653 + +'focus_algo = startOb + A * SV ^ pow +focus_algo = startOb + A * (SV ^ pow - startSV ^ pow) + +End Function