# Presentation: 264484

## Lab #2IOC Database

## Lab #2IOC Database

- Real Life Example #2 : After returning from your vacation, you have an e-mail requesting the following enhancements to the LINAC Control System:
- Add Beam Transport Efficiency calculations (and PVs) for FC1 and FC2
- Provide a PV that allows the operator to enter their name. Display this PV on the medm display labeled “Operator In Charge”
- Turn off gun and set cathode current to 0 if cathode temperature exceeds 180 degrees
- Don’t allow the Beam On button to be activated unless the cathode temperature is within range
- Define an “Open Access” PV which gets its state from a toggle switch
- Define appropriate records to keep all power supplies at 0 current when in “Open Access”
- Turn on a warning light when beam reaches either faraday cup. Reflect the amount of beam hitting the faraday cup on the analog gauge.

## New PVs

- You can either create a new database file for your PVs or add them to
- ~/ioc/linac/linacApp/Db/xxLinacSim.db
- To start jdct ...
- cd ~/ioc/linac/linacApp/Db
- jdct &
- Load database definition file ...
- From file menu, Open  ../../dbd/linacApp.dbd
- Save edited (or new) database ...
- From file menu,  Save as  ../linacApp/Db/_.db
- If you created a new database, edit Makefile.Host and execute gnumake. You must also edit
- ~/ioc/linac/iocBoot/ioclinac/st.cmd
-       to load the new database.

## New PVs

- Create Beam Transport Efficiency PVs for FC1 and FC2
- Create a calc record* studnt_:FC1:transportRatioM *that provides the required calculation (FC1/CM1).* *Scan it periodically at 1 second.
- Create a calc record *studnt_:FC2:transportRatioM. *that provides the required calculation (FC2/CM1).* *Use the .CP attributes on the input links to have it scan when necessary.
- Add readouts for these PVs on the medm display
- Provide a PV that allows the operator to enter their name. Display this PV on the medm display labeled “Operator In Charge”
- Create a stringin record named *studnt_:OP:operator*. Have the value initialize to “None”.
- Create a text entry on the medm display for operator entry

## Auto-shutdown - gun

- Turn off gun and set cathode current to 0 if cathode temperature exceeds 180 degrees
- Create a calcout record that monitors cathode temperature. When temperature exceeds 180 degrees, have the calcout record force the processing of a sequence record that turns the gun off and sets the cathode current to 0.
- NOTE : APS is very careful to distinguish between “equipment protective interlocks” and “prudent operating procedures”. We do not rely on EPICS to perform “equipment protective interlocks”. The above example assumes that there is a hardwired interlock protecting the cathode at 190 degrees.

## Beam On Inhibit

- Don’t allow the Beam On button to be activated unless the cathode temperature is within range
- Create a calc record (*studnt_:cathodeTempCheck*) whose value is 1 when the cathode temperature is within the appropriate range (140-160 degrees) and 0 when it is not within range.
- Set the *studnt_:gunOnC.SDIS* to fetch the above record. Set *studnt_:gunOnC.DISV *to 0 to disable the record when the cathode temperature is out of range.
- Does this work as you expect ?

## Beam On Inhibit

- Another approach ...
- Copy *studnt_:gunOnC *to a new PV *studnt_:gunOnRequestC *
- Set the following fields of *studnt_:gunOnRequestC *:
*.FLNK *to* studnt_:gunOnC*
*.SDIS *to* studnt_:cathodeTempCheck.VAL*
*.DISV *to* 0*
- Change the following fields of *studnt_:gunOnC *:
- .*DOL* to *studnt_:gunOnRequestC*
- .*OMSL* to closed_loop
*.SDIS *to* *NULL
*.DISV *to* *1
- Use *studnt_:gunOnRequestC *as the operator control on the medm display, but still monitor *studnt_:gunOnC *
- Does this work like you want it to ?
- What happens if the beam is on and the cathode temperature decreases ?

## Beam On Inhibit

