def register(instance_name, *device_names): """Register device with a SDPSubarray device server instance. If the device is already registered, do nothing. :param instance_name: Instance name SDPSubarray device server :param device_names: Subarray device names to register """ # pylint: disable=protected-access try: tango_db = Database() class_name = 'SDPSubarray' server_name = '{}/{}'.format(class_name, instance_name) devices = list(tango_db.get_device_name(server_name, class_name)) device_info = DbDevInfo() device_info._class = class_name device_info.server = server_name for device_name in device_names: device_info.name = device_name if device_name in devices: LOG.debug("Device '%s' already registered", device_name) continue LOG.info('Registering device: %s (server: %s, class: %s)', device_info.name, server_name, class_name) tango_db.add_device(device_info) except ConnectionFailed: pass
def get_dev_info(domain_name, device_server_name, device_ref): dev_info = DbDevInfo() dev_info._class = device_server_name dev_info.server = '%s/%s' % (device_server_name, domain_name) # add the device dev_info.name = '%s/%s' % (domain_name, device_ref) return dev_info
def main(): db = Database() """Add device server motor""" new_device_name = "x/foo/motor" new_device_info_motor = DbDevInfo() new_device_info_motor._class = "DS_Motor" new_device_info_motor.server = "DS_Motor/aalonso" print("Creating device: %s" % new_device_name) new_device_info_motor.name = new_device_name db.add_device(new_device_info_motor)
def register_master(): """Register the SDP Master device.""" tango_db = Database() device = "sip_sdp/elt/master" device_info = DbDevInfo() device_info._class = "SDPMasterDevice" device_info.server = "sdp_master_ds/1" device_info.name = device devices = tango_db.get_device_name(device_info.server, device_info._class) if device not in devices: LOG.info('Registering device "%s" with device server "%s"', device_info.name, device_info.server) tango_db.add_device(device_info)
def register_subarray_devices(): """Register subarray devices.""" tango_db = Database() LOG.info("Registering Subarray devices:") device_info = DbDevInfo() # pylint: disable=protected-access device_info._class = "SubarrayDevice" device_info.server = "subarray_ds/1" for index in range(16): device_info.name = "siid_sdp/elt/subarray_{:02d}".format(index) LOG.info("\t%s", device_info.name) tango_db.add_device(device_info) tango_db.put_class_property(device_info._class, dict(version='1.0.0'))
def register_subarray_devices(): """Register subarray devices.""" tango_db = Database() LOG.info("Registering Subarray devices:") device_info = DbDevInfo() # pylint: disable=protected-access device_info._class = "SubarrayDevice" device_info.server = "subarray_ds/1" for index in range(16): device_info.name = "sip_sdp/elt/subarray_{:02d}".format(index) LOG.info("\t%s", device_info.name) tango_db.add_device(device_info) tango_db.put_class_property(device_info._class, dict(version='1.0.0'))
def __register_server(server_type, server_instance, domain=None, family='bliss', member=None, klass=None, db=None): beamline = os.environ.get('BEAMLINENAME', 'bliss') server_name = '{0}/{1}'.format(server_type, server_instance) domain = domain or beamline member = member or server_instance klass = klass or server_type db = db or Database() dev_name = '{0}/{1}/{2}'.format(domain, family, member) config_dir = '~/local/beamline_control' config_file = os.path.join(config_dir, '{0}.yml'.format(beamline)) # try to find which configuration file to use. # if we are not able we ask the user. print_("'{0}' is not configured yet.".format(server_instance)) if not os.path.exists(os.path.expanduser(config_file)): config_file = '' config_file = raw_input('config. file [{0}]? '.format(config_file)) or \ config_file config_file = os.path.expanduser(config_file) if not config_file: print_('No configuration file was given. Exiting...') sys.exit(-1) if not os.path.exists(os.path.expanduser(config_file)): print_('Could not find configuration file. Exiting...') sys.exit(-2) properties = dict(config_file=config_file) # ask the user for the session name session_name = server_instance session_name = raw_input('session name {0}? '.format(session_name)) or \ session_name if session_name != server_instance: properties['session_name'] = session_name _log.info("registering new server: %s with %s device %s", server_name, klass, dev_name) info = DbDevInfo() info.server = server_name info._class = klass info.name = dev_name db.add_device(info) db.put_device_property(dev_name, dict(config_file=config_file))
def register_pb_devices(num_pbs: int = 100): """Register PBs devices. Note(BMo): Ideally we do not want to register any devices here. There does not seem to be a way to create a device server with no registered devices in Tango. This is (probably) because Tango devices must have been registered before the server starts ... """ tango_db = Database() LOG.info("Registering PB devices:") dev_info = DbDevInfo() # pylint: disable=protected-access dev_info._class = 'ProcessingBlockDevice' dev_info.server = 'processing_block_ds/1' for index in range(num_pbs): dev_info.name = 'sip_sdp/pb/{:05d}'.format(index) LOG.info("\t%s", dev_info.name) tango_db.add_device(dev_info)
async def attribute_event_generator(self, configuration): config = json.loads(configuration) attr = config["attribute"] number_of_events = int(config["number_of_events"]) event_delay = config["event_delay"] polled = self.is_attribute_polled(attr) while number_of_events > 0: await asyncio.sleep(event_delay) # using _classname in calls to setattr and getattr due to name mangling # noqa E501 next_value = getattr(self, f"_TestDevice__{attr}") + 1 setattr(self, f"_TestDevice__{attr}", next_value) if not polled: self.push_change_event(attr, next_value) number_of_events -= 1 if __name__ == "__main__": db = Database() test_device = DbDevInfo() if "DEVICE_NAME" in os.environ: # DEVICE_NAME should be in the format domain/family/member test_device.name = os.environ["DEVICE_NAME"] else: # fall back to default name test_device.name = "test/device/1" test_device._class = "TestDevice" test_device.server = "TestDevice/test" db.add_server(test_device.server, test_device, with_dserver=True) TestDevice.run_server()
# -*- coding: utf-8 -*- """Python script to register device""" from tango import Database, DbDevInfo # http://pytango.readthedocs.io/en/stable/database.html db = Database() # Define the tango Class served by this DServer device_info = DbDevInfo() device_info.name = 'sip_SDP/test/1' device_info._class = 'Test' device_info.server = 'Test/test' print('Adding device: %s' % device_info.name) # NOTE: This also adds the server defined by device_info.server to the db db.add_device(device_info)
from tango import Database, DbDevInfo import sys print(sys.argv[1]) device = sys.argv[1] #sys.exit(0) # A reference on the DataBase db = Database() # The 3 devices name we want to create # Note: these 3 devices will be served by the same DServer new_device_name1 = "event/station/" + device #new_device_name2 = "px1/tdl/mouse2" #new_device_name3 = "px1/tdl/mouse3" # Define the Tango Class served by this DServer new_device_info = DbDevInfo() new_device_info._class = "EventStation" new_device_info.server = "EventStation/" + device # add the first device print("Creating device: %s" % new_device_name1) new_device_info.name = new_device_name1 db.add_device(new_device_info)