Phoenix Library Functions in Python Language
object = module_name.class_name()
Creates an object of class 'phoenix' from module 'phoenix'
The constructor method, __init__(), of 'phoenix' class opens the device driver.
For this to succeed the device driver phdriver should be loaded and the device file '/dev/phoenix' should exist.
/etc/rc.d/rc.local should have the scripts to load the driver during startup.
Only one program can use the driver at a time
import phoenix
p = phoenix.phoenix()

integer = read_inputs ()
Returns the status of the four Digital Input pins in a 4 bit integer.  Returns a value from 0 to 15 depends on the voltage levels present.
data = p.read_inputs()

None = write_outputs (integer dat)
Writes a value of 'dat' from 0 to 255 to the eight digital output pins of Phoenix. # Sets lower four pins to HIGH, rest to LOW

p.write_outputs(15)

None = set_dac (integer val)
Sets the 8 bit DAC output from -5V to +5V depends on the argument given.
val  : from 0 to 255
# Sets the DAC to nearly zero volt

p.set_dac(128)

None = set_voltage (float mv)
Sets DAC output from -5V to +5V depends on the argument 'mv'. The arguments ranges from -5000 to +5000 millivolts # Sets the DAC to one volt

p.set_voltage(1000.0)

None = rotate_motor (integer nsteps, integer dir)
Rotates the Stepper Motor. nsteps denotes the no. of steps and dir denotes the direction (1-clock & 0-anticlock). # Takes 100 steps in clockwise direction

p.rotate_motor(100,1)

None = write_motor (integer dat)
Writes values in between 0 and 15 to Stepper Motor Outputs. dat denotes the value to stepper motor outputs. # Energises coil A of stepper motor

p.write_motor(1)

None = select_adc (integer chan)
Selects the ADC channel to be digitized
There are four channels (0 to 3)
Adding 4 to the channel number will do the next digitization without sampling the input. Uses the voltage held by the HOLD capacitor during the last digitization.
p. select_adc(0)   # Selects channel 0
val = p.read_adc()[0]   # samples and digitizes channel 0

p. select_adc(0+4)
# next read_adc will not sample the input

[float, integer] = read_adc ()
Reads analog input. Returns a list containing the value read from ADC and a Timestamp. The timestamp is used only for measuring the time difference between two calls and not as absolute value of it.
res = p. read_adc()
timestamp= res[0]
voltage= res[1]

[float, float] = zero_to_5000 ()
Returns voltage in millivolts (0 to 5000mV) from the ADC along with the time stamp. First item in the list is timestamp and second is voltage
res = p.zero_to_5000()
print 'voltage = ', res[1]

[float, float] = minus5000_to_5000 ()
Returns the voltage in between -5000 mV to +5000 mV corresponding to the value read from ADC. Use this when you giving signal through the (x+5)/2 amplifier
//print value of volatge at the ADC input
print p.minus5000To5000()[1]

[(float ts, float adval),....] = read_block (integer npoints, integer delay, integer bipolar)
Digitizes the ADC input
npoints: number of digitizations. ( maximum 1024)
delay   : interval between two digitizations (min.115 usecs)
bipolar: If TRUE returns -5000 to 5000 else 0 to 5000 mV
ts : array to return the time stamps
adval   : array  to return voltage in mv.
#256 points, 200 usec apart, using (x+5)/2 amplifier

result = p.read_block (256, 200, 1)
for k in range(256):
      print result[k][0], ' ', result[k][1]

[(float ts, float ad0, float  ad1, ..), ..] = multi_read_block (integer npoints, integer nchan, integer delay, integer bipolar)
Digitizes the ADC inputs (multiple channels)
npoints : number of digitizations.(maximum 1024)
nchan   : number of channels (1 to 4). Starts with zero only.
delay    : interval between two digitizations(min.115 usecs)
ts          : time stamp
ad0,ad1,ad2,ad3 : data (fills only the first  nchan ones)
This routine does simultaneous sampling of all the channels and digitizes them one by one.
#digitize and print two bipolar channels with timestamp
result = p.multi_read_block (256, 2, 200,2,1)
for k in range(256):
      print result[k][0], ' ', result[k][1], ' ', result[k][2]

[(float ts, integer adval),....] =
trig_read_block (integer pin, integer npoints, integer deadtime,  integer delay,  integer trig_pol,  integer bipolar)
Digitization of the ADC is triggered by an edge on 'pin'.
pin        : Digital input pin (0 to 3)
npoints : number of digitizations.( maximum 1024)
deadtime: time interval from the Edge to the first digitization.
delay    : between digitizations
trig_pol : trigger polarity (rising or falling edge)
bipolar :  1 if (x+5)/2 amplifier is used, else 0
ts          : time stamps
adval    : adc output
pin = 0
tp = 0
dt = 0
delay = 200
result = p.trig_read_block (pin, 256, dt, delay, tp, 1)
for x in range(256):
      print result[i][0], ' ', result[i][1]

float  = period (integer bit)
Measures the time interval for 10 cycles of the input signal, to calculate and return the Period of the signal, at the digital input pin specified as argument.
Return values in microseconds for all time measurements
# Sets the data to time period of the signal at Dig Input 0

data = p. period (0)

float = r2rtime (integer pin1, integer pin2)
Returns the time interval between a rising edge on pin1 to a rising edge on pin2.  If same pin is specified it will return the time interval between two consecutive rising edges. # Gets the time interval between a rising edge on pin0 to a # rising edge on pin1 in usec.