- Yet another approach : Use the “Mask” mode of a sequence record to perform a conditional set of operations (i.e turn gun on or reset the request)
- Define a calc record (*studnt_:gunOnRequestCheck*) which yields the following result:
- If *studnt_:gunOnRequestC *is 0, result is 2
- If *studnt_:gunOnRequestC *is 1 and *studnt_:cathodeTempCheck is 0, *result 1
- If *studnt_:gunOnRequestC *is 1 and *studnt_:cathodeTempCheck is 1, *result 4
- Set .*FLNK* to *studnt_:gunOnRequestSQ*
- Set *studnt_:gunOnRequestC.SDIS *to NULL* *and* studnt_:gunOnRequestC.DISV *to* *1
- Define a sequence record (*studnt_:gunOnRequestSQ*) as follows :
- .*SELM* =  Mask, *.SELL *to *studnt_:gunOnRequestCheck.VAL*
*.DLY1 = *0.5, *.DOL1 = *0*, .LNK1* to *studnt_:gunOnRequestC * (cancels request)
*.DLY2 = *0, .*DOL2* = 0, .*LNK2* to *studnt_:gunOnC *to 0 (turns gun off)
*.DLY3 = *0, .*DOL3* = 1, .*LNK3 *to *studnt_:gunOnC *to 0 (turns gun on)

## Open Access Mode

- Add a PV to monitor an “access mode” switch
- Create a bi record named* studnt_:accessMode.*
- .*DTYP* : Bitbus Device
- .*INP* : #L0 N1 P0 S0 @
- .*ZNAM* : Open Access ,   .*ONAM* : No Access
- Keep all power supplies at 0 current if toggle switch is in “Open Access”
- Create a calcout record (*studnt_:psHoldOffCO)* that forces the processing of a sequence record (*studnt_:psHoldOffSQ* ) if the toggle switch is in the “Open Access” state.
- Define the sequence record *studnt_:psHoldOffSQ* to hold the set current of all power supplies to 0. Forward link to another sequence record that finishes the job. Decide on the appropriate way to process these records.

## Beam Alert

- Provide an indication on the I/O panel when beam reaches either faraday cup
- Define a binary output record (*studnt_:beamPresentLedC)* to turn on an LED
- DTYP : Bitbus Device
- OUT  : #L0 N1 P0 S3 @
- ZNAM : No Beam    ONAM : Beam On
- Define an analog output record (*studnt_:beamPresentMeterC)* to drive the panel meter
- DTYP : Bitbus Device
- OUT : #L0 N1 P0 S0 @
- EGUF : 20   EGUL : 0
- Define two calcout records to drive the above records based on the current present at the faraday cups.
**EXTRA CHALLENGE** : Enhance the above implementation by blinking the light if the beam at the faraday cup exceeds 5 mA (Hint : this can be done by adding one record).

## Additional Database Exercises

- Rate-of-change on ao record
- Monitor *studnt_:BM1:setCurrentC.OVAL *(with medm or probe) while changing *studnt_:BM1:setCurrentC.VAL . *
- Set *studnt_:BM1:setCurrentC.OROC *to 10*. *Set* studnt_:BM1:setCurrentC.SCAN *to '1 second'*. *Monitor *studnt_:BM1:setCurrentC.OVAL* again while changing *studnt_:BM1:setCurrentC.VAL.*
- Create a record that indicates when *studnt_:BM1:setCurrentC *has not reached its setpoint (i.e. indicates that it is still ramping). Indicate this on the medm display with a yellow box around the set point text entry.
- I/O Panel - (Make sure these don't interfere with the other uses of the I/O panel)
- Create the necessary records so three LEDs on the I/O panel (0,1,2) count in binary while switch 0 is on and stop counting when the switch is off.
- Create the necessary records so the meter follows the potentiometer when all switches are on.

## Additional Database Exercises

- Add the following lines in ~/ioc/iocBoot/ioclinac/st.cmd
- cd startup
- asSetFilename("CA_ACCESS")
- Change *studnt_:BM1:setCurrentC.ASG *to SUPERUSER.
- Add other security conditions as desired.

- UAG(users) {studnt_}
- ASG(DEFAULT) {
-     RULE(1, READ)
-     RULE(1, WRITE)
- }

- ASG(SUPERUSER) {
-     RULE(1, READ)
-     RULE(1, WRITE) {
-         UAG(users)
-     }
- }

- Implement Channel Access Security such that only *studnt_* can control *studnt_:BM1:setCurrentC.*
- Create an access security configuration file named CA_ACCESS in ~/ioc/iocBoot/ioclinac/.