#%TITLE% millitron.MAC
#%NAME%
# Macros to control a MILLITRON 1240 Version 2.0
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
# This macro file allows to connect a millitron micrometer as a pseudo counter in SPEC.
#%DL%
#%DT% History:
#%DD% 18/10/01, L.Claustre change on %B%milon%B% macro see the setup section.
#%DD% 18/12/00, L.Claustre first version for distribution.
#%XDL%
#
#%SETUP%
#%DL%
#%DT% Controller 1240
#%DD% The millitron controller has to be configured before using it with this macros.
#%DD% Press the \"config\" press-button (on the rear panel), then go the \"PARAM E/S\" menu and check values are the following:
#%UL%
#%LI% 9600
#%LI% PR.V--
#%LI% RS232C
#%LI% CAR.8n1
#%LI% NO.DIS.
#%XUL%
#%DD% Then go to the main menu and check the \"CALCUL\" option is set instead of \"SANS C/I\".
#%DD% Now save changes, so go to the \"SAUVEG.\" menu and press the down button (right side), \"OK\" should be displayed.
#%DT% SPEC
#%DD% configure a ESRF serial device (dserver for IBAM) with baud rate set to 9600 and with \"raw\" mode.
#%DT% SerialLine dserver
#%DD% Default resources are enough.
#%XDL%
#%END%
#%UU% [No of mils] [mil1 motor name] [mil1 device name] ...
#%MDESC% Adds the given mils to the already defined mils
#
#%IU% mil-mnemonic serial_id channel_nr
#%MDESC%
# Add definitions for a millitron micrometer pseudocounter
def miladd 'mil_add("$1", "$2", "$3")'
#%IU% (mil-mnemonic, serial_id, channel_nr)
#%MDESC%
# Add definitions for a millitron micrometer pseudocounter
def mil_add(mne, dev, nr) '{
local device angle hlim llim
if (cnt_num(mne) == -1) {
printf("Counter \"%s\" does not exist, exit\n", mne)
exit
}
if (nr != 1 && nr != 2) {
printf("Wrong Channel number for %s, choose 1 or 2, exit\n", mne)
exit
}
list_add(MIL_LIST, mne)
list_setpar(MIL_LIST, mne, "dev", dev)
list_setpar(MIL_LIST, mne, "nr", nr)
if (whatis("blmenu") & 0x2 )
milblon()
setup_tail("mil", sprintf("mil_%s %s", mne, mne))
}'
def milblon() '{
blmenuadd("Millitron counters", "Millitron Info", "milbody", "mil")
}'
def milbody(mode) '{
if ( mode == 1 ) {
if (MILON) {
miloff
} else {
milon
}
}
if (mode == 2) {
milshow
}
return(MILON?"On":"Off")
}'
#%IU% (mil-mnemonic)
#%MDESC%
# Delete definitions for one MILLI mnemonic
#
def milunsetup '{
mildel($1)
}'
#%IU% (mil-mnemonic)
#%MDESC%
# Delete definitions for one MIL mnemonic
#
def mildel(mne) '{
list_remove(MIL_LIST,mne)
cdef("", "", mne, "delete")
S[cnt_num(mne)]=0
}'
#%UU% [mil-mne1 serial_id1 channel_nr1 [...]]
#%MDESC%
# Sets parameters for a group of millitron micrometer pseudocounters. It can be called
# interactively or non-interactively by giving all parameters in the
# command line.
def milsetup '
{
global MILON MIL_LIST MIL_LAST_CNT
list_test MIL_LIST
local millist i
local params number
local milmne mildev milno milnr
number = 0
if (!$#) {
milshow
if ((milno = list_n(MIL_LIST)) > 0 ) {
_yn = yesno("Do you want to change any of this values",0)
}
if (_yn || !milno) {
miloff
print "\nEnter as mnemonic \`end\' to finish or \`delete\' to remove a millitron counter."
list_init millist
for(i = 1; ; i++) {
printf("\nMILLITRON #%d:", i)
if ((milmne = list_item(MIL_LIST, i)) == -1) {
milmne = "end"
}
milmne = getval("\tMnemonic", milmne)
if (milmne == "delete") {
milmne = list_item(MIL_LIST, i)
milunsetup milmne
i--
continue
}
if (milmne == "end") {
break
}
if ((mildev = list_getpar(MIL_LIST, milmne, "dev")) == -1) {
mildev = ""
}
mildev = getval("\tSERIAL ID # ", list_getpar(MIL_LIST, i, "dev"))
list_add(millist, milmne)
milnr = getval("\tChannel (1-2)# ", list_getpar(MIL_LIST, i, "nr"))
list_add(millist, milnr)
list_setpar(millist, milmne, "dev", mildev)
list_setpar(millist, milmne, "nr", milnr)
number +=1
}
print
milreset
for (i = 1; i <= number; i++) {
milmne = list_item(millist, i * 2 - 1)
mildev = list_getpar(millist, milmne, "dev")
milnr = list_getpar(millist, milmne, "nr")
mil_add(milmne, mildev, milnr)
}
}
} else {
miloff
milno = int($#/3)
split("$*",params)
milreset
for (i = 0; i < milno; i++) {
milmne = params[i*3]
mildev = params[i*3 + 1]
milnr = params[i*3 + 2]
mil_add(milmne, mildev, milnr)
}
}
}
'
#%UU%
#%MDESC%
# Reset internal lists.
def milreset '
miloff
list_init MIL_LIST
'
#%UU%
#%MDESC%
# Shows current MIL pseudocounters definition.
#
def milshow '{
local milno mne
if (milno = list_n(MIL_LIST)) {
printf("\nMILLITRON pseudocounters are \"%s\"\n\n",MILON?"ACTIVE":"NOT ACTIVE")
printf("\t Motor Device Config\n")
printf("\t---------------------------------------------------\n")
for (i=1; i<=milno; i++) {
mne = list_item(MIL_LIST, i)
printf("\t%8s %15s/%s", mne, list_getpar(MIL_LIST, mne, "dev"),\
list_getpar(MIL_LIST, mne, "nr"))
if (cnt_num(mne) < 0)
printf(" %20s\n","NOT DEFINED")
else
printf(" %20s\n","OK")
}
printf("\n")
} else
printf("Nothing defined for MILLITRON\n")
}'
#%UU%
#%MDESC%
# Deactivates definitions for MIL pseudocounters.
def miloff '
{
local milno
milno = list_n(MIL_LIST)
for (i = 1; i <= milno; i++) {
cdef("", "", list_item(MIL_LIST, i), "delete")
}
MILON=0
}'
#%UU%
#%MDESC%
# Activates definitions for MIL pseudocounters.
#
def milon '
{
local milno num mne dev nr init
milno = list_n(MIL_LIST)
init=0
for (i=1; i <= milno; i++) {
num = cnt_num(mne = list_item(MIL_LIST, i))
if (num != -1 ) {
dev = list_getpar(MIL_LIST, mne, "dev")
nr = list_getpar(MIL_LIST, mne, "nr")
if (init==0) {
# first initialise the controller for computer control
ser_put(dev, "I\015") # Init. controller for remote ctrl
p ser_get(dev,23)
# after poweroff-on Tcr = 13, so read exact number of char.
# Then change the Tcr to 10 (\n)
# so now spec can read char. until a "\n" is sent.
# if dserver is used, check the newline resource is set
# to 13
ser_put(dev, "P30,10\015")
sleep(.2)
p ser_get(dev)
init=1
}
cdef("user_getcounts", sprintf("mil_getcounts %s\n", mne), mne, 0x02)
}
}
MILON=1
setup_tail("mil", sprintf("mil_%s %s", mne, mne))
# position control
printf("MILLITRON pseudocounters are now ACTIVE\n")
}'
#%UU%
#%MDESC%
# Activates the display for the input selected.
#
def mildisp '{
if (!$# || ($1!=1 && $1!=2)) {
printf("usage: mildisp <1-2>\n")
exit
}
ser_put(device, sprintf("P51,X%d\015", $1)) # select channel i
sleep(0.2)
ser_get(device)
}'
#%IU%
#
def mil_getcounts '
{
local device mil_dummy mil_ct mil_val nr
device = list_getpar(MIL_LIST, "$1", "dev")
nr = list_getpar(MIL_LIST, "$1", "nr")
if (MIL_LAST_CNT != "$1") {
ser_put(device, sprintf("P51,X%d\015", nr)) # select channel i
sleep(0.05)
ser_get(device)
MIL_LAST_CNT = "$1"
}
ser_put(device,"M\015")
sleep(0.05)
mil_ct = ""
mil_ct = ser_get(device)
# mil_dummy= ser_get(device)
# while (mil_dummy !="") {
# mil_ct = sprintf("%s%s", mil_ct, mil_dummy)
# mil_dummy = ser_get(device)
# }
if (mil_ct != "") {
split(mil_ct, mil_val,",")
if (mil_val[0]=="E7") {
S[$1] = mil_val[2]
}else {
S[$1] = mil_val[1]
}
} else {
S[$1] = -99999
}
}'
#%MACROS%
#%IMACROS%
#%DEPENDENCIES%
# To use a millitron as a counter the following conditions have to be fulfilled:
#%UL%
#%LI% The file millitron.mac has to be read in done by: startup s.
# (this file needs: pseudo.mac , stchanges.mac)
#%LI% the millitron counters have to be configured done by: SPECADM
# (Controller NONE, mnemonic as in startupscript)
#%LI% setup the mils ( with milsetup ) done by: startup s.
#%XUL%
#%AUTHOR% Laurent
#%TOC%
|