#!/usr/bin/env python
# -*- coding:utf-8 -*-


# ############################################################################
#  license :
# ============================================================================
#
#  File :        PILCPICOLASTriggerGenerator.py
#
#  Project :     
#
# This file is part of Tango device class.
# 
# Tango is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# Tango is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Tango.  If not, see <http://www.gnu.org/licenses/>.
# 
#
#  $Author :      maxim.stassevich$
#
#  $Revision :    $
#
#  $Date :        $
#
#  $HeadUrl :     $
# ============================================================================
#            This file is generated by POGO
#     (Program Obviously used to Generate tango Object)
# ############################################################################

__all__ = ["PILCPICOLASTriggerGenerator", "PILCPICOLASTriggerGeneratorClass", "main"]

__docformat__ = 'restructuredtext'

import PyTango
import sys
# Add additional import
#----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.additionnal_import) ENABLED START -----#

import PiLCAPI

#----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.additionnal_import

# Device States Description
# ON : 
# OFF : 


class PILCPICOLASTriggerGenerator (PyTango.Device_4Impl):
    """Class to control PICL trigger generator with PICOLAS LED driver"""
    
    # -------- Add you global variables here --------------------------
    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.global_variables) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.global_variables

    def __init__(self, cl, name):
        PyTango.Device_4Impl.__init__(self,cl,name)
        self.debug_stream("In __init__()")
        PILCPICOLASTriggerGenerator.init_device(self)
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.__init__) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.__init__
        
    def delete_device(self):
        self.debug_stream("In delete_device()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.delete_device) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.delete_device

    def init_device(self):
        self.debug_stream("In init_device()")
        self.get_device_properties(self.get_device_class())
        self.attr_External_Trigger_Active_read = 0
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.init_device) ENABLED START -----#
        self.frequency = 0.1
        try:
            self.pilc = PiLCAPI.PiLCAPI(self.PiLCDevice)
            self.set_state(PyTango.DevState.ON)
            self.set_status("Device is in ON state")
        except:
            self.set_state(PyTango.DevState.OFF)
            self.set_status("Not able to connect to pilc device " + self.PiLCDevice)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.init_device

    def always_executed_hook(self):
        self.debug_stream("In always_excuted_hook()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.always_executed_hook) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.always_executed_hook

    # -------------------------------------------------------------------------
    #    PILCPICOLASTriggerGenerator read/write attribute methods
    # -------------------------------------------------------------------------
    
    def write_Frequency_divider(self, attr):
        self.debug_stream("In write_Frequency_divider()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Frequency_divider_write) ENABLED START -----#
        self.pilc.WriteFPGA(PiLCAPI.FREQUENCY_DIVIDER_REGISTER, data)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Frequency_divider_write
        
    def is_Frequency_divider_allowed(self, attr):
        self.debug_stream("In is_Frequency_divider_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Frequency_divider_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Frequency_divider_allowed
        return state_ok
        
    def write_Delay(self, attr):
        self.debug_stream("In write_Delay()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Delay_write) ENABLED START -----#
        if not (data % 20):
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value(((data // 20) + 1) * 20)
         
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Delay_write
        
    def is_Delay_allowed(self, attr):
        self.debug_stream("In is_Delay_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Delay_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Delay_allowed
        return state_ok
    
    def write_Internal_frequency1(self, attr):
        self.debug_stream("In write_Internal_frequency1()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Internal_frequency1_write) ENABLED START -----#
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)
        #----- PROTECTED REGION END -----#    //    PILCPICOLASTriggerGenerator.Internal_frequency1_write
    
    def is_Internal_frequency1_allowed(self, attr):
        self.debug_stream("In is_Internal_frequency1_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Internal_frequency1_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#    //    PILCPICOLASTriggerGenerator.is_Internal_frequency1_allowed
        return state_ok
    
    def write_High_time(self, attr):
        self.debug_stream("In write_High_time()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.High_time_write) ENABLED START -----#
        #self.frequency = 40000000
        if not (data % 20):
            dataToWrite = int(data / 20)
            if data >= (1.0/self.frequency) * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed, "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value(((data // 20) + 1) * 20)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.High_time_write
        
    def is_High_time_allowed(self, attr):
        self.debug_stream("In is_High_time_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_High_time_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_High_time_allowed
        return state_ok
        
    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream("In write_Internal_Generator_Enable()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Internal_Generator_Enable_write) ENABLED START -----#
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Internal_Generator_Enable_write
        
    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream("In is_Internal_Generator_Enable_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Internal_Generator_Enable_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Internal_Generator_Enable_allowed
        return state_ok
        
    def read_External_Trigger_Active(self, attr):
        self.debug_stream("In read_External_Trigger_Active()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.External_Trigger_Active_read) ENABLED START -----#
        attr.set_value(self.attr_External_Trigger_Active_read)
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.External_Trigger_Active_read
        
    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream("In is_External_Trigger_Active_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_External_Trigger_Active_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_External_Trigger_Active_allowed
        return state_ok
            
    def read_attr_hardware(self, data):
        self.debug_stream("In read_attr_hardware()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.read_attr_hardware) ENABLED START -----#
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0
        #print self.attr_Output_read
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.read_attr_hardware


    # -------------------------------------------------------------------------
    #    PILCPICOLASTriggerGenerator command methods
    # -------------------------------------------------------------------------
    

    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.programmer_methods) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.programmer_methods

class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    # -------- Add you global class variables here --------------------------
    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.global_class_variables) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.global_class_variables


    #    Class Properties
    class_property_list = {
        }


    #    Device Properties
    device_property_list = {
        'PiLCDevice':
            [PyTango.DevString, 
            "Name of the PiLC tango device to connect to",
            [] ],
        }


    #    Command definitions
    cmd_list = {
        }


    #    Attribute definitions
    attr_list = {
        'Frequency_divider':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Frequency_divider",
                'min value': "1",
                'Memorized':"true"
            } ],
        'Delay':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Delay",
                'unit': "ns",
                'min value': "20",
                'description': "Delay from the incoming signal to the output signal, ns",
                'Memorized':"true"
            } ],
        'High_time':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "High_time",
                'unit': "ns",
                'min value': "20",
                'description': "High Time from the Output Signal, ns",
                'Memorized':"true"
            } ],
        'Internal_Generator_Enable':
            [[PyTango.DevBoolean,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Internal_Generator_Enable",
                'description': "Internal Frequency generator. false = disable. true = enable",
                'Memorized':"true_without_hard_applied"
            } ],
        'External_Trigger_Active':
            [[PyTango.DevShort,
            PyTango.SCALAR,
            PyTango.READ],
            {
                'label': "External_Trigger_Active",
                'description': "Incoming Signal 1, else 0.",
            } ],
        'Internal_frequency1':
            [[PyTango.DevDouble,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Internal_frequency1",
                'unit': "Hz",
                'max value': "100000",
                'min value': "0.1",
                'Memorized':"true"
            } ],
        }


def main():
    try:
        py = PyTango.Util(sys.argv)
        py.add_class(PILCPICOLASTriggerGeneratorClass, PILCPICOLASTriggerGenerator, 'PILCPICOLASTriggerGenerator')
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.add_classes) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.add_classes

        U = PyTango.Util.instance()
        U.server_init()
        U.server_run()

    except PyTango.DevFailed as e:
        print ('-------> Received a DevFailed exception:', e)
    except Exception as e:
        print ('-------> An unforeseen exception occured....', e)

if __name__ == '__main__':
    main()

f4f134ed3958c5e995800dc0a96822cdd83909a1
<mask token>


class PILCPICOLASTriggerGenerator(PyTango.Device_4Impl):
    <mask token>
    <mask token>

    def delete_device(self):
        self.debug_stream('In delete_device()')
    <mask token>

    def always_executed_hook(self):
        self.debug_stream('In always_excuted_hook()')
    <mask token>
    <mask token>

    def write_Delay(self, attr):
        self.debug_stream('In write_Delay()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)
    <mask token>

    def write_Internal_frequency1(self, attr):
        self.debug_stream('In write_Internal_frequency1()')
        data = attr.get_write_value()
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)
    <mask token>

    def write_High_time(self, attr):
        self.debug_stream('In write_High_time()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            if data >= 1.0 / self.frequency * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed,
                    "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_High_time_allowed(self, attr):
        self.debug_stream('In is_High_time_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream('In write_Internal_Generator_Enable()')
        data = attr.get_write_value()
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)

    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream('In is_Internal_Generator_Enable_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok
    <mask token>

    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream('In is_External_Trigger_Active_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in []
        return state_ok

    def read_attr_hardware(self, data):
        self.debug_stream('In read_attr_hardware()')
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0


class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    class_property_list = {}
    device_property_list = {'PiLCDevice': [PyTango.DevString,
        'Name of the PiLC tango device to connect to', []]}
    cmd_list = {}
    attr_list = {'Frequency_divider': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Frequency_divider', 'min value': '1',
        'Memorized': 'true'}], 'Delay': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Delay', 'unit': 'ns', 'min value': '20',
        'description':
        'Delay from the incoming signal to the output signal, ns',
        'Memorized': 'true'}], 'High_time': [[PyTango.DevUShort, PyTango.
        SCALAR, PyTango.WRITE], {'label': 'High_time', 'unit': 'ns',
        'min value': '20', 'description':
        'High Time from the Output Signal, ns', 'Memorized': 'true'}],
        'Internal_Generator_Enable': [[PyTango.DevBoolean, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Internal_Generator_Enable',
        'description':
        'Internal Frequency generator. false = disable. true = enable',
        'Memorized': 'true_without_hard_applied'}],
        'External_Trigger_Active': [[PyTango.DevShort, PyTango.SCALAR,
        PyTango.READ], {'label': 'External_Trigger_Active', 'description':
        'Incoming Signal 1, else 0.'}], 'Internal_frequency1': [[PyTango.
        DevDouble, PyTango.SCALAR, PyTango.WRITE], {'label':
        'Internal_frequency1', 'unit': 'Hz', 'max value': '100000',
        'min value': '0.1', 'Memorized': 'true'}]}


<mask token>

<mask token>


class PILCPICOLASTriggerGenerator(PyTango.Device_4Impl):
    <mask token>

    def __init__(self, cl, name):
        PyTango.Device_4Impl.__init__(self, cl, name)
        self.debug_stream('In __init__()')
        PILCPICOLASTriggerGenerator.init_device(self)

    def delete_device(self):
        self.debug_stream('In delete_device()')

    def init_device(self):
        self.debug_stream('In init_device()')
        self.get_device_properties(self.get_device_class())
        self.attr_External_Trigger_Active_read = 0
        self.frequency = 0.1
        try:
            self.pilc = PiLCAPI.PiLCAPI(self.PiLCDevice)
            self.set_state(PyTango.DevState.ON)
            self.set_status('Device is in ON state')
        except:
            self.set_state(PyTango.DevState.OFF)
            self.set_status('Not able to connect to pilc device ' + self.
                PiLCDevice)

    def always_executed_hook(self):
        self.debug_stream('In always_excuted_hook()')

    def write_Frequency_divider(self, attr):
        self.debug_stream('In write_Frequency_divider()')
        data = attr.get_write_value()
        self.pilc.WriteFPGA(PiLCAPI.FREQUENCY_DIVIDER_REGISTER, data)

    def is_Frequency_divider_allowed(self, attr):
        self.debug_stream('In is_Frequency_divider_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Delay(self, attr):
        self.debug_stream('In write_Delay()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_Delay_allowed(self, attr):
        self.debug_stream('In is_Delay_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_frequency1(self, attr):
        self.debug_stream('In write_Internal_frequency1()')
        data = attr.get_write_value()
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)

    def is_Internal_frequency1_allowed(self, attr):
        self.debug_stream('In is_Internal_frequency1_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_High_time(self, attr):
        self.debug_stream('In write_High_time()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            if data >= 1.0 / self.frequency * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed,
                    "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_High_time_allowed(self, attr):
        self.debug_stream('In is_High_time_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream('In write_Internal_Generator_Enable()')
        data = attr.get_write_value()
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)

    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream('In is_Internal_Generator_Enable_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def read_External_Trigger_Active(self, attr):
        self.debug_stream('In read_External_Trigger_Active()')
        attr.set_value(self.attr_External_Trigger_Active_read)

    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream('In is_External_Trigger_Active_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in []
        return state_ok

    def read_attr_hardware(self, data):
        self.debug_stream('In read_attr_hardware()')
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0


class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    class_property_list = {}
    device_property_list = {'PiLCDevice': [PyTango.DevString,
        'Name of the PiLC tango device to connect to', []]}
    cmd_list = {}
    attr_list = {'Frequency_divider': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Frequency_divider', 'min value': '1',
        'Memorized': 'true'}], 'Delay': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Delay', 'unit': 'ns', 'min value': '20',
        'description':
        'Delay from the incoming signal to the output signal, ns',
        'Memorized': 'true'}], 'High_time': [[PyTango.DevUShort, PyTango.
        SCALAR, PyTango.WRITE], {'label': 'High_time', 'unit': 'ns',
        'min value': '20', 'description':
        'High Time from the Output Signal, ns', 'Memorized': 'true'}],
        'Internal_Generator_Enable': [[PyTango.DevBoolean, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Internal_Generator_Enable',
        'description':
        'Internal Frequency generator. false = disable. true = enable',
        'Memorized': 'true_without_hard_applied'}],
        'External_Trigger_Active': [[PyTango.DevShort, PyTango.SCALAR,
        PyTango.READ], {'label': 'External_Trigger_Active', 'description':
        'Incoming Signal 1, else 0.'}], 'Internal_frequency1': [[PyTango.
        DevDouble, PyTango.SCALAR, PyTango.WRITE], {'label':
        'Internal_frequency1', 'unit': 'Hz', 'max value': '100000',
        'min value': '0.1', 'Memorized': 'true'}]}


<mask token>

<mask token>


class PILCPICOLASTriggerGenerator(PyTango.Device_4Impl):
    """Class to control PICL trigger generator with PICOLAS LED driver"""

    def __init__(self, cl, name):
        PyTango.Device_4Impl.__init__(self, cl, name)
        self.debug_stream('In __init__()')
        PILCPICOLASTriggerGenerator.init_device(self)

    def delete_device(self):
        self.debug_stream('In delete_device()')

    def init_device(self):
        self.debug_stream('In init_device()')
        self.get_device_properties(self.get_device_class())
        self.attr_External_Trigger_Active_read = 0
        self.frequency = 0.1
        try:
            self.pilc = PiLCAPI.PiLCAPI(self.PiLCDevice)
            self.set_state(PyTango.DevState.ON)
            self.set_status('Device is in ON state')
        except:
            self.set_state(PyTango.DevState.OFF)
            self.set_status('Not able to connect to pilc device ' + self.
                PiLCDevice)

    def always_executed_hook(self):
        self.debug_stream('In always_excuted_hook()')

    def write_Frequency_divider(self, attr):
        self.debug_stream('In write_Frequency_divider()')
        data = attr.get_write_value()
        self.pilc.WriteFPGA(PiLCAPI.FREQUENCY_DIVIDER_REGISTER, data)

    def is_Frequency_divider_allowed(self, attr):
        self.debug_stream('In is_Frequency_divider_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Delay(self, attr):
        self.debug_stream('In write_Delay()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_Delay_allowed(self, attr):
        self.debug_stream('In is_Delay_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_frequency1(self, attr):
        self.debug_stream('In write_Internal_frequency1()')
        data = attr.get_write_value()
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)

    def is_Internal_frequency1_allowed(self, attr):
        self.debug_stream('In is_Internal_frequency1_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_High_time(self, attr):
        self.debug_stream('In write_High_time()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            if data >= 1.0 / self.frequency * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed,
                    "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_High_time_allowed(self, attr):
        self.debug_stream('In is_High_time_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream('In write_Internal_Generator_Enable()')
        data = attr.get_write_value()
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)

    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream('In is_Internal_Generator_Enable_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def read_External_Trigger_Active(self, attr):
        self.debug_stream('In read_External_Trigger_Active()')
        attr.set_value(self.attr_External_Trigger_Active_read)

    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream('In is_External_Trigger_Active_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in []
        return state_ok

    def read_attr_hardware(self, data):
        self.debug_stream('In read_attr_hardware()')
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0


class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    class_property_list = {}
    device_property_list = {'PiLCDevice': [PyTango.DevString,
        'Name of the PiLC tango device to connect to', []]}
    cmd_list = {}
    attr_list = {'Frequency_divider': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Frequency_divider', 'min value': '1',
        'Memorized': 'true'}], 'Delay': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Delay', 'unit': 'ns', 'min value': '20',
        'description':
        'Delay from the incoming signal to the output signal, ns',
        'Memorized': 'true'}], 'High_time': [[PyTango.DevUShort, PyTango.
        SCALAR, PyTango.WRITE], {'label': 'High_time', 'unit': 'ns',
        'min value': '20', 'description':
        'High Time from the Output Signal, ns', 'Memorized': 'true'}],
        'Internal_Generator_Enable': [[PyTango.DevBoolean, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Internal_Generator_Enable',
        'description':
        'Internal Frequency generator. false = disable. true = enable',
        'Memorized': 'true_without_hard_applied'}],
        'External_Trigger_Active': [[PyTango.DevShort, PyTango.SCALAR,
        PyTango.READ], {'label': 'External_Trigger_Active', 'description':
        'Incoming Signal 1, else 0.'}], 'Internal_frequency1': [[PyTango.
        DevDouble, PyTango.SCALAR, PyTango.WRITE], {'label':
        'Internal_frequency1', 'unit': 'Hz', 'max value': '100000',
        'min value': '0.1', 'Memorized': 'true'}]}


<mask token>

<mask token>


class PILCPICOLASTriggerGenerator(PyTango.Device_4Impl):
    """Class to control PICL trigger generator with PICOLAS LED driver"""

    def __init__(self, cl, name):
        PyTango.Device_4Impl.__init__(self, cl, name)
        self.debug_stream('In __init__()')
        PILCPICOLASTriggerGenerator.init_device(self)

    def delete_device(self):
        self.debug_stream('In delete_device()')

    def init_device(self):
        self.debug_stream('In init_device()')
        self.get_device_properties(self.get_device_class())
        self.attr_External_Trigger_Active_read = 0
        self.frequency = 0.1
        try:
            self.pilc = PiLCAPI.PiLCAPI(self.PiLCDevice)
            self.set_state(PyTango.DevState.ON)
            self.set_status('Device is in ON state')
        except:
            self.set_state(PyTango.DevState.OFF)
            self.set_status('Not able to connect to pilc device ' + self.
                PiLCDevice)

    def always_executed_hook(self):
        self.debug_stream('In always_excuted_hook()')

    def write_Frequency_divider(self, attr):
        self.debug_stream('In write_Frequency_divider()')
        data = attr.get_write_value()
        self.pilc.WriteFPGA(PiLCAPI.FREQUENCY_DIVIDER_REGISTER, data)

    def is_Frequency_divider_allowed(self, attr):
        self.debug_stream('In is_Frequency_divider_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Delay(self, attr):
        self.debug_stream('In write_Delay()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_Delay_allowed(self, attr):
        self.debug_stream('In is_Delay_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_frequency1(self, attr):
        self.debug_stream('In write_Internal_frequency1()')
        data = attr.get_write_value()
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)

    def is_Internal_frequency1_allowed(self, attr):
        self.debug_stream('In is_Internal_frequency1_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_High_time(self, attr):
        self.debug_stream('In write_High_time()')
        data = attr.get_write_value()
        if not data % 20:
            dataToWrite = int(data / 20)
            if data >= 1.0 / self.frequency * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed,
                    "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value((data // 20 + 1) * 20)

    def is_High_time_allowed(self, attr):
        self.debug_stream('In is_High_time_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream('In write_Internal_Generator_Enable()')
        data = attr.get_write_value()
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)

    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream('In is_Internal_Generator_Enable_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        return state_ok

    def read_External_Trigger_Active(self, attr):
        self.debug_stream('In read_External_Trigger_Active()')
        attr.set_value(self.attr_External_Trigger_Active_read)

    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream('In is_External_Trigger_Active_allowed()')
        if attr == PyTango.AttReqType.READ_REQ:
            state_ok = not self.get_state() in [PyTango.DevState.OFF]
        else:
            state_ok = not self.get_state() in []
        return state_ok

    def read_attr_hardware(self, data):
        self.debug_stream('In read_attr_hardware()')
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0


class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    class_property_list = {}
    device_property_list = {'PiLCDevice': [PyTango.DevString,
        'Name of the PiLC tango device to connect to', []]}
    cmd_list = {}
    attr_list = {'Frequency_divider': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Frequency_divider', 'min value': '1',
        'Memorized': 'true'}], 'Delay': [[PyTango.DevUShort, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Delay', 'unit': 'ns', 'min value': '20',
        'description':
        'Delay from the incoming signal to the output signal, ns',
        'Memorized': 'true'}], 'High_time': [[PyTango.DevUShort, PyTango.
        SCALAR, PyTango.WRITE], {'label': 'High_time', 'unit': 'ns',
        'min value': '20', 'description':
        'High Time from the Output Signal, ns', 'Memorized': 'true'}],
        'Internal_Generator_Enable': [[PyTango.DevBoolean, PyTango.SCALAR,
        PyTango.WRITE], {'label': 'Internal_Generator_Enable',
        'description':
        'Internal Frequency generator. false = disable. true = enable',
        'Memorized': 'true_without_hard_applied'}],
        'External_Trigger_Active': [[PyTango.DevShort, PyTango.SCALAR,
        PyTango.READ], {'label': 'External_Trigger_Active', 'description':
        'Incoming Signal 1, else 0.'}], 'Internal_frequency1': [[PyTango.
        DevDouble, PyTango.SCALAR, PyTango.WRITE], {'label':
        'Internal_frequency1', 'unit': 'Hz', 'max value': '100000',
        'min value': '0.1', 'Memorized': 'true'}]}


def main():
    try:
        py = PyTango.Util(sys.argv)
        py.add_class(PILCPICOLASTriggerGeneratorClass,
            PILCPICOLASTriggerGenerator, 'PILCPICOLASTriggerGenerator')
        U = PyTango.Util.instance()
        U.server_init()
        U.server_run()
    except PyTango.DevFailed as e:
        print('-------> Received a DevFailed exception:', e)
    except Exception as e:
        print('-------> An unforeseen exception occured....', e)


if __name__ == '__main__':
    main()

#!/usr/bin/env python
# -*- coding:utf-8 -*-


# ############################################################################
#  license :
# ============================================================================
#
#  File :        PILCPICOLASTriggerGenerator.py
#
#  Project :     
#
# This file is part of Tango device class.
# 
# Tango is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# Tango is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Tango.  If not, see <http://www.gnu.org/licenses/>.
# 
#
#  $Author :      maxim.stassevich$
#
#  $Revision :    $
#
#  $Date :        $
#
#  $HeadUrl :     $
# ============================================================================
#            This file is generated by POGO
#     (Program Obviously used to Generate tango Object)
# ############################################################################

__all__ = ["PILCPICOLASTriggerGenerator", "PILCPICOLASTriggerGeneratorClass", "main"]

__docformat__ = 'restructuredtext'

import PyTango
import sys
# Add additional import
#----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.additionnal_import) ENABLED START -----#

import PiLCAPI

#----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.additionnal_import

# Device States Description
# ON : 
# OFF : 


class PILCPICOLASTriggerGenerator (PyTango.Device_4Impl):
    """Class to control PICL trigger generator with PICOLAS LED driver"""
    
    # -------- Add you global variables here --------------------------
    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.global_variables) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.global_variables

    def __init__(self, cl, name):
        PyTango.Device_4Impl.__init__(self,cl,name)
        self.debug_stream("In __init__()")
        PILCPICOLASTriggerGenerator.init_device(self)
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.__init__) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.__init__
        
    def delete_device(self):
        self.debug_stream("In delete_device()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.delete_device) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.delete_device

    def init_device(self):
        self.debug_stream("In init_device()")
        self.get_device_properties(self.get_device_class())
        self.attr_External_Trigger_Active_read = 0
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.init_device) ENABLED START -----#
        self.frequency = 0.1
        try:
            self.pilc = PiLCAPI.PiLCAPI(self.PiLCDevice)
            self.set_state(PyTango.DevState.ON)
            self.set_status("Device is in ON state")
        except:
            self.set_state(PyTango.DevState.OFF)
            self.set_status("Not able to connect to pilc device " + self.PiLCDevice)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.init_device

    def always_executed_hook(self):
        self.debug_stream("In always_excuted_hook()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.always_executed_hook) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.always_executed_hook

    # -------------------------------------------------------------------------
    #    PILCPICOLASTriggerGenerator read/write attribute methods
    # -------------------------------------------------------------------------
    
    def write_Frequency_divider(self, attr):
        self.debug_stream("In write_Frequency_divider()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Frequency_divider_write) ENABLED START -----#
        self.pilc.WriteFPGA(PiLCAPI.FREQUENCY_DIVIDER_REGISTER, data)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Frequency_divider_write
        
    def is_Frequency_divider_allowed(self, attr):
        self.debug_stream("In is_Frequency_divider_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Frequency_divider_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Frequency_divider_allowed
        return state_ok
        
    def write_Delay(self, attr):
        self.debug_stream("In write_Delay()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Delay_write) ENABLED START -----#
        if not (data % 20):
            dataToWrite = int(data / 20)
            self.pilc.WriteFPGA(PiLCAPI.DELAY_REGISTER, dataToWrite)
        else:
            attr.set_write_value(((data // 20) + 1) * 20)
         
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Delay_write
        
    def is_Delay_allowed(self, attr):
        self.debug_stream("In is_Delay_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Delay_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Delay_allowed
        return state_ok
    
    def write_Internal_frequency1(self, attr):
        self.debug_stream("In write_Internal_frequency1()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Internal_frequency1_write) ENABLED START -----#
        self.frequency = data
        dataToWrite = data * 10
        self.pilc.WriteFPGA(PiLCAPI.INTERNAL_FREQUENCY_REGISTER, dataToWrite)
        #----- PROTECTED REGION END -----#    //    PILCPICOLASTriggerGenerator.Internal_frequency1_write
    
    def is_Internal_frequency1_allowed(self, attr):
        self.debug_stream("In is_Internal_frequency1_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Internal_frequency1_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#    //    PILCPICOLASTriggerGenerator.is_Internal_frequency1_allowed
        return state_ok
    
    def write_High_time(self, attr):
        self.debug_stream("In write_High_time()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.High_time_write) ENABLED START -----#
        #self.frequency = 40000000
        if not (data % 20):
            dataToWrite = int(data / 20)
            if data >= (1.0/self.frequency) * 1000000000:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, 100)
                attr.set_write_value(100)
                PyTango.Except.throw_exception(PyTango.DevFailed, "Pulse width couldn't be bigger than Period")
            else:
                self.pilc.WriteFPGA(PiLCAPI.HIGH_TIME_REGISTER, dataToWrite)
        else:
            attr.set_write_value(((data // 20) + 1) * 20)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.High_time_write
        
    def is_High_time_allowed(self, attr):
        self.debug_stream("In is_High_time_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_High_time_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_High_time_allowed
        return state_ok
        
    def write_Internal_Generator_Enable(self, attr):
        self.debug_stream("In write_Internal_Generator_Enable()")
        data = attr.get_write_value()
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.Internal_Generator_Enable_write) ENABLED START -----#
        if data:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 1)
        else:
            self.pilc.WriteFPGA(PiLCAPI.INTERNAL_GENERATOR_ENABLE_REGISTER, 0)
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.Internal_Generator_Enable_write
        
    def is_Internal_Generator_Enable_allowed(self, attr):
        self.debug_stream("In is_Internal_Generator_Enable_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_Internal_Generator_Enable_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_Internal_Generator_Enable_allowed
        return state_ok
        
    def read_External_Trigger_Active(self, attr):
        self.debug_stream("In read_External_Trigger_Active()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.External_Trigger_Active_read) ENABLED START -----#
        attr.set_value(self.attr_External_Trigger_Active_read)
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.External_Trigger_Active_read
        
    def is_External_Trigger_Active_allowed(self, attr):
        self.debug_stream("In is_External_Trigger_Active_allowed()")
        if attr==PyTango.AttReqType.READ_REQ:
            state_ok = not(self.get_state() in [PyTango.DevState.OFF])
        else:
            state_ok = not(self.get_state() in [])
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.is_External_Trigger_Active_allowed) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.is_External_Trigger_Active_allowed
        return state_ok
            
    def read_attr_hardware(self, data):
        self.debug_stream("In read_attr_hardware()")
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.read_attr_hardware) ENABLED START -----#
        if self.pilc.ReadFPGA(PiLCAPI.EXTERNAL_TRIGGER_ACTIVE_REGISTER):
            self.attr_External_Trigger_Active_read = 1
        else:
            self.attr_External_Trigger_Active_read = 0
        #print self.attr_Output_read
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.read_attr_hardware


    # -------------------------------------------------------------------------
    #    PILCPICOLASTriggerGenerator command methods
    # -------------------------------------------------------------------------
    

    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.programmer_methods) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.programmer_methods

class PILCPICOLASTriggerGeneratorClass(PyTango.DeviceClass):
    # -------- Add you global class variables here --------------------------
    #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.global_class_variables) ENABLED START -----#
    
    #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.global_class_variables


    #    Class Properties
    class_property_list = {
        }


    #    Device Properties
    device_property_list = {
        'PiLCDevice':
            [PyTango.DevString, 
            "Name of the PiLC tango device to connect to",
            [] ],
        }


    #    Command definitions
    cmd_list = {
        }


    #    Attribute definitions
    attr_list = {
        'Frequency_divider':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Frequency_divider",
                'min value': "1",
                'Memorized':"true"
            } ],
        'Delay':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Delay",
                'unit': "ns",
                'min value': "20",
                'description': "Delay from the incoming signal to the output signal, ns",
                'Memorized':"true"
            } ],
        'High_time':
            [[PyTango.DevUShort,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "High_time",
                'unit': "ns",
                'min value': "20",
                'description': "High Time from the Output Signal, ns",
                'Memorized':"true"
            } ],
        'Internal_Generator_Enable':
            [[PyTango.DevBoolean,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Internal_Generator_Enable",
                'description': "Internal Frequency generator. false = disable. true = enable",
                'Memorized':"true_without_hard_applied"
            } ],
        'External_Trigger_Active':
            [[PyTango.DevShort,
            PyTango.SCALAR,
            PyTango.READ],
            {
                'label': "External_Trigger_Active",
                'description': "Incoming Signal 1, else 0.",
            } ],
        'Internal_frequency1':
            [[PyTango.DevDouble,
            PyTango.SCALAR,
            PyTango.WRITE],
            {
                'label': "Internal_frequency1",
                'unit': "Hz",
                'max value': "100000",
                'min value': "0.1",
                'Memorized':"true"
            } ],
        }


def main():
    try:
        py = PyTango.Util(sys.argv)
        py.add_class(PILCPICOLASTriggerGeneratorClass, PILCPICOLASTriggerGenerator, 'PILCPICOLASTriggerGenerator')
        #----- PROTECTED REGION ID(PILCPICOLASTriggerGenerator.add_classes) ENABLED START -----#
        
        #----- PROTECTED REGION END -----#	//	PILCPICOLASTriggerGenerator.add_classes

        U = PyTango.Util.instance()
        U.server_init()
        U.server_run()

    except PyTango.DevFailed as e:
        print ('-------> Received a DevFailed exception:', e)
    except Exception as e:
        print ('-------> An unforeseen exception occured....', e)

if __name__ == '__main__':
    main()
