Hello, Sidekick System!¶
A simple example showing how to print out some variables from your sidekick system, and set some as well. Uses the "pyepics" code.
Run this from a laptop on your same network as the sidekick devices.
Start this Python kernel after joining the proper network.
References:¶
In [1]:
Copied!
import epics
import epics
Read some values!¶
In [2]:
Copied!
epics.caget("LEDS:info")
epics.caget("LEDS:info")
Out[2]:
'DolphinDAQ,Arduino LEDs,#00,v0.1'
In [3]:
Copied!
epics.caget("SHUTTER:info")
epics.caget("SHUTTER:info")
Out[3]:
'DolphinDAQ,Arduino Shutter,#00,v0.1'
In [9]:
Copied!
epics.caget("PULSEGEN:info")
epics.caget("PULSEGEN:info")
Out[9]:
'DolphinDAQ,Arduino PulseGen,#00,v0.2'
In [10]:
Copied!
epics.caget("LEDS:CH0:dur") # Read pulse duration of LED#0
epics.caget("LEDS:CH0:dur") # Read pulse duration of LED#0
Out[10]:
200000.0
You should get "200000.0" above. If you got "None" instead, you're not establishing a proper connection to the EPICS sidekick system. Check your network connection and try again!
Examine fields other than just the value¶
Examining individual fields¶
In [6]:
Copied!
print("PV Name: ", epics.caget("PULSEGEN:CH2:delay.NAME"))
print("PV Value: ", epics.caget("PULSEGEN:CH2:delay.VAL"))
print("PV Description: ", epics.caget("PULSEGEN:CH2:delay.DESC"))
print("PV Units: ", epics.caget("PULSEGEN:CH2:delay.EGU"))
print("PV Name: ", epics.caget("PULSEGEN:CH2:delay.NAME"))
print("PV Value: ", epics.caget("PULSEGEN:CH2:delay.VAL"))
print("PV Description: ", epics.caget("PULSEGEN:CH2:delay.DESC"))
print("PV Units: ", epics.caget("PULSEGEN:CH2:delay.EGU"))
PV Name: PULSEGEN:CH2:delay PV Value: 2000.0 PV Description: Set pulse delay time PV Units: micros
In [7]:
Copied!
channel = "SHUTTER:dur"
for field, label in zip(["NAME", "VAL", "DESC", "EGU"], ["Name", "Value", "Description", "Units"]):
print("PV " + label + ": ", epics.caget(channel + "." + field))
channel = "SHUTTER:dur"
for field, label in zip(["NAME", "VAL", "DESC", "EGU"], ["Name", "Value", "Description", "Units"]):
print("PV " + label + ": ", epics.caget(channel + "." + field))
PV Name: SHUTTER:dur PV Value: 500000.0 PV Description: Set shutter-open duration (output) PV Units: micros
Examining all info about a PV¶
Or even more efficiently, we could just use the "cainfo" method!
In [8]:
Copied!
epics.cainfo("PULSEGEN:CH2:delay")
epics.cainfo("PULSEGEN:CH2:delay")
== PULSEGEN:CH2:delay (time_double) == value = 2000 char_value = '2000' count = 1 nelm = 1 type = time_double units = micros precision = 0 host = epics1.epics-net:5064 access = read/write status = 0 char_status= NO_ALARM severity = 0 char_severity = NO_ALARM timestamp = 631152000.000 (1989-12-31 16:00:00.00000) posixseconds = 631152000.0 nanoseconds= 0 upper_ctrl_limit = 4294967295.0 lower_ctrl_limit = 0.0 upper_disp_limit = 0.0 lower_disp_limit = 0.0 upper_alarm_limit = 0.0 lower_alarm_limit = 0.0 upper_warning_limit = 0.0 lower_warning_limit = 0.0 PV is internally monitored, with 0 user-defined callbacks: =============================
Set some values!¶
In [9]:
Copied!
epics.caput("LEDS:CH0:brig", 0) # Suppress output from LED #0 by setting brightness to "0" (out of 255)
epics.caput("LEDS:CH0:brig", 0) # Suppress output from LED #0 by setting brightness to "0" (out of 255)
Out[9]:
1
In [10]:
Copied!
epics.caput("LEDS:CH3:brig", 255) # Maximize brightness from LED #3 by setting brightness to "255" (out of 255)
epics.caput("LEDS:CH3:brig", 255) # Maximize brightness from LED #3 by setting brightness to "255" (out of 255)
Out[10]:
1
In [11]:
Copied!
epics.caput("LEDS:CH5:dur", 500e3) # Maximize brightness from LED #3 by setting brightness to "255" (out of 255)
epics.caput("LEDS:CH5:dur", 500e3) # Maximize brightness from LED #3 by setting brightness to "255" (out of 255)
Out[11]:
1
Object-Oriented Approach¶
The above uses procedural methods like "caget", "caput", and "cainfo". There is also an object-oriented approach in pyepics that can be quite powerful.
In [12]:
Copied!
from epics import PV
from epics import PV
In [13]:
Copied!
mypv = PV('LEDS:CH4:brig.VAL')
mypv.get() # Get brightness of LED #4
mypv = PV('LEDS:CH4:brig.VAL')
mypv.get() # Get brightness of LED #4
Out[13]:
200
In [14]:
Copied!
mypv.put(255) # Maximize brightness from LED #4 by setting brightness to "255" (out of 255)
mypv.put(255) # Maximize brightness from LED #4 by setting brightness to "255" (out of 255)
Out[14]:
1