psuria  
                
                  
                    March 4, 2019,  8:54am
                   
                  1 
               
             
            
              first of all forgive me for my English
I have developed this code by which I read a csv file, I add the data of a new row, then I generate an xml and update the csv.
Could you help me see the light?
punter = system.tag.read("Logo/Dades maquina[0]").value
Dia = system.tag.read("Logo/Dades maquina[1]").value
Mes = system.tag.read("Logo/Dades maquina[2]").value
Any = system.tag.read("Logo/Dades maquina[3]").value
Hora = system.tag.read("Logo/Dades maquina[4]").value
Min = system.tag.read("Logo/Dades maquina[5]").value
Maquina = system.tag.read("Logo/Dades maquina[0]").value
Referencia = system.tag.read("Logo/Dades maquina[6]").value
Temps_cicle = system.tag.read("Logo/Dades maquina[7]").value
copiar_dades = system.tag.read("Logo/aux copia").value
valor = 0
data = system.date.now()
data_nom = system.date.format(data, "dd-MM-yyyy")
if copiar_dades == 1:
#escriure csv
	import csv
	csvData = csv.reader(open("C:\\output\\DUEVO1.csv"))
	header = csvData.next()
	conjuntdades = system.dataset.toDataSet(header ,list(csvData))
	novafila=[Dia, Mes, Any, Hora, Min, Maquina, Referencia, Temps_cicle]
	conjuntdades = system.dataset.addRow(conjuntdades,novafila)
	
	excel = system.dataset.dataSetToExcel(1,[conjuntdades])
	system.file.writeFile("C:\\output\\Dades_DU_EVO_"+data_nom+"_logo.xml", excel)
	
	csv2 = system.dataset.toCSV(conjuntdades)	
	system.file.writeFile("C:\\output\\DUEVO1.csv", csv2)
		
	system.tag.write("Logo/aux copia",valor)
	
elif copiar_dades == 0:
 
            
              
            
           
          
            
            
              Where is this code being used? Is this in an event?
I ask because while I don’t see anything wrong in the code, whatever event you are using may be getting fired twice.
             
            
              
            
           
          
            
            
              Well, maybe it has nothing to do with it but punter  and Maquina  are the same variable.
             
            
              
            
           
          
            
              
                psuria  
              
                  
                    March 4, 2019, 12:36pm
                   
                  4 
               
             
            
              
punter is not used, it was for a part of old code
             
            
              
            
           
          
            
              
                psuria  
              
                  
                    March 4, 2019, 12:46pm
                   
                  5 
               
             
            
              
 JordanCClark:
 
Where is this code being used? Is this in an event?
I ask because while I don't see anything wrong in the code, whatever event you are using may be getting fired twice.
 
 
Now that you say it, review and comment later but I think you're right, always thinking about the code failure and leave aside other options
             
            
              
            
           
          
            
              
                psuria  
              
                  
                    March 4, 2019,  1:51pm
                   
                  6 
               
             
            
              
 JordanCClark:
 
Where is this code being used? Is this in an event?
I ask because while I don't see anything wrong in the code, whatever event you are using may be getting fired twice.
 
 
reviewing the event, I have not found where the failure can come from
the event is associated with a propertyChange of a Label the value of the label depends on the tag "" Logo / aux copia "). value"
the most refined code I have left now in:
Dia = system.tag.read("Logo/Dades maquina[1]").value
Mes = system.tag.read("Logo/Dades maquina[2]").value
Any = system.tag.read("Logo/Dades maquina[3]").value
Hora = system.tag.read("Logo/Dades maquina[4]").value
Min = system.tag.read("Logo/Dades maquina[5]").value
Maquina = system.tag.read("Logo/Dades maquina[0]").value
Referencia = system.tag.read("Logo/Dades maquina[6]").value
Temps_cicle = system.tag.read("Logo/Dades maquina[7]").value
copiar_dades = system.tag.read("Logo/aux copia").value
data = system.date.now()
data_nom = system.date.format(data, "dd-MM-yyyy")
if copiar_dades == 0:
		
		valor = 0
		system.tag.write("Logo/aux copia",valor)
		
elif copiar_dades == 1:
		valor = 0
		system.tag.write("Logo/aux copia",valor)
		
#lleguir csv
		import csv
		csvData = csv.reader(open("C:\\output\\DUEVO1.csv"))
		header = csvData.next()
		conjuntdades = system.dataset.toDataSet(header ,list(csvData))
#afegir fila			
		novafila=[Dia, Mes, Any, Hora, Min, Maquina, Referencia, Temps_cicle]
		conjuntdades = system.dataset.addRow(conjuntdades,novafila)
#escriure excel				
		excel = system.dataset.dataSetToExcel(1,[conjuntdades])
		system.file.writeFile("C:\\output\\Dades_DU_EVO_"+data_nom+"_logo.xml", excel)
#escriure csv				
		csv2 = system.dataset.toCSV(conjuntdades)	
		system.file.writeFile("C:\\output\\DUEVO1.csv", csv2)
		
If someone observes where I am making the mistake, I will be deeply grateful
             
            
              
            
           
          
            
            
              You might just need to narrow down the propertyChange you want this to run on, since the label has many properties that can trigger the script.
if event.propertyName == 'text':
      your code here
 
            
              1 Like 
            
            
           
          
            
            
              
Not might .  Must propertyChange event that is not within an if block that checks for the correct propertyName is always 
Most troublesome is any such code that unconditionally sets a bindable property on the source component -- that will trigger infinite recursion.
             
            
              4 Likes 
            
                
            
           
          
            
              
                psuria  
              
                  
                    March 5, 2019, 10:04am
                   
                  9 
               
             
            
              
 dkhayes117:
 
You might just need to narrow down the propertyChange you want this to run on, since the label has many properties that can trigger the script.
if event.propertyName == 'text':
      your code here
 
 
indeed that was the reason.
             
            
              
            
           
          
            
              
                psuria  
              
                  
                    March 5, 2019, 10:05am
                   
                  10 
               
             
            
              
 pturmel:
 
Not might .  Must propertyChange event that is not within an if block that checks for the correct propertyName is always 
Most troublesome is any such code that unconditionally sets a bindable property on the source component -- that will trigger infinite recursion.
 
 
indeed that was the reason.
             
            
              
            
           
          
            
              
                psuria  
              
                  
                    March 5, 2019, 10:06am
                   
                  11 
               
             
            
              There is nothing more rewarding than every day learning something new.
Thanks to all for the help
             
            
              1 Like