data=r2rtime(0,1)

float =  r2ftime (integer pin1, integer pin2)
Returns the time interval between a rising edge on pin1 to a falling edge on pin2. If same pin is specified it will return the 'high time' of the TTL pulse fed to that pin. Also used for testing the accuracy of the system.
data=p.r2ftime (0,1)

float = f2rtime (integer pin1, integer pin2)
Returns the time interval between a falling edge on pin1 to a rising edge on pin2. If same pin is specified it will return the 'low time' of the TTLpulse fed to that pin. # Sets the data to time interval between a falling edge on # pin0 to a rising edge on pin1 in usec.
 
data=p.f2rtime(0,1)

float = f2ftime (integer pin1, integer pin2)
Returns the time interval between a falling edge on pin1 to a falling edge on pin2. If same pin is specified it will return the time between two consecutive falling edges. #Sets the data to time interval between a falling edge on # pin0 to a falling edge on pin1 in usec.

data=p.f2ftime(0,1)

float = set2rtime (integer pin1, integer pin2)
Returns the time interval from setting a bit on output pin1 to the rising edge on input pin2.
pin1 : 0 to 7 means the Digital output pins.
          8 to 11 means stepper motor outputs   
          A,B,C and D
pin2 : Input pins 0 to 3
# Sets the data to time interval from setting output pin0 to # the rising edge on an input pin0 in usec.


data=p.set2rtime(0,0)

float = set2ftime  (integer pin1, integer pin2)
Returns the time interval from setting a bit on output pin1 to the falling edge on input pin2.
pin1 : 0 to 7 means the Digital output pins.
          8 to11 means stepper motor outputs    
          A,B,C and D
pin2 : Input pins 0 to 3
# Sets the data to time interval from setting output pin0 to # the falling edge on an input pin0 in usec.


data=p.set2ftime(0,0)

float = clr2rtime (integer pin1, integer pin2)
Returns the time interval from clearing the output pin1 to the rising edge on input pin2.
pin1 : 0 to 7 means the Digital output pins.
          8 to11 means stepper motor outputs    
          A,B,C and D
pin2 : Input pins 0 to 3
# Sets the data to time interval from clearing output pin0 # to the rising edge on an input pin0 in usec.


data=p.clr2rtime(0,0)

float = clr2ftime (integer pin1, integer pin2)
 Returns the time interval from clearing the output pin1 to the falling edge on input pin2.
pin1 : 0 to 7 means the Digital output pins.
          8 to11 means stepper motor outputs    
          A,B,C and D
pin2 : Input pins 0 to 3
# Sets the data to time interval from clearing output pin0  # to the falling edge on an input pin0 in usec.


data = p.clr2ftime(0,0)

float = pulse2rtime (integer pin1, integer pin2, integer width, integer deadtime, integer pol)
Generates a pulse on pin1 and returns the time interval from that pulse to the rising edge on pin2.
pin1  : 0 to 7 for digital outputs, 8 to 11 for
           stepper motor outputs
pin2  : 0 to 3
width: width of the pulse, Assumes the output
           was zero when called
deadtime: Starts waiting only after elapsing
                 deadtime.
pol: 0 -> HIGH TRUE TTL (1 -> LOW TRUE)
"""
Sets the data to time interval from  a 2 usec wide pulse output pin0 to a rising edge on pin 0.
Deadtime of 10 usec. LOW TRUE TTL pulse.
"""

data=p.pulse2rtime(0,0,2,10,1)

float = pulse2ftime (integer pin1, integer pin2, integer width, integer deadtime, integer pol)
Generates a pulse on pin1 and returns the time interval from that pulse to the falling edge on pin2.

pin1  : 0 to 7 for digital outputs, 8 to 11 for
           stepper motor outputs
pin2  : 0 to 3
width: width of the pulse, Assumes the output
           was zero when called
deadtime: Starts waiting only after elapsing
                 deadtime.
pol: 0 -> HIGH TRUE TTL (1 -> LOW TRUE)
// Sets the data to time interval from  a 2 usec wide pulse output pin0 to a falling edge on pin 0.
Deadtime of 10 usec. LOW TRUE TTL pulse.
  

data=p.pulse2ftime(0,0,2,10,1)

float = mid_high_time (integer pin)
Returns the time of occurance of a Positive TTL pulse on the specified digital input. This function is used for measuring time intervals in the order of seconds by subtracting the values from two calls.
data= p.mid_high_time (0)

float = mid_low_time (integer pin)
Returns the time of occurance of a Negative TTL pulse on the specified digital input. This function is used for measuring time intervals in the order of seconds by subtracting the values from two calls.
data=p.mid_low_time (0)

None = pulse_out (integer pin, integer high, integer low, integer np, integer pol)
Generates a pulse on a digital output or the stepper motor output pin.
pin   : 0 to 7 means the bits on digital output. 
          8 tp 11 means Stepper Motor outputs.
high : HIGH time of the pulse in usecs
low   : LOW time of the pulse in usecs
np    : number of pulses to be generated
pol   : 0 -> HIGH TRUE TTL (1 -> LOW TRUE)
"""Generates 10 HIGH TRUE TTL pulses of 10usec width and a total time period of 100usec  on digital output pin1."""


p.pulse_out (1,10,90,10, 0)

None = set_timeout (integer  usecs)
Time measurement calls waits inside the kernel and freezes the system for that period. It is essential to provide maximum limits for waiting.The default is around 2 seconds.This can be set between 5 m sec and 5 sec.
p.set_timeout (1000)