"""
#%TITLE% Huber_attenuators.mac
#$Revision: 1.1 $
#%NAME% Macros for Huber Attenuator
#%DESCRIPTION%
#Macros for Huber Attenuator
#%CATEGORY% Attenuator
#%INTERNALS%
#based on WAGO SPS, Huber Diffraction
#%SETUP%
#This macro assumes that an Interface I "FIELD" with "Modbus over TCP IP"
#with device ID 0 is defined ie device x.x.x.x:502 Modbus over TCP_IP
#byte 32000 contains the 8 Bits of the IO ports of the SPS controller
#%BR%%BR%
#Attention: TCP timeout has to be set to 0 = no timeout on WAGO controller
#%BR%%BR%
#connection problems: connection refused:
#reason: generic modbus controller must be present and working
#%END%
"""
#assign variables
noFilters = 8 # 8 for 8-fold 6 for 6 fold
global array hfilter[noFilters]
# ********************* attenuator help ********************************
#%UU%
#%MDESC% help
def attenuator_help '{
tty_cntl("md")
printf("\n")
printf("** help for Huber attenuator box **\n")
tty_cntl("me")
printf("attenuator set 1-8 1/0 to switch off,on or request status \n")
#printf("example: attenuator set 1 1 move attenuator no 1 in \n")
printf("attenuator off move all attenuators out \n")
printf("attenuator get get status \n")
printf("attenuator_help get help text \n")
printf("\n")
}'
rdef huber_help attenuator_help # second name for the help macro
# ********************* attenuator help end ***************************
#***********************************************************************
# Attenuator macro
#***********************************************************************
#%UU%[off|set|get]
#%MDESC%
#%INTERNALS%
#for any reason commands always have to be sent twice ** solved by TCP timeout = 0
def attenuator '{
if ($# == 0) {
eprint "Usage: attenuator off or attenuator set 1-6 1/0 to set filter 1-6 to 1/0 or attenuator get"
exit
}
#********************************* off *****************************
if ("$1" == "off") {
#fbus_put(0,6,32000,0)
#sleep(1)
fbus_put(0,6,32000,0)
eval("attenuator get")
}
#********************************* set *****************************
if ("$1" == "set") {
hsum = 0
hfilter[$2-1] = $3
for (i=0; i < noFilters; i++) {
#printf ("Filter %s = %s \n", i+1, hfilter[i])
if (hfilter[i] == 1) hsum = hsum + pow(2,i)
}
#fbus_put(0,6,32000,hsum)
#sleep(1)
fbus_put(0,6,32000,hsum)
eval("attenuator get")
}
#********************************* get *****************************
if ("$1" == "get") {
#fbus_get(0,3,32000,1)
#sleep(1)
hsum = fbus_get(0,3,32000,1)
for (i = noFilters-1; i > -1; i--) {
if ((hsum - pow(2,i)) >= 0) {
hfilter[i] = 1
hsum = hsum -pow(2,i)
} else {
hfilter[i] = 0
}
}
printf("Attenuator set No. %d: \n", fbus_get(0,3,32001,1))
for (m=0; m < noFilters; m++ ) {
att_thick = fbus_get(0,3,32002+m,1)
att_text = att_get_text (32100 + m*100)
if (hfilter[m] == 1)
tty_cntl("md")
printf ("%s:%s \(%s mum\) = %s \n", m+1, att_text, att_thick, hfilter[m])
tty_cntl("me")
}
}
}
'
#%IU%(att_mod_adress)
#%MDESC% extract letters from 16 Bit answer
def att_get_text(att_mod_adress) '{
att_text = ""
for (k = 0; k < 80; k++) {
char1 = 0
char2 = 0
two_byte = fbus_get(0,3,att_mod_adress+k,1)
#p $1+ka
for (i = 15; i >= 8; i--) {
#p two_byte
if ((two_byte - pow(2,i)) >= 0) {
char1 = char1 + pow(2,i-8)
two_byte= two_byte -pow(2,i)
}
}
#p "byte2"
for (i=7; i >= 0; i--) {
#p two_byte
if ((two_byte - pow(2,i)) >= 0) {
char2 = char2 + pow(2,i)
two_byte= two_byte -pow(2,i)
}
}
if (char2!=0)
att_text = sprintf("%s%c",att_text,char2)
if (char1!=0 && char2!=0)
att_text = sprintf("%s%c",att_text,char1)
#printf("%c%c",char2,char1)
#printf("%d %d ",char2,char1)
if (char1 == 0)
k=80
if (char2 == 0)
k=80
}
#p att_text
return (att_text)
}
'
#%MACROS%
#%IMACROS%
#%AUTHOR% SG 2022
#$Revision: 1.1 $
#%TOC%
|