Gabri.cicchi Inserito: 16 aprile 2021 Segnala Inserito: 16 aprile 2021 Buongiorno a tutti, non riesco a trovare nelle varie discussioni un esempio per poter scrivere un file CSV da un pannello TP900 con TIA V15. Potete aiutarmi.
lupusimprobus Inserita: 19 agosto 2021 Segnala Inserita: 19 agosto 2021 Ciao. Spero ti sia ancora utile Script: "CMP732_log_create" Sub CMP732_log_create() '********************************************************************* '* Descrizione: * '* - Quando richiamato, lo script crea un file .csv con i dati * '* dell'ultimo ciclo macchina. * '* - Viene creato un file per ogni mese dell'anno. * '* - Se il file non esiste significa che nel mese attuale non sono * '* ancora stati lavorati dei pezzi. In questo caso viene creato un * '* nuovo file con la prima riga di intestazione. * '* - Se il file esiste, ovvero se all'interno del mese, sono già * '* stati aggiunte righe per il log, allora verrà solo aggiunta una * '* nuova riga al file. * '* - --------------------------------------------------------------- * '* - Lo script viene richiamato ad ogni modifica di un parametro sul * '* CMP 732. '* - Il file viene salvato all'interno di una cartella della * '* scheda SD. * '* DATE: 2020-07-27 * '* AUTHOR: CMP_VG * '********************************************************************* ' Gestione errori On Error Resume Next ' Lo script viene richiamato al cambio di valore della variabile. ' Faccio in modo che venga eseguito solo sul fronte di salita. ' Questo per evitare di eseguire due volte lo script If SmartTags("CMP732_TCP-IP_IS_HMI_com_set_script_start") Then ' ================================================================= ' Inizializzazione ' Nome dello script Const SCRIPT_NAME = "CMP732_log_create" ' Nomee del file Const FILE_NAME_BASE = "log_change_data" ' Estensione del file Const FILE_EXT = ".csv" ' Cartella di destinazione Const DIR_DEFAULT = "\Storage card SD\log" ' Stampa messaggi di sistema Const PRINT_SYS_MSG = False ' Costanti per apertura file Const F_READ = 1, F_WRITE = 2, F_APPEND = 8 ' Debug ShowSystemAlarm("----------------------------") ShowSystemAlarm(SCRIPT_NAME&" [0000]: Script in run...") ' Segnalo al PLC che lo script è avviato SmartTags("CMP732_TCP-IP_IS_HMI_com_get_script_busy") = True ' ****************************************************************** ' Definisco il nome del file ' Esempio: 20191110_log_change_data.csv Dim FILE_NAME FILE_NAME = get_date( _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_YEAR"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_MONTH"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_DAY")) & _ "_" & FILE_NAME_BASE & FILE_EXT 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0020]: file_name = " & FILE_NAME) 'End If ' Nome del file completo di prercorso Dim file_name_full file_name_full = DIR_DEFAULT & "\" & FILE_NAME 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0021]: file_name_full = " & file_name_full) 'End If ' ****************************************************************** ' Accesso al file system Dim fSystem Set fSystem = CreateObject("FileCtl.FileSystem") ' ****************************************************************** ' Verifico se il percorso della cartella in cui voglio salvare il file esiste Dim path_exist 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0031]: Controllo che il percorso di destinazione esista") 'End If ' Se il percorso non esiste lo creo If(dir_exist_TP(DIR_DEFAULT) <> 0) Then ' Il percorso non esiste ' Creo la cartella fSystem.MkDir(DIR_DEFAULT & "\") 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0032]: La cartella non esiste. Creo la cartella") 'End If End If ' Se il percorso ancora non esiste, abilito un errore If(dir_exist_TP(DIR_DEFAULT) = 0) Then ' La cartella esiste path_exist = True 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0033]: La cartella ora esiste. Continuo...") 'End If Else ' La cartella non esiste path_exist = False ' Attiva variabile che segnala la mancanza della cartella di destinazione 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0034]: La cartella continua a non esistere. ERRORE!!!") 'End If End If ' ****************************************************************** ' Verifico se il file di questo mese esiste già Dim file_new file_new = False 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0035]: Controllo se il file di questo mese esiste già") 'End If ' Verifico se il file esiste If(dir_exist_TP(file_name_full) = 0) Then ' Il file esiste già file_new = False 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0036]: Il file del mese esiste già") 'End If Else ' Il file del mese non esiste file_new = True 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME&" [0036]: Il file del mese ancora non esiste") 'End If End If ' ****************************************************************** ' Se la cartella esiste... ' Apro il file e ci scrivo dentro i dati If(path_exist) Then ' Creo il file di testo Dim fFile_write Set fFile_write = CreateObject("FileCtl.File") ' Apro il file in versione "append" ' Se il file non esiste, lo creo fFile_write.open file_name_full, F_APPEND 'Apertura file in "Append" 'If PRINT_SYS_MSG Then ' ShowSystemAlarm(SCRIPT_NAME & " [0040] - File aperto") 'End If ' Creo la stringa da aggiungere al file Dim str str = "" Dim str_loc str_loc = "" ' ****************************************************************** ' Se il file è appena stato creato, inserisco la riga di intestazione If file_new Then ' Il file è appena stato creato. ' Aggiungo la riga di intestazione str = "DATA;ORA;USER;STATO;LAYER;UNITA' U.S.;TIPO SALDATURA;VALORE LAVORO;U.M.;" str = str & "CORREZIONE;U.M.;QUOTA START;QUOTA START FINESTRA;" str = str & "TEMPO MIN. [s]; TEMPO MAX. [s];ENERGIA MIN. [J];ENERGIA MAX. [J];" str = str & "POTENZA MIN. [W];POTENZA MAX. [W];POTENZA TEST [W];" str = str & "QUOTA FINE MIN. [mm];QUOTA FINE MAX. [mm];" str = str & "QUOTA DIFF. MIN. [mm];QUOTA DIFF. MAX. [mm];" str = str & "TEMPO RAFFREDDA U.S.; START ANTICIPATO;" str = str & "OFFSET [Hz];OFFSET CORREZIONE [Hz];" str = str & "AMPIEZZA START [%];AMPIEZZA STOP [%]" ' Fine stringa di intestazione ' str = str & vbCrLf ' Aggiungo la riga al file fFile_write.LinePrint str End If ShowSystemAlarm(SCRIPT_NAME&" [0100]: U.S. Unit = " & _ SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].US_Unit")) Dim aux ' ****************************************************************** ' Ora che so di avere la riga di intestazione... ' Creo la stringa da agiungere al file. ' ------------------------------------------------------------------ ' Colonna 1: Data str = get_date_long(SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_YEAR"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_MONTH"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_DAY")) & ";" ' ------------------------------------------------------------------ ' Colonna 2: Ora str = str & get_time_long(SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_HOUR"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_MINUTE"), _ SmartTags("HMI_Area_DB_DateAndTime_get_date_and_time_system_SECOND")) & ";" ' ------------------------------------------------------------------ ' Colonna 3: Nome utente e gruppo str = str & SmartTags("CMP732_TCP-IP_IS_user_Data_user_name") & " " & _ SmartTags("CMP732_TCP-IP_IS_user_Data_user_surname") & " [" & _ SmartTags("CMP732_TCP-IP_IS_user_Group_user_name") & " " & _ SmartTags("CMP732_TCP-IP_IS_user_Group_user_group") & "];" ' ------------------------------------------------------------------ ' Colonna 4: Stato ' Indica se la riga in esame riporta i valori prima della modifica ' (vecchio) o dopo la modifica (nuovo). str = str & "NEW;" ' ------------------------------------------------------------------ ' Colonna 5: Layer / Programma str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Layer") & ";" ' ------------------------------------------------------------------ ' Colonna 6: Numero Unità U. S. str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].US_Unit") & ";" ' ------------------------------------------------------------------ ' Colonna 7: Tipo di saldatura ' 1 = Energia ' 2 = Tempo ' 3 = Quota assoluta ' 4 = Quta relativa Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_mode") Case 1 str = str & "Energia;" Case 2 str = str & "Tempo;" Case 3 str = str & "Q.ta Assuluta;" Case 4 str = str & "Q.ta Relativa;" Case Else str = str & "Indefinito;" End Select ' ------------------------------------------------------------------ ' Colonna 8: Valore di lavoro ' 1 = Energia -> Joule ' 2 = Tempo -> Secondi ' 3 = Quota assoluta -> mm ' 4 = Quta relativa -> mm Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_mode") Case 1 str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_value") & ";Joule;" Case 2 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_value") aux = aux / 100.0 str = str & CStr(aux) & ";s;" Case 3 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_value") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case 4 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_value") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case Else str = str & "Indefinito;-;" End Select ' ------------------------------------------------------------------ ' Colonna 9: Correzione del valore di lavoro ' 1 = Energia -> Joule ' 2 = Tempo -> Secondi ' 3 = Quota assoluta -> mm ' 4 = Quta relativa -> mm Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Weld_mode") Case 1 str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Correction") & ";Joule;" Case 2 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Correction") aux = aux / 100.0 str = str & CStr(aux) & ";s;" Case 3 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Correction") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case 4 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Correction") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case Else str = str & "Indefinito;-;" End Select ' ------------------------------------------------------------------ ' Colonna 10: Controllo quota iniziale aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Quote_start_target") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 11: Controllo quota iniziale (finestra) aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Quote_start_win") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 12: Controllo tempo minimo di saldatura aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Time_Min") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 13: Controllo tempo massimo di saldatura aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Time_Max") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 14: Controllo energia minima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Energy_Min") & ";" ' ------------------------------------------------------------------ ' Colonna 15: Controllo energia massima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Energy_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 16: Controllo potenza minima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Power_Min") & ";" ' ------------------------------------------------------------------ ' Colonna 17: Controllo potenza massima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Power_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 18: Potenza massima in test str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Power_test_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 19: Quota finale per saldatura in quota assoluta -> limite minimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Final_Quote_Min") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 20: Quota finale per saldatura in quota assoluta -> limite massimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Final_Quote_Max") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 21: Quota finale per saldatura in quota relativa -> limite minimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Delta_Quote_Min") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 22: Quota finale per saldatura in quota relativa -> limite massimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].check_Delta_Quote_Max") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 23: Tempo di raffreddamento aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Delay_Time") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 24: Avvio anticipato degli U. S. If SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Early_start") = 0 Then str = str & "NO;" Else str = str & "SI;" End If ' ------------------------------------------------------------------ ' Colonna 25: Offset str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Offset") & ";" ' ------------------------------------------------------------------ ' Colonna 26: Correzione Offset str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].Offset_correction") & ";" ' ------------------------------------------------------------------ ' Colonna 27: Ampiezza iniziale str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].perc_start") & ";" ' ------------------------------------------------------------------ ' Colonna 28: Ampiezza finale str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[0].perc_stop") & ";" ' ****************************************************************** ' Aggiungo la nuova riga al file fFile_write.LinePrint str 'If PRINT_SYS_MSG Then ShowSystemAlarm(SCRIPT_NAME&" [8000] - Scritto valore Vecchio") ' ****************************************************************** ' ****************************************************************** ' ------------------------------------------------------------------ ' Colonna 1: Data str = ";" ' ------------------------------------------------------------------ ' Colonna 2: Ora str = str & ";" ' ------------------------------------------------------------------ ' Colonna 3: Nome utente e gruppo str = str & ";" ' ------------------------------------------------------------------ ' Colonna 4: Stato ' Indica se la riga in esame riporta i valori prima della modifica ' (vecchio) o dopo la modifica (nuovo). str = str & "OLD;" ' ------------------------------------------------------------------ ' Colonna 5: Layer / Programma str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Layer") & ";" ' ------------------------------------------------------------------ ' Colonna 6: Numero Unità U. S. str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].US_Unit") & ";" ' ------------------------------------------------------------------ ' Colonna 7: Tipo di saldatura ' 1 = Energia ' 2 = Tempo ' 3 = Quota assoluta ' 4 = Quta relativa Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_mode") Case 1 str = str & "Energia;" Case 2 str = str & "Tempo;" Case 3 str = str & "Q.ta Assuluta;" Case 4 str = str & "Q.ta Relativa;" Case Else str = str & "Indefinito;" End Select ' ------------------------------------------------------------------ ' Colonna 8: Valore di lavoro ' 1 = Energia -> Joule ' 2 = Tempo -> Secondi ' 3 = Quota assoluta -> mm ' 4 = Quta relativa -> mm Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_mode") Case 1 str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_value") & ";Joule;" Case 2 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_value") aux = aux / 100.0 str = str & CStr(aux) & ";s;" Case 3 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_value") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case 4 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_value") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case Else str = str & "Indefinito;-;" End Select ' ------------------------------------------------------------------ ' Colonna 9: Correzione del valore di lavoro ' 1 = Energia -> Joule ' 2 = Tempo -> Secondi ' 3 = Quota assoluta -> mm ' 4 = Quta relativa -> mm Select Case SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Weld_mode") Case 1 str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Correction") & ";Joule;" Case 2 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Correction") aux = aux / 100.0 str = str & CStr(aux) & ";s;" Case 3 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Correction") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case 4 aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Correction") aux = aux / 10.0 str = str & CStr(aux) & ";mm;" Case Else str = str & "Indefinito;-;" End Select ' ------------------------------------------------------------------ ' Colonna 10: Controllo quota iniziale aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Quote_start_target") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 11: Controllo quota iniziale (finestra) aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Quote_start_win") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 12: Controllo tempo minimo di saldatura aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Time_Min") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 13: Controllo tempo massimo di saldatura aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Time_Max") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 14: Controllo energia minima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Energy_Min") & ";" ' ------------------------------------------------------------------ ' Colonna 15: Controllo energia massima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Energy_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 16: Controllo potenza minima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Power_Min") & ";" ' ------------------------------------------------------------------ ' Colonna 17: Controllo potenza massima di saldatura str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Power_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 18: Potenza massima in test str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Power_test_Max") & ";" ' ------------------------------------------------------------------ ' Colonna 19: Quota finale per saldatura in quota assoluta -> limite minimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Final_Quote_Min") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 20: Quota finale per saldatura in quota assoluta -> limite massimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Final_Quote_Max") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 21: Quota finale per saldatura in quota relativa -> limite minimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Delta_Quote_Min") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 22: Quota finale per saldatura in quota relativa -> limite massimo aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].check_Delta_Quote_Max") aux = aux / 100.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 23: Tempo di raffreddamento aux = SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Delay_Time") aux = aux / 1000.0 str = str & CStr(aux) & ";" ' ------------------------------------------------------------------ ' Colonna 24: Avvio anticipato degli U. S. If SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Early_start") = 0 Then str = str & "NO;" Else str = str & "SI;" End If ' ------------------------------------------------------------------ ' Colonna 25: Offset str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Offset") & ";" ' ------------------------------------------------------------------ ' Colonna 26: Correzione Offset str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].Offset_correction") & ";" ' ------------------------------------------------------------------ ' Colonna 27: Ampiezza iniziale str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].perc_start") & ";" ' ------------------------------------------------------------------ ' Colonna 28: Ampiezza finale str = str & SmartTags("CMP732_TCP-IP_IS_HMI_com_log_data.Data[1].perc_stop") & ";" ' ****************************************************************** ' Aggiungo la nuova riga al file fFile_write.LinePrint str 'If PRINT_SYS_MSG Then ShowSystemAlarm(SCRIPT_NAME&" [8001] - Scritto valore Nuovo") ' ****************************************************************** 'If PRINT_SYS_MSG Then ShowSystemAlarm(SCRIPT_NAME&" [9000] - Scritto il file") ' Chiudo il file fFile_write.Close If PRINT_SYS_MSG Then ShowSystemAlarm(SCRIPT_NAME&" [9010] - Chiuso il file") End If ' Segnalo la conclusione dello script If PRINT_SYS_MSG Then ShowSystemAlarm(SCRIPT_NAME&" [9100] -> FILE: " & file_name_full) End If ShowSystemAlarm("----------------------------") ShowSystemAlarm(SCRIPT_NAME&" [9101] -> OPERAZIONE ESEGUITA CON SUCCESSO") End If SmartTags("CMP732_TCP-IP_IS_HMI_com_get_script_busy") = False SmartTags("CMP732_TCP-IP_IS_HMI_com_get_script_done") = True Else ' ============================================================================================= ' Reset variabili ' Segnale di script è in esecuzione SmartTags("CMP732_TCP-IP_IS_HMI_com_get_script_busy") = True ' Messaggio di errore attivo ' SmartTags("loc_err_msg_show") = False End If ' =============================================================================== ' Gestione errori If Err.Number <> 0 Then ' Lo script è finito (anche se con errore) ShowSystemAlarm(SCRIPT_NAME&" [9900] - Error: " & CStr(Err.Number) & " - " & Err.Description) End If End Sub Funzioni esterne: Funzione "Get_date" Function get_date(ByRef Y, ByRef M, ByRef D) ' Restituise la data attuale nel formato: "yyyymmgg" ' Data: Anno Dim dy dy = CStr(Y) ' Data: Mese Dim dm dm = CInt(M) If(dm<10) Then dm = "0" & dm End If ' Data: Giorno Dim dd dd = CInt(D) If(dd<10) Then dd = "0" & dd End If ' Restituisco la data get_date = dy & dm & dd End Function Funzione: "dir_exist_TP" Function dir_exist_TP(ByRef dirAddr) ' Verifica se il percorso di rete dato in ingresso esiste ed è raggiungibile. ' Può essere la MMC, le USB o un percorso di rete. ' -------------------------------------------------- ' par: dirAddr (String) ' Percorso di rete da testare. ' ret: 0 -> Cartella o percorso di rete trovato ' -1 -> Cartella o percorso di rete non trovato ' -------------------------------------------------- ' Accesso al file system Dim fSystem Set fSystem = CreateObject("FileCtl.FileSystem") ' Controllo se il percorso dato in ingresso è raggiungibile If(fSystem.Dir(dirAddr)="") Then ' La cartella non esiste 'ShowSystemAlarm ("dirExist [001] - Directory " & dirAddr & " not found") dir_exist_TP = -1 Else 'la cartella esiste 'ShowSystemAlarm ("dirExist [002] - Directory " & dirAddr & " found") dir_exist_TP = 0 End If End Function Funzione: "get_date_long" Function get_date_long(ByRef Y, ByRef M, ByRef D) ' Restituise la data attuale nel formato: "yyyymmgg" ' Data: Anno Dim dy dy = CStr(Y) ' Data: Mese Dim dm dm = CInt(M) If(dm<10) Then dm = "0" & dm End If ' Data: Giorno Dim dd dd = CInt(D) If(dd<10) Then dd = "0" & dd End If ' Restituisco la data get_date_long = dy & "/" & dm & "/" & dd End Function Funzione: "get_time_long" Function get_time_long(ByRef H, ByRef M, ByRef S) ' Restituise l'ora attuale nel formato: "HHMMSS" ' Ora: Ora Dim ora ora = CStr(H) If(ora<10) Then ora = "0" & ora End If ' Ora: Minuti Dim minuti minuti = CInt(M) If(minuti<10) Then minuti = "0" & minuti End If ' Ora: Secondi Dim secondi secondi = CInt(S) If(secondi<10) Then secondi = "0" & secondi End If ' Restituisco lora get_time_long = ora & ":" & minuti & ":" & secondi End Function Spero ti sia utile.
Messaggi consigliati