tried adding LDAP information for contact user. Failed.
Added copyright info.
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblParams" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" pref="514" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
@@ -286,7 +286,11 @@
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace pref="442" max="32767" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="jTextField1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="48" max="-2" attributes="0"/>
|
||||
<Component id="jButtonGenerate" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@@ -296,7 +300,11 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="jButtonGenerate" min="-2" pref="33" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jButtonGenerate" alignment="3" min="-2" pref="33" max="-2" attributes="0"/>
|
||||
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jTextField1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
@@ -311,6 +319,19 @@
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonGenerateActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton2"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="jTextField1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Boccioli Marco"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
|
||||
@@ -22,10 +22,22 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
/**
|
||||
@@ -103,6 +115,8 @@ public class NewTest extends javax.swing.JPanel {
|
||||
jTableParams = new javax.swing.JTable();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jButtonGenerate = new javax.swing.JButton();
|
||||
jButton2 = new javax.swing.JButton();
|
||||
jTextField1 = new javax.swing.JTextField();
|
||||
|
||||
jMenuItemAddRow.setText("Add Row");
|
||||
jMenuItemAddRow.addActionListener(new java.awt.event.ActionListener() {
|
||||
@@ -194,12 +208,25 @@ public class NewTest extends javax.swing.JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
jButton2.setText("jButton2");
|
||||
jButton2.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton2ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jTextField1.setText("Boccioli Marco");
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap(442, Short.MAX_VALUE)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton2)
|
||||
.addGap(48, 48, 48)
|
||||
.addComponent(jButtonGenerate, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
@@ -207,7 +234,10 @@ public class NewTest extends javax.swing.JPanel {
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(jButtonGenerate, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jButtonGenerate, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jButton2)
|
||||
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@@ -226,7 +256,7 @@ public class NewTest extends javax.swing.JPanel {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(lblParams)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jScrollPane1))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblName)
|
||||
@@ -309,6 +339,15 @@ public class NewTest extends javax.swing.JPanel {
|
||||
}
|
||||
}//GEN-LAST:event_jMenuItemDeleteRowActionPerformed
|
||||
|
||||
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
// LdapClient ldap = new LdapClient();
|
||||
// System.out.println( "boccioli_m exists:: "+ldap.userExists("boccioli_m"));
|
||||
|
||||
|
||||
getUserInfo(this.jTextField1.getText());
|
||||
}//GEN-LAST:event_jButton2ActionPerformed
|
||||
|
||||
/**
|
||||
* fill table with example parameters
|
||||
* @param newType of type TypeOfNewFile, can be device or test.
|
||||
@@ -490,7 +529,14 @@ public class NewTest extends javax.swing.JPanel {
|
||||
SwingUtils.showMessage(this, "checkDataFields()",
|
||||
"Please provide a valid user name");
|
||||
return false;
|
||||
}
|
||||
} /*else{ //check if the user name is in LDAP *FOR THE MOMENT IT DOES NOT WORK*
|
||||
LdapClient ldap = new LdapClient();
|
||||
if ( !ldap.userExists(txtContactName.getText())){
|
||||
SwingUtils.showMessage(this, "checkDataFields()",
|
||||
"Could not find user name "+txtContactName.getText()+"\nPlease provide a valid user name");
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
//check parameters table
|
||||
for(int row=0 ; row<jTableParams.getRowCount() ; row++){
|
||||
String sParam = jTableParams.getValueAt(row, 0).toString();
|
||||
@@ -833,9 +879,22 @@ public class NewTest extends javax.swing.JPanel {
|
||||
sTestParameters = sTestParameters + "<code>" + name + " </code>" + description + "<br/>\n" ;
|
||||
}
|
||||
}
|
||||
Attributes user = null;
|
||||
/* //does not work for the moment
|
||||
LdapClient ldap = new LdapClient();
|
||||
user = ldap.getUserInfo(sContactName);
|
||||
*/
|
||||
String contactTelephone = "";
|
||||
String contactFirstName = sContactName;
|
||||
String contactSurname = "";
|
||||
if (user != null){
|
||||
contactTelephone = user.get("telephoneNumber").toString().replace("telephoneNumber: ", "");
|
||||
contactFirstName = user.get("givenname").toString().replace("givenName: ", "");
|
||||
contactSurname = user.get("sn").toString().replace("sn: ", "");
|
||||
}
|
||||
success = replaceParameters(path,
|
||||
new String[]{"$testName","$testDescription","$testParameters","$contactName"},
|
||||
new String[]{sTestName,sTestDescription,sTestParameters,sContactName});
|
||||
new String[]{"$testName","$testDescription","$testParameters","$contactUserName","$contactFirstName","$contactSurname","$contactTelephone"},
|
||||
new String[]{sTestName,sTestDescription,sTestParameters,sContactName,contactFirstName,contactSurname,contactTelephone});
|
||||
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "generateTestHelp()", "Cannot create directory " + ex.toString());
|
||||
@@ -888,10 +947,154 @@ public class NewTest extends javax.swing.JPanel {
|
||||
private String cleanFileName(String sName){
|
||||
return sName.replace(":", "-");
|
||||
}
|
||||
|
||||
//does not work
|
||||
private Attributes getUserInfo(String userName){
|
||||
Attributes attrs = null;
|
||||
try {
|
||||
Hashtable env = new Hashtable();
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.ldap.LdapCtxFactory");
|
||||
env.put(Context.PROVIDER_URL, "ldap://d.psi.ch");
|
||||
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
ctx = new InitialDirContext(env);
|
||||
} catch (NamingException ex) {
|
||||
System.out.println("initialdircontext error");
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
try {
|
||||
attrs = ctx.getAttributes("sn="+userName+",ou=People");
|
||||
} catch (NamingException ex) {
|
||||
System.out.println("get attributes error");
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
if(attrs == null){
|
||||
System.out.println("nothing found for " + userName);
|
||||
}else{
|
||||
System.out.println( attrs.get("sn").get().toString());
|
||||
}
|
||||
} catch (NamingException ex) {
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LDAP tool for checking if a user name exists in LDAP.
|
||||
* ######### IT DOES NOT WORK YET ################
|
||||
* ######### Problem: I don't manage to access LDAP as anonymous user
|
||||
* #########(I need to give a username+password in order to get info from a user)
|
||||
*/
|
||||
|
||||
public class LdapClient {
|
||||
|
||||
public void LdapClient() {
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
System.out.println("run: " + new Date());
|
||||
LdapContext ldapContext = getLdapContext();
|
||||
SearchControls searchControls = getSearchControls();
|
||||
getUserInfo("boccioli_m", ldapContext, searchControls);
|
||||
getUserInfo("rees_s", ldapContext, searchControls);
|
||||
getUserInfo("Andrey_Zinovyev", ldapContext, searchControls);
|
||||
getUserInfo("Roman_Kurbangaliyev", ldapContext, searchControls);
|
||||
getUserInfo("fake_user", ldapContext, searchControls);
|
||||
System.out.println("done: " + new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Ldap context. It is used later for getting user info
|
||||
* @return LdapContext
|
||||
*/
|
||||
private LdapContext getLdapContext() {
|
||||
LdapContext ctx = null;
|
||||
try {
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||
//env.put(Context.SECURITY_AUTHENTICATION, "none");//with "none" it does not seem to work. It works with "simple" but it needs a user name and password
|
||||
//env.put(Context.SECURITY_PRINCIPAL, "PSICH\\boccioli_m");//input user & password for access to ldap
|
||||
//env.put(Context.SECURITY_CREDENTIALS, "");//here I should write my password in clear!?!?!?
|
||||
env.put(Context.PROVIDER_URL, "ldap://d.psi.ch");
|
||||
//env.put(Context.REFERRAL, "follow");
|
||||
|
||||
//this works:
|
||||
/*
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||
env.put(Context.SECURITY_AUTHENTICATION, "simple");//with "none" it does not seem to work. It works with "simple" but it needs a user name and password
|
||||
env.put(Context.SECURITY_PRINCIPAL, "PSICH\\boccioli_m");//input user & password for access to ldap
|
||||
env.put(Context.SECURITY_CREDENTIALS, "");//here I should write my password in clear!?!?!?
|
||||
env.put(Context.PROVIDER_URL, "ldap://d.psi.ch");
|
||||
env.put(Context.REFERRAL, "follow");
|
||||
*/
|
||||
|
||||
ctx = new InitialLdapContext(env, null);
|
||||
|
||||
//System.out.println("LDAP Connection: COMPLETE");
|
||||
} catch (NamingException ex) {
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public Attributes getUserInfo(String userName, LdapContext ctx, SearchControls searchControls) {
|
||||
System.out.println("*** " + userName + " ***");
|
||||
Attributes attrs = null;
|
||||
try {
|
||||
NamingEnumeration<SearchResult> answer = ctx.search("dc=d,dc=psi,dc=ch", "sAMAccountName=" + userName, searchControls);
|
||||
if (answer.hasMore()) {
|
||||
attrs = answer.next().getAttributes();
|
||||
//System.out.println(attrs.get("givenname"));
|
||||
//System.out.println(attrs.get("sn"));
|
||||
//System.out.println(attrs.get("mail"));
|
||||
//System.out.println(attrs.get("telephoneNumber"));
|
||||
} else {
|
||||
System.out.println("Ldap user not found.");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public Attributes getUserInfo(String userName) {
|
||||
Attributes attrs = null;
|
||||
LdapContext ldapContext = getLdapContext();
|
||||
SearchControls searchControls = getSearchControls();
|
||||
attrs = getUserInfo(userName, ldapContext, searchControls);
|
||||
String tel = attrs.get("telephonenumber").toString().replace(" ", "");
|
||||
tel = "Tel.: " + tel.substring(tel.length()-4);
|
||||
attrs.put("telephoneNumber",tel);
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public boolean userExists(String userName) {
|
||||
//nex.printStackTrace();
|
||||
|
||||
LdapContext ldapContext = getLdapContext();
|
||||
SearchControls searchControls = getSearchControls();
|
||||
Attributes attrs = getUserInfo(userName, ldapContext, searchControls);
|
||||
return (attrs != null);
|
||||
}
|
||||
|
||||
private SearchControls getSearchControls() {
|
||||
SearchControls cons = new SearchControls();
|
||||
cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
String[] attrIDs = {"sn", "givenname", "mail", "telephoneNumber"};
|
||||
cons.setReturningAttributes(attrIDs);
|
||||
return cons;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton2;
|
||||
private javax.swing.JButton jButtonGenerate;
|
||||
private javax.swing.JComboBox jComboBoxTestSuites;
|
||||
private javax.swing.JMenuItem jMenuItemAddRow;
|
||||
@@ -901,6 +1104,7 @@ public class NewTest extends javax.swing.JPanel {
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane3;
|
||||
private javax.swing.JTable jTableParams;
|
||||
private javax.swing.JTextField jTextField1;
|
||||
private javax.swing.JLabel lblContact;
|
||||
private javax.swing.JLabel lblDescr;
|
||||
private javax.swing.JLabel lblName;
|
||||
|
||||
@@ -268,6 +268,7 @@
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/icons/settings-32px.png"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Optional actions"/>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[60, 40]"/>
|
||||
</Property>
|
||||
|
||||
@@ -57,6 +57,7 @@ import javax.swing.table.TableRowSorter;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.python.core.PyList;
|
||||
import static org.python.bouncycastle.util.Arrays.append;
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
/**
|
||||
@@ -576,6 +577,7 @@ public class TestingList extends Panel {
|
||||
jPanelButtons.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jButtonOptions.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/settings-32px.png"))); // NOI18N
|
||||
jButtonOptions.setToolTipText("Optional actions");
|
||||
jButtonOptions.setMaximumSize(new java.awt.Dimension(60, 40));
|
||||
jButtonOptions.setMinimumSize(new java.awt.Dimension(0, 40));
|
||||
jButtonOptions.setPreferredSize(new java.awt.Dimension(50, 40));
|
||||
@@ -2077,4 +2079,5 @@ public class TestingList extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
#Script Motor Test 2
|
||||
#Go to absolute position A, then move +B steps, then -2B steps, then +2Bsteps (ie oscillate round centre position, logging after each movement); repeat N times
|
||||
|
||||
from startup import *
|
||||
from local import *
|
||||
|
||||
import sys, inspect, os, traceback, time
|
||||
|
||||
|
||||
|
||||
###### DO NOT MODIFY THE CODE BELOW ######
|
||||
def startTest(testName, DEVICE, params):
|
||||
#get the path of this script
|
||||
testPath = inspect.getfile(inspect.currentframe())
|
||||
#by default, failed
|
||||
ret = 'Test failed'
|
||||
status = False
|
||||
#plot name to be given to the scan. Use: scan.setPlotName(plotName)
|
||||
plotName = DEVICE + ' - ' + testName
|
||||
###### WRITE YOUR CODE HERE BELOW #######
|
||||
|
||||
#get parameters from the calling interface
|
||||
try:
|
||||
print_log(testName, DEVICE, "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:\n" + str(params))
|
||||
middle = 40.0 #float(params["midPoint"]["value"])
|
||||
loopTimes = 1 #int(params["repeatTimes"]["value"])
|
||||
span = 2 # float(params["spanFromMidPoint"]["value"])
|
||||
except:
|
||||
ret = 'Could not retrieve testing parameters - ' + traceback.format_exc()
|
||||
success = False
|
||||
sendFeedback(testPath, testName, DEVICE, ret, status)
|
||||
return
|
||||
|
||||
#scan = ManualScan(['idX'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'] , [ 0.0], [ 3000.0], [20])
|
||||
scan = ManualScan(['idX'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idMotorPosition', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idBtvsProc', 'idDiff01', 'idDiff02'])
|
||||
scan.setPlotName(plotName)
|
||||
scan.start()
|
||||
|
||||
#Creating channels: dimension 1
|
||||
try:
|
||||
#RegionPositioner idInkr
|
||||
#idInkr = Channel(DEVICE+':INKR:2', type = 'd')
|
||||
idInkr = Channel(DEVICE+':MOTOR.VAL', type = 'd')
|
||||
#ScalarDetector idMotorStatus
|
||||
#idMotorStatus = Channel(DEVICE+':STA:1', type = 'd')
|
||||
idMotorStatus = Channel(DEVICE+':MOTOR.MSTA', type = 'd')
|
||||
#ScalarDetector idLogicalPosition
|
||||
#idLogicalPosition = Channel(DEVICE+':IST:2', type = 'd')
|
||||
idLogicalPosition = Channel(DEVICE+':MOTOR.RVAL', type = 'd')
|
||||
#ScalarDetector idDiameter
|
||||
#idDiameter = Channel(DEVICE+':DIAM:2', type = 'd')
|
||||
idDiameter = Channel(DEVICE+':ENCODERoff', type = 'd')
|
||||
#ScalarDetector idMotorPosition
|
||||
#idMotorPosition = Channel(DEVICE+':IST1:2', type = 'd')
|
||||
idMotorPosition = Channel(DEVICE+':MOTOR.RBV', type = 'd')
|
||||
#ScalarDetector idPotiRaw
|
||||
#idPotiRaw = Channel(DEVICE+':POSA:1', type = 'd')
|
||||
idPotiRaw = Channel(DEVICE+':ENCODERraw', type = 'd')
|
||||
#ScalarDetector idPotiProc
|
||||
#idPotiProc = Channel(DEVICE+':POSA:2', type = 'd')
|
||||
idPotiProc = Channel(DEVICE+':ENCODER', type = 'd')
|
||||
#ScalarDetector idBtvsRaw
|
||||
#idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd')
|
||||
idBtvsRaw = Channel(DEVICE+':MOTOR.LLS', type = 'd')
|
||||
#ScalarDetector idBtvsProc
|
||||
#idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd')
|
||||
idBtvsProc = Channel(DEVICE+':MOTOR.HLS', type = 'd')
|
||||
#ScalarDetector idEndSwitchL
|
||||
#idBtvsRaw = Channel(DEVICE+':IST3:1', type = 'd')
|
||||
idEndSwitchL = Channel(DEVICE+':MOTOR.LLS', type = 'd')
|
||||
#ScalarDetector idEndSwitchH
|
||||
#idBtvsProc = Channel(DEVICE+':IST3:2', type = 'd')
|
||||
idEndSwitchH = Channel(DEVICE+':MOTOR.HLS', type = 'd')
|
||||
#high position limit
|
||||
idLimitH = Channel(DEVICE+':MOTOR.HLM', type = 'd')
|
||||
#low position limit
|
||||
idLimitL = Channel(DEVICE+':MOTOR.LLM', type = 'd')
|
||||
except:
|
||||
ret = 'Unable to create channel - ' + traceback.format_exc()
|
||||
success = False
|
||||
sendFeedback(testPath, testName, DEVICE, ret, status)
|
||||
return
|
||||
|
||||
|
||||
#remove limits
|
||||
idLimitH.put(999999.9, timeout=None)
|
||||
idLimitL.put(-999999.9, timeout=None)
|
||||
|
||||
direction = 1.0
|
||||
startDefault = middle - span
|
||||
endDefault = middle + span
|
||||
end = endDefault+1
|
||||
#find position: it will be the middle point of the test
|
||||
print_log(testName, DEVICE, 'Moving to middle point ' + str(middle) )
|
||||
idInkr.put(middle, timeout=None) # TODO: Set appropriate timeout
|
||||
readback2 = idInkr.get()
|
||||
if abs(readback2 - middle) > 1 : # TODO: Check accuracy
|
||||
ret = 'Actor idInkr could not be set to the value ' + str(middle) + ' (current value: ' + str(readback2) + ')'
|
||||
success = False
|
||||
sendFeedback(testPath, testName, DEVICE, ret, status)
|
||||
return
|
||||
start = readback2+direction
|
||||
countSteps = 0
|
||||
count = 0
|
||||
print_log(testName, DEVICE, 'Moving around middle point (+-' + str(span) + ')' )
|
||||
for setpoint1 in range(0, loopTimes*2):
|
||||
count = count + 1
|
||||
sleep( 2 ) # Settling time
|
||||
#RegionPositioner idInkr
|
||||
for setpoint2 in frange(start, end, direction):
|
||||
readback1 = setpoint1
|
||||
idInkr.put(setpoint2, timeout=None) # TODO: Set appropriate timeout
|
||||
sleep( 0.2 ) # Settling time
|
||||
readback2 = idInkr.get()
|
||||
if abs(readback2 - setpoint2) > 1 : # TODO: Check accuracy
|
||||
ret = 'Actor idInkr could not be set to the value ' + str(setpoint2) + ' (current value: ' + str(readback2) + ')'
|
||||
success = False
|
||||
sendFeedback(testPath, testName, DEVICE, ret, status)
|
||||
return
|
||||
#Detector idMotorStatus
|
||||
detector1 = idMotorStatus.get()
|
||||
#Detector idLogicalPosition
|
||||
detector2 = idLogicalPosition.get()
|
||||
#Detector idDiameter
|
||||
detector3 = idDiameter.get()
|
||||
#Detector idMotorPosition
|
||||
detector4 = idMotorPosition.get()
|
||||
#Detector idPotiRaw
|
||||
detector5 = idPotiRaw.get()
|
||||
#Detector idPotiProc
|
||||
detector6 = idPotiProc.get()
|
||||
#Detector idBtvsRaw
|
||||
detector7 = idBtvsRaw.get()
|
||||
#Detector idBtvsProc
|
||||
detector8 = idBtvsProc.get()
|
||||
#end switches
|
||||
endH = idEndSwitchH.get()
|
||||
endL = idEndSwitchL.get()
|
||||
#Manipulation idDiff02
|
||||
#Variable Mappings
|
||||
a = detector4
|
||||
b = detector8
|
||||
idDiff02 = a-b
|
||||
#Manipulation idDiff01
|
||||
#Variable Mappings
|
||||
a = detector4
|
||||
b = detector6
|
||||
idDiff01 = a-b
|
||||
countSteps = countSteps + 1
|
||||
scan.append ([countSteps], [countSteps], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, idDiff02, idDiff01])
|
||||
if endH>0.0 or (direction > 0.0 and setpoint2 >= end -1):
|
||||
#invert direction and swap start with end of translation
|
||||
end = startDefault-1
|
||||
start = setpoint2 - direction
|
||||
direction = -1.0
|
||||
print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) )
|
||||
break
|
||||
if endL>0.0 or ( direction < 0.0 and setpoint2 <= end +1):
|
||||
#invert direction and swap start with end of translation
|
||||
end = endDefault+1
|
||||
start = setpoint2 - direction
|
||||
direction = 1.0
|
||||
print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) )
|
||||
break
|
||||
|
||||
#set limits back
|
||||
idLimitH.put(145.0, timeout=None)
|
||||
idLimitL.put(0.0, timeout=None)
|
||||
|
||||
#Closing channels
|
||||
idInkr.close()
|
||||
idMotorStatus.close()
|
||||
idLogicalPosition.close()
|
||||
idDiameter.close()
|
||||
idMotorPosition.close()
|
||||
idPotiRaw.close()
|
||||
idPotiProc.close()
|
||||
idBtvsRaw.close()
|
||||
idBtvsProc.close()
|
||||
|
||||
scan.end()
|
||||
ret = 'Slide moved back and forth (' + str(count) + ' runs)'
|
||||
status = True
|
||||
|
||||
########## END OF YOUR CODE ###########
|
||||
|
||||
###### DO NOT MODIFY THE CODE BELOW ######
|
||||
sendFeedback(testPath, testName, DEVICE, ret, status)
|
||||
|
||||
#prepare and send feedback to calling tool
|
||||
def sendFeedback(testPath, testName, DEVICE, returnString, testPassed):
|
||||
print_log(testName, DEVICE, 'End of test. Result:')
|
||||
print_log(testName, DEVICE, 'Test path: ' + testPath)
|
||||
print_log(testName, DEVICE, 'Test name: ' + testName)
|
||||
print_log(testName, DEVICE, 'Device: ' + DEVICE)
|
||||
print_log(testName, DEVICE, 'Test passed: ' + str(testPassed))
|
||||
print_log(testName, DEVICE, 'Return string: ' + returnString)
|
||||
ret = [testPath, DEVICE, returnString, testPassed]
|
||||
set_return(ret)
|
||||
|
||||
def print_log(testName, DEVICE, text):
|
||||
time.ctime()
|
||||
now = time.strftime('%Y.%m.%d %H:%M:%S')
|
||||
print now + ' ' + DEVICE + ' - ' + testName + ': ' + text
|
||||
|
||||
|
||||
#get test arguments
|
||||
#DEVICE = device
|
||||
#parameters={}#REMOVE
|
||||
#launch the test
|
||||
#startTest(test, device, parameters)
|
||||
@@ -1,11 +1,13 @@
|
||||
<html>
|
||||
<!-- Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. -->
|
||||
<body>
|
||||
<h2>Description</h2>
|
||||
$testDescription
|
||||
<h2>Parameters</h2>
|
||||
$testParameters
|
||||
<h2>Contact</h2>
|
||||
<a href="https://intranet.psi.ch/search/#?t=phonebook&q=$contactName">$contactName</a>
|
||||
<a href="https://intranet.psi.ch/search/#?t=phonebook&q=$contactUserName">$contactFirstName $contactSurname</a> <br/>
|
||||
$contactTelephone
|
||||
</html>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Test name: $testName
|
||||
# $testDescription
|
||||
# Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
|
||||
|
||||
###### Init - DO NOT MODIFY THE CODE BELOW ######
|
||||
global sys, inspect, os, traceback
|
||||
|
||||
@@ -42,10 +42,10 @@ def startTest(testName, DEVICE, params):
|
||||
try:
|
||||
idCom = Channel(DEVICE+':COM:2' , type = 'd') #current position as from motor step counter [mm]
|
||||
idMotorPosition = Channel(DEVICE+':IST3:2', type = 'd') #current position as from motor step counter [mm]
|
||||
idPotiPosFromBeam = Channel(DEVICE+':IST1:2', type = 'd') #current position from beam as from potentiometer [mm]
|
||||
#idPotiPosFromBeam = Channel(DEVICE+':IST1:2', type = 'd') #current position from beam as from potentiometer [mm]
|
||||
idPotiPosition = Channel(DEVICE+':IST2:1', type = 'd') #current position as from potentiometer [mm]
|
||||
idPotiRef1Position = Channel(DEVICE+':REF1:1', type = 'd') #R1 position as from potentiometer [mm]
|
||||
idPotiRef2Position = Channel(DEVICE+':REF2:1', type = 'd') #R2 position as from potentiometer [mm]
|
||||
#idPotiRef1Position = Channel(DEVICE+':REF1:1', type = 'd') #R1 position as from potentiometer [mm]
|
||||
#idPotiRef2Position = Channel(DEVICE+':REF2:1', type = 'd') #R2 position as from potentiometer [mm]
|
||||
|
||||
except:
|
||||
test.sendFeedback( 'Unable to create channel - ' + traceback.format_exc(), False)
|
||||
@@ -63,10 +63,10 @@ def startTest(testName, DEVICE, params):
|
||||
currentTime = float(java.lang.System.currentTimeMillis())
|
||||
|
||||
motorPosition = idMotorPosition.get()
|
||||
potiPosFromBeam = idPotiPosFromBeam.get()
|
||||
#potiPosFromBeam = idPotiPosFromBeam.get()
|
||||
potiPosision = idPotiPosition.get()
|
||||
potiRef1Position = idPotiRef1Position.get()
|
||||
potiRef2Position = idPotiRef2Position.get()
|
||||
#potiRef1Position = idPotiRef1Position.get()
|
||||
#potiRef2Position = idPotiRef2Position.get()
|
||||
diff1 = motorPosition-potiPosision
|
||||
scan.append ([currentTime], [currentTime], [motorPosition, potiPosision, diff1])
|
||||
sleep( samplePeriod ) # Settling time
|
||||
@@ -79,7 +79,6 @@ def startTest(testName, DEVICE, params):
|
||||
idPotiPosition.close()
|
||||
idPotiRef1Position.close()
|
||||
idPotiRef2Position.close()
|
||||
test.log( 'End of Monitoring')
|
||||
ret = 'End of Monitoring'
|
||||
success = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user