176 lines
5.5 KiB
Markdown
176 lines
5.5 KiB
Markdown
|
|
||
|
### If it is needed to use the PLC the script can be like this:
|
||
|
***
|
||
|
|
||
|
```pascal
|
||
|
' v 0.1 ABiasini
|
||
|
' v 0.2 MVera 31-10-23
|
||
|
Const TagsBase = "XData\Rcp\Air\"
|
||
|
Const MaxNumDeRiccete = 20
|
||
|
Const NumRecipe = 1 '1:Air 2:TTOP 3:PAck
|
||
|
Dim n
|
||
|
For n = 1 To MaxNumDeRiccete
|
||
|
|
||
|
'Prendo il Nome del formato n
|
||
|
GetDataRecordName NumRecipe, n, "XData\Rcp\NomeReceta", "XData\Rcp\NomeSetDati" ,"XData\Rcp\STATUS_NomeSetDati"
|
||
|
|
||
|
'Attendo il Risultato del Formato n
|
||
|
Do Until (SmartTags("XData\Rcp\STATUS_NomeSetDati") = 4 Or (SmartTags("XData\Rcp\STATUS_NomeSetDati")) = 12)
|
||
|
Loop
|
||
|
|
||
|
SmartTags(TagsBase & "NomeSetDati "& CStr(n)) = SmartTags("XData\Rcp\NomeSetDati")
|
||
|
SmartTags(TagsBase & "STATUS_NomeSetDati "& CStr(n))= SmartTags("XData\Rcp\STATUS_NomeSetDati")
|
||
|
Next
|
||
|
SmartTags(TagsBase & "NomeFormato") = SmartTags("XData\Rcp\NomeReceta")
|
||
|
```
|
||
|
|
||
|
|
||
|
### For the creation of the txt file without using the PLC:
|
||
|
***
|
||
|
|
||
|
We need this internal tags:
|
||
|
|
||
|
![[Pasted image 20231030135511.png]]
|
||
|
|
||
|
```pascal
|
||
|
' v 0.1 ABiasini
|
||
|
' v 0.2 MVera 31-10-23
|
||
|
' This script works with the PC and WinCE filesystem
|
||
|
' Need to change the TypeOfPanel constant
|
||
|
' The logic of this script is to read all names of the Recipe "NumRecipe"
|
||
|
' and creates a TXT file with the number and the name
|
||
|
|
||
|
|
||
|
'Define variable of script
|
||
|
Dim FolderPath, fileObj, fileSysObj, Row
|
||
|
Dim n, TagNomeSetDati, Spaces
|
||
|
|
||
|
'Definitions
|
||
|
Const MaxNumDeRiccete = 25
|
||
|
Const TagsBase = "XData\Rcp\Air\"
|
||
|
Const NumRecipe = 1 '1:Air 2:TTOP 3:PAck
|
||
|
Const FileName = "Air_RCP_Name.txt"
|
||
|
Const TypeOfPanel = "WinCE" '"WindowsPC"
|
||
|
Const TruncFormatNotExistent = 0 ' Not write the formats not existent
|
||
|
|
||
|
'Reset Status of operation (Warning)
|
||
|
SmartTags(TagsBase & "STATUS_Operation") = False
|
||
|
|
||
|
'Define Folder Address
|
||
|
On Error Resume Next
|
||
|
|
||
|
If TypeOfPanel = "WinCE" Then
|
||
|
|
||
|
'********************************
|
||
|
' WINCE
|
||
|
'********************************
|
||
|
Const fModeAppend = 8
|
||
|
FolderPath = "\Storage Card SD\FLASH"
|
||
|
Set fileSysObj = CreateObject("FileCtl.FileSystem")
|
||
|
If Err.Number <> 0 Then
|
||
|
ShowSystemAlarm "1. " & Err.Number & " " & Err.Description
|
||
|
Err.Clear
|
||
|
End If
|
||
|
|
||
|
If fileSysObj.Dir(FolderPath)="" Then
|
||
|
fileSysObj.MkDir(FolderPath)
|
||
|
If Err.Number <> 0 Then
|
||
|
ShowSystemAlarm "2. " & Err.Number & " " & Err.Description
|
||
|
Err.Clear
|
||
|
End If
|
||
|
Else
|
||
|
fileSysObj.Kill FolderPath & "\" & FileName
|
||
|
End If
|
||
|
|
||
|
fileSysObj = Nothing
|
||
|
Set fileObj = CreateObject ("FileCtl.File")
|
||
|
|
||
|
Err.Clear
|
||
|
fileObj.Open FolderPath & "\" & FileName, fModeAppend
|
||
|
If Err.Number <> 0 Then
|
||
|
ShowSystemAlarm "4. " & Err.Number & " " & Err.Description
|
||
|
Err.Clear
|
||
|
ShowSystemAlarm ("Error Opening file: " & FolderPath & "\" & FileName)
|
||
|
End If
|
||
|
|
||
|
fileObj.LinePrint("Format Nr ; Format Name")
|
||
|
If Err.Number <> 0 Then
|
||
|
ShowSystemAlarm "5. " & Err.Number & " " & Err.Description
|
||
|
Err.Clear
|
||
|
End If
|
||
|
|
||
|
For n = 1 To MaxNumDeRiccete
|
||
|
|
||
|
'Prendo il Nome del formato n
|
||
|
GetDataRecordName NumRecipe, n, "XData\Rcp\NomeReceta", "XData\Rcp\NomeSetDati", "XData\Rcp\STATUS_NomeSetDati"
|
||
|
|
||
|
'Attendo il Risultato del Formato n
|
||
|
Do Until (SmartTags("XData\Rcp\STATUS_NomeSetDati") = 4 Or (SmartTags("XData\Rcp\STATUS_NomeSetDati")) = 12)
|
||
|
Loop
|
||
|
|
||
|
If n<=9 Then Spaces = " ; "
|
||
|
If n>9 Then Spaces = " ; "
|
||
|
If n>99 Then Spaces = " ; "
|
||
|
|
||
|
If SmartTags("XData\Rcp\STATUS_NomeSetDati") = 4 Or Not TruncFormatNotExistent Then
|
||
|
fileObj.LinePrint(CStr(n) & Spaces & SmartTags("XData\Rcp\NomeSetDati"))
|
||
|
If Err.Number = 0 Then
|
||
|
ShowSystemAlarm (SmartTags("XData\Rcp\NomeSetDati") & " format added.")
|
||
|
Else
|
||
|
ShowSystemAlarm "62 " & Err.Number & " " & Err.Description
|
||
|
End If
|
||
|
End If
|
||
|
Next
|
||
|
fileObj.Close
|
||
|
ShowSystemAlarm (FileName & " written succesfully.")
|
||
|
|
||
|
'Reset Status of operation (Warning)
|
||
|
SmartTags(TagsBase & "STATUS_Operation") = True
|
||
|
|
||
|
Else
|
||
|
'********************************
|
||
|
' WINDOWS PC
|
||
|
'********************************
|
||
|
|
||
|
FolderPath = "C:\FLASH"
|
||
|
Set fileSysObj = CreateObject("Scripting.FileSystemObject")
|
||
|
|
||
|
If Not fileSysObj.FolderExists(FolderPath) Then
|
||
|
fileSysObj.CreateFolder FolderPath
|
||
|
End If
|
||
|
Set Row = fileSysObj.CreateTextFile(FolderPath & "\" & FileName,True)
|
||
|
|
||
|
Row.WriteLine "Format Nr ; Format Name"
|
||
|
|
||
|
For n = 1 To MaxNumDeRiccete
|
||
|
|
||
|
'Prendo il Nome del formato n
|
||
|
GetDataRecordName NumRecipe, n, "XData\Rcp\NomeReceta", "XData\Rcp\NomeSetDati", "XData\Rcp\STATUS_NomeSetDati"
|
||
|
|
||
|
'Attendo il Risultato del Formato n
|
||
|
Do Until (SmartTags("XData\Rcp\STATUS_NomeSetDati") = 4 Or (SmartTags("XData\Rcp\STATUS_NomeSetDati")) = 12)
|
||
|
Loop
|
||
|
|
||
|
If n<=9 Then Spaces = " ; "
|
||
|
If n>9 Then Spaces = " ; "
|
||
|
If n>99 Then Spaces = " ; "
|
||
|
|
||
|
If SmartTags("XData\Rcp\STATUS_NomeSetDati") = 4 Or Not TruncFormatNotExistent Then Row.WriteLine(CStr(n) & Spaces & SmartTags("XData\Rcp\NomeSetDati"))
|
||
|
Next
|
||
|
|
||
|
Row.Close
|
||
|
|
||
|
'Reset Status of operation (Warning)
|
||
|
SmartTags(TagsBase & "STATUS_Operation") = True
|
||
|
|
||
|
|
||
|
End If
|
||
|
|
||
|
```
|
||
|
|
||
|
With this script the HMI reads all recipes and creates the file.txt with the desired format. Also if the number of recipes increment is very easy to change.
|
||
|
|
||
|
There is completely different to use the file system on WinCE or in Windows.
|
||
|
|
||
|
|