Exemplo n.º 1
0
	def create_esi_db(self, db_name):
		try:
			if os.path.exists(db_name):
				os.remove(db_name)
				YoUtil.debug_print('DB file deleted:',db_name)	
			self.con = sqlite3.connect(db_name)
			cur = self.con.cursor()
			YoUtil.debug_print('SQLite version: ',cur.fetchone())	
			with self.con:
				cur.execute("CREATE TABLE IF NOT EXISTS Vendors(VendorId INT, Name TEXT, Path TEXT, App TEXT)")
				cur.execute("CREATE TABLE IF NOT EXISTS Devices(VendorId INT, productCode INT, revisionNumber INT, Name TEXT, Xml TEXT)")
			
			files_pair = self.get_ESI_files()
			for pair in files_pair:
				esi_path = pair[1]
				vendor_id,vendor_name = self.get_ESI_info(esi_path)
				if vendor_id!= 0:
					with self.con:
						cur.execute("INSERT INTO Vendors (VendorId,Name,Path,App) VALUES(?,?,?,?)",(vendor_id,vendor_name,esi_path,pair[0]))
					device_list = self.get_ESI_devices()
					for device in device_list:
						with self.con:
							cur.execute("INSERT INTO Devices (VendorId,productCode,revisionNumber,Name) VALUES(?,?,?,?)",(vendor_id,device[0],device[1],device[2]))
			return True
		except sqlite3.Error as e:
			print('DB Error: ',e)
			return False
		finally:
			if self.con:
				self.con.close()
Exemplo n.º 2
0
    def __init__(self, xml_slave):
        self.InitCmds = list()
        self.Mailbox = None
        self.DC = None

        self.name_in_res = YoUtil.get_xml_node_as_text(xml_slave,
                                                       'Info/NameInResource')
        self.device_name = YoUtil.get_xml_node_as_text(xml_slave, 'Info/Name')
        self.ProductName = YoUtil.get_xml_node_as_text(xml_slave,
                                                       'Info/ProductName')
        self.vendor_id = YoUtil.get_xml_node_as_int(xml_slave, 'Info/VendorId')
        self.productCode = YoUtil.get_xml_node_as_int(xml_slave,
                                                      'Info/ProductCode')
        self.revisionNo = YoUtil.get_xml_node_as_int(xml_slave,
                                                     'Info/RevisionNo')

        self.ProcessData_Send_BitStart = YoUtil.get_xml_node_as_int(
            xml_slave, 'ProcessData/Send/BitStart')
        self.ProcessData_Send_BitLength = YoUtil.get_xml_node_as_int(
            xml_slave, 'ProcessData/Send/BitLength')
        self.ProcessData_Recv_BitStart = YoUtil.get_xml_node_as_int(
            xml_slave, 'ProcessData/Recv/BitStart')
        self.ProcessData_Recv_BitLength = YoUtil.get_xml_node_as_int(
            xml_slave, 'ProcessData/Recv/BitLength')

        self.load_initCmds(xml_slave)
        self.load_mailbox(xml_slave)
        self.load_DC(xml_slave)
Exemplo n.º 3
0
 def tostring(self, type, indent=0):
     ret = ("Slave ('%s','%s', (0x%x,0x%x,0x%x) -> '%s') " %
            (YoUtil.str_strip(
                self.name_in_res), YoUtil.str_strip(
                    self.device_name), self.vendor_id, self.productCode,
             self.revisionNo, YoUtil.str_strip(self.ProductName))) + '\n'
     ret += YoUtil.get_indent(indent + 1) + 'ProcessData '
     if self.ProcessData_Send_BitStart != None:
         ret += ('Send BitStart=%d, BitLength=%d' %
                 (self.ProcessData_Send_BitStart,
                  self.ProcessData_Send_BitLength))
     if self.ProcessData_Recv_BitStart != None:
         ret += (', Recv BitStart=%d, BitLength=%d' %
                 (self.ProcessData_Recv_BitStart,
                  self.ProcessData_Recv_BitLength))
     ret += '\n'
     if self.DC != None:
         ret += self.DC.tostring(indent + 1)
     if self.Mailbox != None:
         ret += '\n' + self.Mailbox.tostring(indent + 1)
     if type >= 1:
         ret += ("%sInitCmds count= %d" %
                 (YoUtil.get_indent(indent + 1), len(self.InitCmds))) + '\n'
         self.InitCmds = sorted(self.InitCmds, key=attrgetter('Ado'))
         for initCmd in self.InitCmds:
             str = initCmd.tostring(indent + 2)
             ret += (str)
     return ret
