#%TITLE% IRL_LASER.MAC
#
#%NAME%
# Macros to remote control a laser power supply from IPG company.
#
#
#%UU% serialline
#%MDESC%
# Configure the serial line to use to communicate with the laser controller
#
def irlsetup '{
global IRL_SL
local sl
if($#!=1)
{
print "Usage: $0 serialline"
print " serialline: number corresponding to entry in the config"
exit
}
sl=$1
if(ser_par(sl,"device_id") == -1)
{
print "Error: serialline number not valid"
print "Hint : configure the serial in spec config"
exit
}
IRL_SL = sl
}'
#%IU%
#%MDESC%
# Check that the setup has been well done
#
def _irl_checksl '{
global IRL_SL
# check if set
if(whatis("IRL_SL") & 0x08000000)
{
print "ERROR: missing serialline"
print "Hint : use macro \"irl_setup\""
exit
}
}'
#%IU%(pwr)
#%MDESC%
# Set the infra red laser power in watts
#
def _irlset(pwr) '{
local byte array cmd[10]
local str
local ret
local i
local j
str=sprintf("%.3f",pwr)
i = 0
cmd[i++] = 0x81
for(j=1;j<=length(str);j++) { cmd[i++] = asc(substr(str,j,1)) }
cmd[i++] = 0x0d
ser_put(IRL_SL,cmd,i)
}'
#%IU%(x)
#%MDESC%
# Returns a valid integer rounded
#
def _irlround(x) '{if (x>=0) return int(x+0.5); else return int(x-0.5)}'
#%IU%(x)
#%MDESC%
# Returns a valid float rounded
#
def _irlfloat(x) '{return (_irlround(x*10.0)/10.0)}'
#%UU% power
#%MDESC%
# Set the infra red laser power given in watts
#
def irlset '{
global IRL_SL
local str
local pwr
if($# != 1)
{
print "Usage: $0 power"
print " power: given in watts"
exit
}
str = "$1"
if(sscanf(str,"%f",pwr) != 1)
{
print "Error: bad power value: ",str
print "Hint : enter a float value"
exit
}
pwr=_irlfloat(pwr)
if(pwr >= 0.7)
{
if(!yesno("Do you really want to buy a new modulator",0))
exit;
}
if(pwr >= 2.0)
{
print "ERROR: requested power too high"
exit
}
_irl_checksl
_irlset(pwr)
}'
#%IU%()
#%MDESC%
# Return the current infra red laser power in watts
# or -1 in case of error
#
def _irlget() '{
local byte array cmd[10]
local ans
local ret
local i
i = 0
cmd[i++] = 0x83
cmd[i++] = 0x0d
ser_put(IRL_SL,cmd,i)
ans=ser_get(IRL_SL)
if(sscanf(ans,"%f",ret) != 1) {ret = -1 }
return(ret)
}'
#%UU%
#%MDESC%
# Print out the current infra red laser power in watts
#
def irlget '{
global IRL_SL
local pwr
_irl_checksl
pwr = _irlget()
if(pwr == -1)
{
print "ERROR: unable to get laser power"
exit
}
printf("Current infrared laser power in Watts: %.3f\n",pwr)
}'
#%IU%()
#%MDESC%
# Return the current controller status
# or -1 in case of error
#
def _irlgetstatus() '{
local byte array cmd[10]
local ans
local ret
local i
i = 0
cmd[i++] = 0x8b
cmd[i++] = 0x0d
ser_put(IRL_SL,cmd,i)
ans=ser_get(IRL_SL)
if(sscanf(ans,"%d",ret) != 1) {ret = -1 }
return(ret)
}'
#%IU%()
#%MDESC%
# Return the current controller temperature
# or -1 in case of error
#
def _irlgettemp() '{
local byte array cmd[10]
local ans
local ret
local i
i = 0
cmd[i++] = 0x85
cmd[i++] = 0x0d
ser_put(IRL_SL,cmd,i)
ans=ser_get(IRL_SL)
if(sscanf(ans,"%f",ret) != 1) {ret = -1 }
return(ret)
}'
#%UU%
#%MDESC%
# Print out the current infra red laser power in watts
#
def irlstatus '{
global IRL_SL
local st
local sttxt[]
local stset[]
local stclr[]
local i
local msk
local temp
_irl_checksl
st = _irlgetstatus()
if(st == -1)
{
print "ERROR: unable to get laser controller status"
exit
}
temp = _irlgettemp()
if(temp == -1)
{
print "ERROR: unable to get laser controller temperature"
exit
}
stset[0x001] = "APC"
stclr[0x001] = "ACC"
sttxt[0x001] = "Mode"
stset[0x002] = "too high !!!!!!!!!!!!"
stclr[0x002] = "OK"
sttxt[0x002] = "Back reflect"
stset[0x004] = "ACTIVE"
stclr[0x004] = "OK"
sttxt[0x004] = "Interlock"
stset[0x008] = "too high !!!!!!!!!!!!"
stclr[0x008] = "OK"
sttxt[0x008] = "Temperature"
stset[0x020] = "ON !!!!!!!!!!!!"
stclr[0x020] = "OFF"
sttxt[0x020] = "Emission"
stset[0x040] = "ON !!!!!!!!!!!!"
stclr[0x040] = "OFF"
sttxt[0x040] = "Red laser "
stset[0x100] = "Ext"
stclr[0x100] = "Int (APC ACC)"
sttxt[0x100] = "Cmd mode"
stset[0x200] = "OFF"
stclr[0x200] = "ON"
sttxt[0x200] = "Module"
for(i=0;i<10;i++)
{
msk = 1<<i
if(msk in sttxt)
{
printf("%-13s:",sttxt[msk])
if(msk & st)
printf("%s\n",stset[msk]);
else
printf("%s\n",stclr[msk]);
}
}
printf("%-13s:%.1f\n","Temperature",temp)
}'
#%IU%(todo)
#%MDESC%
# Set the red laser on (0) or off (1)
#
def _irlred(todo) '{
local byte array cmd[10]
local str
local ret
local i
local j
i = 0
cmd[i++] = 0x8e
cmd[i++] = (todo==0?0x30:0x31)
cmd[i++] = 0x0d
ser_put(IRL_SL,cmd,i)
}'
#%UU%
#%MDESC%
# Switch on the red laser
#
def irlredon '{
_irlred(1)
}'
#%UU%
#%MDESC%
# Switch off the red laser
#
def irlredoff '{
_irlred(0)
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% MP BLISS (Original 12/2009).
# %BR%$Revision: 1.0 $ / $Date: 2009/12/10 12:00:41 $
#%TOC%
|