"""
EPICS direct channel access.
EPICS devices implemented are included in PShell, package ch.psi.pshell.epics.
However direct channel access builtin functions are available.
"""

channel_name = "TESTIOC:TESTCALCOUT:Output"

#reading/writing to a channel
print (caget(channel_name))
caput(channel_name, 0.0)
#Put with no wait
caput(channel_name, 0.0)
print (caget(channel_name))

#waiting for a channel valur
cawait(channel_name, 0.0, timeout = 10.0)

#If many IO it is better to keep the same CA connection
channel = Channel(channel_name, 'd')
for i in range(100):
    print channel.get()
lscan(channel, (ai2,channel), 0, 10, 0.1)

#The channel class implements Readable and Writable and therefore can be used in scans
lscan(channel, ai2, 0, 10, 0.1)

#Or else we can use a Device
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
channel = ChannelDouble("My Channel", channel_name)
channel.initialize()