Exemplo n.º 4
0
def esi_folders():
    '''
	gets the list of folders that holds ESI files
	'''
    pr1 = pr()
    esi = EsiUtil()
    folders = esi.get_ESI_folders()
    YoUtil.print_list(folders, 1)
Exemplo n.º 5
0
def cmd_slave_list():
    if len(sys.argv) >= 3:
        cfg = Config(sys.argv[2])
        cfg.load_config()
        lst = cfg.get_slaves()
        YoUtil.print_list(lst, 1)
    else:
        print_usage()
Exemplo n.º 6
0
def cmd_load_config_full():
    if len(sys.argv) >= 3:
        cfg = Config(sys.argv[2])
        cfg.load_config()
        master = cfg.get_master()
        lst += cfg.get_slaves()
        YoUtil.print_list(lst, 1)
    else:
        print_usage()
Exemplo n.º 7
0
 def tostring(self, type, indent=0):
     ret = ("Master name='%s' " % (YoUtil.str_strip(self.name))) + '\n'
     ret += ("%sInitCmds count= %d" %
             (YoUtil.get_indent(indent + 1), len(self.InitCmds))) + '\n'
     self.InitCmds = sorted(self.InitCmds, key=attrgetter('Ado'))
     for initCmd in self.InitCmds:
         str = initCmd.tostring(indent + 2)
         ret += (str)
     return ret
Exemplo n.º 8
0
	def load(self):
		YoUtil.debug_print('loading ->', self.path)
		self.tree = ET()
		self.tree.parse(self.path)
		root = self.tree.getroot()	
		xml_list = root.findall('Workspace/Targets/item')
		if  xml_list != None:
			#YoUtil.debug_print('lst',xml_list)
			for xml_node in xml_list:
				tm = target_model(xml_node)
				self.target_list.append(tm)
Exemplo n.º 9
0
	def get_ESI_devices(self):
		ret = list()
		#devices
		if self.xml_esi!= None:
			YoUtil.debug_print('read devices of esi=',self.esi_path)
			xml_list_device = self.xml_esi.findall('Descriptions/Devices/Device')
			YoUtil.debug_print('num of devices in esi=',len(xml_list_device))
			for xml_device in xml_list_device:
				pc = None
				rev=None
				name=None
				xml_type = xml_device.find('Type')
				if xml_type != None:
					msg1 = ''
					if 'ProductCode' in xml_type.attrib.keys():
						pc = YoUtil.get_int(xml_type.attrib['ProductCode'])
						msg1 = msg1+'ProductCode='+hex(pc)
					if 'RevisionNo' in xml_type.attrib.keys():
						rev = YoUtil.get_int(xml_type.attrib['RevisionNo'])
						msg1= msg1+' RevisionNo:'+hex(rev)
					
					if len(msg1)>0:
						YoUtil.debug_print(msg1,'')
				if pc != None:
					ret.append((pc,rev,name))
		return ret
Exemplo n.º 10
0
	def __init__(self, xml_device):
		self.xml_node = xml_device
		self.product_code = None
		self.revision = None
		self.name = None
		
		xml_type = xml_device.find('Type')
		if xml_type!= None:
			if 'ProductCode' in xml_type.attrib.keys():
				self.product_code  = YoUtil.get_int(xml_type.attrib['ProductCode'])
			if 'RevisionNo' in xml_type.attrib.keys():
				self.revision = YoUtil.get_int(xml_type.attrib['RevisionNo'])
		xml_name = xml_device.find('Name')
		if xml_name!=None:
			self.name = xml_name.text
Exemplo n.º 11
0
	def get_ESI_files(self, vendor_id=None, productCode=None):
		esi_folders = self.get_ESI_folders()
		esi_files = list()
		for pair in esi_folders:
			folder = pair[1]
			files = YoUtil.get_list_of_files(folder,'.xml')
			for file in files:
				full_path = os.path.join(folder,file)
				esi_files.append((pair[0],full_path))

		if vendor_id==None and productCode==None:
			return esi_files
			
		ret = list()
		for pair in esi_files:
			file_path = pair[1]
			esi_file = EsiFile(file_path)
			if esi_file != None:
				esi_file.load_vendor()
				if esi_file.id == vendor_id:
					if productCode == None:
						ret.append((pair[0],esi_file.path))
					else:
						esi_file.load_devices()
						for d in esi_file.devices:
							if d != None:
								if d.product_code == productCode:
									ret.append((pair[0],file_path))
									break
		return ret
Exemplo n.º 12
0
    def __init__(self, xml_initCmd):
        self.Transition = list()
        self.Comment = None
        self.Cmd = None
        self.Adp = None
        self.Ado = None
        self.Index = None
        self.SubIndex = None
        self.Data = None
        self.Cnt = None
        self.CompleteAccess = None

        xml_transitions = xml_initCmd.findall('Transition')
        for xml_transition in xml_transitions:
            self.Transition.append(xml_transition.text)

        xml_comment = xml_initCmd.find('Comment')
        if xml_comment != None:
            self.Comment = xml_comment.text
        xml_ado = xml_initCmd.find('Ado')
        if xml_ado != None:
            self.Ado = YoUtil.get_int(xml_ado.text)
        xml_adp = xml_initCmd.find('Adp')
        if xml_adp != None:
            self.Adp = YoUtil.get_int(xml_adp.text)
        xml_Index = xml_initCmd.find('Index')
        if xml_Index != None:
            self.Index = YoUtil.get_int(xml_Index.text)
        xml_SubIndex = xml_initCmd.find('SubIndex')
        if xml_SubIndex != None:
            self.SubIndex = YoUtil.get_int(xml_SubIndex.text)

        xml_Data = xml_initCmd.find('Data')
        if xml_Data != None:
            self.Data = xml_Data.text

        xml_Cmd = xml_initCmd.find('Cmd')
        if xml_Cmd != None:
            self.Cmd = xml_Cmd.text

        xml_Cnt = xml_initCmd.find('Cnt')
        if xml_Cnt != None:
            self.Cnt = xml_Cnt.text

        if 'CompleteAccess' in xml_initCmd.attrib:
            self.CompleteAccess = xml_initCmd.attrib['CompleteAccess']
Exemplo n.º 13
0
def Main():
    print("ECatConfigUtil -> ")
    YoUtil.print_list(sys.argv, 1)
    numofParams = len(sys.argv)
    if numofParams > 1:
        cmd = sys.argv[1].lower()
        command_options = {
            'slaves': cmd_slave_list,
            'full': cmd_load_config_full,
        }

        if cmd in command_options.keys():
            command_options[cmd]()
        else:
            print_usage(cmd)
    else:
        print_usage()
Exemplo n.º 14
0
def find_esi(vendor, product):
    '''
		finds ESI files can fileter by [vendor] and [product]
	'''
    pr1 = pr()
    esi = EsiUtil()
    vendor_id = None
    productCode = None
    if vendor != None:
        vendor_id = YoUtil.get_int(vendor)
    if product != None:
        productCode = YoUtil.get_int(product)
    files = esi.get_ESI_files(vendor_id, productCode)
    if files != None and len(files) > 0:
        YoUtil.print_list(files, 1)
    else:
        pr1.print('ESI not found !')
Exemplo n.º 15
0
 def tostring(self, indent=0):
     if self.Ado != None:
         ret = YoUtil.get_indent(
             indent
         ) + 'InitCmd Ado,Adp=(0x%4.4x,0x%4.4x) [%s] - "%s" - Data=[%s] Cnt=[%s] Cmd=[%s] CompleteAccess=[%s]' % (
             self.Ado, self.Adp, self.get_transitions(),
             YoUtil.str_strip(self.Comment), self.Data,
             YoUtil.str_strip(self.Cnt), YoUtil.str_strip(
                 self.Cmd), YoUtil.str_strip(self.CompleteAccess)) + '\n'
     elif self.Index != None:
         ret = YoUtil.get_indent(
             indent
         ) + 'InitCmd Index=(0x%4.4x.%d) [%s] - "%s" - Data=[%s] Cnt=[%s] Cmd=[%s] CompleteAccess=[%s]' % (
             self.Index, self.SubIndex, self.get_transitions(),
             YoUtil.str_strip(self.Comment), self.Data,
             YoUtil.str_strip(self.Cnt), YoUtil.str_strip(
                 self.Cmd), YoUtil.str_strip(self.CompleteAccess)) + '\n'
     return ret
Exemplo n.º 16
0
 def get_ESI_folders(self):
     ret = list()
     userESIPath = YoUtil.get_elmo_user_ESI_path()
     ret.append(('ElmoUserESI', userESIPath))
     ret.append(
         ('EASESI',
          'C:/Dev/eas/View/ElmoMotionControl.View.Main/EtherCATSlaveLib'))
     ret.append(('TwinCAT', 'C:/TwinCAT/3.1/Config/Io/EtherCAT'))
     return ret
Exemplo n.º 17
0
    def __init__(self, xml_mailbox):
        self.Protocols = list()
        self.CoEInitCmds = None
        self.Send_Start = None
        self.Send_Length = None
        self.Recv_Start = None
        self.Recv_Length = None
        self.Recv_PollTime = None
        self.Recv_StatusBitAddr = None

        self.Send_Start = YoUtil.get_xml_node_as_int(xml_mailbox, 'Send/Start')
        self.Send_Length = YoUtil.get_xml_node_as_int(xml_mailbox,
                                                      'Send/Length')
        self.Recv_Start = YoUtil.get_xml_node_as_int(xml_mailbox, 'Recv/Start')
        self.Recv_Length = YoUtil.get_xml_node_as_int(xml_mailbox,
                                                      'Recv/Length')
        self.Recv_PollTime = YoUtil.get_xml_node_as_int(
            xml_mailbox, 'Recv/PollTime')
        self.Recv_StatusBitAddr = YoUtil.get_xml_node_as_int(
            xml_mailbox, 'Recv/StatusBitAddr')

        xml_Protocol_list = xml_mailbox.findall('Protocol')
        if xml_Protocol_list != None:
            for xml_protocol in xml_Protocol_list:
                self.Protocols.append(xml_protocol.text)

        xml_initCmd_list = xml_mailbox.findall('CoE/InitCmds/InitCmd')
        if xml_initCmd_list != None:
            self.CoEInitCmds = list()
            for xml_initCmd in xml_initCmd_list:
                initcmd = InitCmd(xml_initCmd)
                self.CoEInitCmds.append(initcmd)
Exemplo n.º 18
0
	def load_vendor(self):
		xml_esi = self.tree.getroot()
		if xml_esi!= None:
			xml_vendor = xml_esi.find('Vendor')
			if xml_vendor!= None:
				xml_id = xml_vendor.find('Id')
				if xml_id != None:
					self.id = YoUtil.get_int(xml_id.text)
				else:
					self.id=None
				xml_name = xml_vendor.find('Name')
				if xml_name != None:
					self.vendor_name = xml_name.text
Exemplo n.º 19
0
 def decode_slave_InitCmds(self, slave_name):
     #print('decode_slave_InitCmds')
     ret = list()
     xml_slave = self.get_xml_slave_by_name(slave_name)
     if xml_slave != None:
         print('Slave found:')
         print(YoUtil.get_xml_content(xml_slave))
         pass
         # get the list of InitCmds
         # build the list
         # get the list of mailbox\CoE\InitCmds
         # build the list
     return ret
Exemplo n.º 20
0
 def tostring(self, ident=0):
     ret = YoUtil.get_indent(ident) + 'Mailbox'
     ret += '\n' + YoUtil.get_indent(ident + 1) + 'Protocols: '
     ret += YoUtil.list_to_comma_separated(self.Protocols) + ' '
     ret += '\n' + YoUtil.get_indent(ident + 1) + (
         "Send: Start=%d Length= %d, Recv: Start=%d, Length=%d" %
         (self.Send_Start, self.Send_Length, self.Recv_Start,
          self.Recv_Length))
     if self.Recv_PollTime != None:
         ret += (", PollTime=%d") % (self.Recv_PollTime)
     if self.Recv_StatusBitAddr != None:
         ret += (", StatusBitAddr=%d") % (self.Recv_StatusBitAddr)
     if self.CoEInitCmds != None:
         self.CoEInitCmds = sorted(self.CoEInitCmds,
                                   key=attrgetter('Index'))
         ret += (
             "\n%sCoE InitCmds count= %d" %
             (YoUtil.get_indent(ident + 1), len(self.CoEInitCmds))) + '\n'
         for initCmd in self.CoEInitCmds:
             str = initCmd.tostring(ident + 2)
             ret += (str)
     return ret
Exemplo n.º 21
0
def cmd_find(esi):			
	cmd = sys.argv[2].lower()
	if cmd == 'esi':
		files = esi.get_ESI_files()
		YoUtil.print_list(files,1)
	elif cmd == 'vendor':
		vendor_id = YoUtil.get_int(sys.argv[3])
		files = esi.get_ESI_files_by_vendor(vendor_id)
		YoUtil.print_list(files,1)
	elif cmd == 'createdb':
		if esi.create_esi_db('esi.db') == True:
			print('ESI DB created successfully')
		else:
			print('failed to create ESI DB ')
	elif cmd == 'device_esi':
		vendor_id = YoUtil.get_int(sys.argv[3])
		productCode = YoUtil.get_int(sys.argv[4])
		revisionNumber = None
		if len(sys.argv) > 5:
			revisionNumber = YoUtil.get_int(sys.argv[5])
		files = esi.get_devices(vendor_id,productCode,revisionNumber)
		YoUtil.print_list(files,1)
	else:
		print_usage('find')
Exemplo n.º 22
0
    def load(self):
        YoUtil.debug_print('loading ->', self.path)
        self.tree = ET()
        self.tree.parse(self.path)
        root = self.tree.getroot()
        xml_list = root.findall('GLOBAL_PARAMS/NAME')
        if xml_list != None:
            #YoUtil.debug_print('xml_list=',xml_list)
            for xml_name in xml_list:
                res_id = xml_name.get('RES_ID')
                #YoUtil.debug_print('Res_ID=',res_id)
                if res_id != None:
                    self.res_id = res_id
        xml_list = root.findall('MOTION_DEVICES/NODE')
        if xml_list != None:
            #YoUtil.debug_print('Nodes xml_list=',xml_list)
            for xml_node in xml_list:
                self.load_node(xml_node)

        xml_list = root.findall('IO_DEVICES/NODE')
        if xml_list != None:
            #YoUtil.debug_print('Nodes xml_list=',xml_list)
            for xml_node in xml_list:
                self.load_io(xml_node)

        xml_list = root.findall('GENERAL_DEVICES/NODE')
        if xml_list != None:
            #YoUtil.debug_print('Nodes xml_list=',xml_list)
            for xml_node in xml_list:
                self.load_general(xml_node)

        xml_list = root.findall('VIRTUAL_OBJECTS/VIRTUAL_OBJECT')
        if xml_list != None:
            #YoUtil.debug_print('Nodes xml_list=',xml_list)
            for xml_node in xml_list:
                self.load_virtual(xml_node)
Exemplo n.º 23
0
	def get_ESI_files_by_vendor(self, vendor_id):
		files = self.get_ESI_files()
		ret = list()
		for pair in files:
			file_path = pair[1]
			xml_esi = self.load_esi(file_path)
			if xml_esi!= None:
				xml_vendor = xml_esi.find('Vendor')
				if xml_vendor!= None:
					xml_id = xml_vendor.find('Id')
					if xml_id != None:
						id = YoUtil.get_int(xml_id.text)
						if id == vendor_id:
							ret.append(file_path)
		return ret
Exemplo n.º 24
0
	def get_ESI_info(self,esi_path):
		esi = EsiFile(esi_path)
		vendor_id = 0
		vendor_name  = None
		self.esi_path = esi_path
		self.xml_esi = self.load_esi(esi_path)
		if self.xml_esi!= None:
			xml_vendor = self.xml_esi.find('Vendor')
			if xml_vendor!= None:
				xml_id = xml_vendor.find('Id')
				if xml_id != None:
					vendor_id = YoUtil.get_int(xml_id.text)
				xml_name = xml_vendor.find('Name')
				if xml_name != None:
					vendor_name = xml_name.text
						
		return vendor_id,vendor_name
Exemplo n.º 25
0
	def get_devices(self, vendor_id,productCode,revisionNumber):
		ret = list()
		files = self.get_ESI_files_by_vendor(vendor_id)
		YoUtil.debug_print('num of files=',len(files))
		for file_path in files:
			xml_esi = self.load_esi(file_path)
			if xml_esi!= None:
				xml_list_device = xml_esi.findall('Descriptions/Devices/Device')
				YoUtil.debug_print('num of devices=',len(xml_list_device))
				for xml_device in xml_list_device:
					xml_type = xml_device.find('Type')
					if xml_type != None:
						pc = YoUtil.get_int(xml_type.attrib['ProductCode'])
						YoUtil.debug_print('ProductCode=',pc)
						if pc == productCode:
							ret.append(file_path)
		return ret
Exemplo n.º 26
0
	def __init__(self,xml_dc):
		self.ReferenceClock = YoUtil.get_xml_node_as_bool(xml_dc,'ReferenceClock')
		self.CycleTime0 = YoUtil.get_xml_node_as_int(xml_dc,'CycleTime0')
		self.CycleTime1 = YoUtil.get_xml_node_as_int(xml_dc,'CycleTime1')
		self.ShiftTime = YoUtil.get_xml_node_as_int(xml_dc,'ShiftTime')
Exemplo n.º 27
0
	def tostring(self,indent=0):
		ret = YoUtil.get_indent(indent)+'DC -'+'ReferenceClock='+str(self.ReferenceClock)+' CycleTime0='+str(self.CycleTime0)+' CycleTime1='+str(self.CycleTime1)+' ShiftTime='+str(self.ShiftTime)
		return ret
Exemplo n.º 28
0
	def get_ESI_folders(self):
		ret = list()
		userESIPath= YoUtil.get_elmo_user_ESI_path()
		ret.append(('ElmoUserESI',userESIPath))
		ret.append(('EASESI','C:\Dev\eas\View\ElmoMotionControl.View.Main\EtherCATSlaveLib'))
		return ret
Exemplo n.º 29
0
def cmd_esi_folder(esi):
	YoUtil.print_list(esi.get_ESI_folders(),1)