Wincc 2008 Flex Script Read a datalog into an array

drip

Member
Join Date
Jan 2009
Location
canada
Posts
59
Hello,
I am currently in the middle of a project and looking to read data from a .csv file on a server. I need to read this data and get it into the PLC so I can then compare the information for some necessary checks of validation. I have wrote a script already that can read the data, but I do not know how to save it to an array or structure and bring it into the PLC. Can any help point me in the right direction or provide any examples?

Here is my existing script:

'Declaration of local tags -
Dim fso, f, ts, Path, field, MyZf, i, j, k, HiField(2,6)


'Definition of local tags -
i=0
j=0
k=0

Path = "C:\Datalog1.csv"


'Error Routine -
On Error Resume Next

'Create object -
Set fso = CreateObject("Scripting.FileSystemObject")

If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If

Set f = fso_OpenTextFile(Path, 1, 0, -2)

If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If

'Loop
Do While f.AtEndOfStream <> True

MyZf = f.ReadLine
field = Split(MyZf, ",")

For i=0 To 6
field(i) = Replace(field(i), " ", "")
HiField(j, i) = field(i)

Next

j = j + 1
Loop

SmartTags("szString_1") = HiField(0,1)
SmartTags("nValue_1") = HiField(1,1)
SmartTags("nValue_2") = HiField(2,1)


'Close file
f.Close

Set f = Nothing
Set fso = Nothing

ShowSystemAlarm "Readout of the data was successful!"
'// EOS /////////////////////////////////////////////////////////


The bolded Hifield information is what I am looking to stick into an array. I have 7 columns of information that I am looking to read for each row, and up to 1000 rows.
Is there a way I could use a structure so I could have the labels for each column (ie- date, torque, part #....)? Or I could live with sticking it in a array as 1a,1b,1c,1d,1e,1f,1g for each row incrementing the number. Any help would be appreciated thanks!
 
Tags in WinCC Flex can only have one dimension, regardles that you can make multidemensional arrays in the PLC
(i.e. "MyDB".MyArray[0..10,0..10]).
The best I can suggest is to create one array in the HMI where it is implied that the dimensions of the PLC array are appended after each other.
For example "MyDB".MyArrayA[0..10], followed by "MyDB".MyArrayB[0..10].

Then distribute the values like this
smarttags("MyDB.MyArray")(i) = HiField(i,0)
smarttags("MyDB.MyArray")(i+10) = HiField(i,1)

The transfer of the values from the HMI tags to the PLC occurs automatically.
 
Ok thanks I see your logic and that makes sense and should work.
My question though is how do I declare the HMI array so that the arrays are appended to one another?

I create the tags in HMI and switch the array elements to my desired number, but for the joining for them is that something I do in the tags editor or do I have to declare it in the script?

Or is there way way to write the HIField array to an HMI tag created array?
 
Maybe these screen shots will help. Because you can only have one dimension you must break the two dimension array into two variables. I would suggest doing this when you read the file in from the script.

The screen shots I show are from reading an array out of the plc and putting it into a text file via WinCC Flex Script. I have tried to go the other way but I have had problems. First my array size is 500 long. The script will read the data in and put it into the array but WinCC Flexible has problems sending the data down to the plc. I think it just overloads and kills the script. I have gotten it to work by sending only 25 at a time then waiting a second then another 25 etc, etc. This works but is very slow. Because of this being slow I removed loading from a file from my project. I would very much like to get this to work so if you come up with a solution let me know.

tag_array.jpg tag_array_DB.JPG tag_array_script.jpg
 
I got the arrays to work and for the data to load into the PLC testing with a dummy file. I now have a new problem, because the serial codes are 37 characters in length this is too long for my integers to process and there is also a date format which gives characters that stops the script. I wanted to use an array of strings, but that is not possible so I am going to try to look into structures to create an array.

I will let you know when I come across something charles, as I will get this going sooner or later, somehow.
 

Similar Topics

Hi, I have WinCC Felxible 2008 SP5 installed on my Windows 10. I want to program Simatic panel TP177B using USB transfer cable. But i can't...
Replies
8
Views
2,120
Hello! Another weird request from the swede with customers that doesn´t like to pay for quality in first place... Is there any way to have a...
Replies
8
Views
2,684
Hi! I'm a little lost here. I have made a script in VB that run perfect when I simulate it on my programming machine (Windows 8.1) But when I...
Replies
9
Views
2,789
Hi! Writing this in a hurry. Today we made a break at a factory and I should download new s7-1200 program and a new WinCC Flex 2008 RT program...
Replies
0
Views
2,244
hi guys,,can i personalize data logging in wincc flex? i mean i want to make a table that shows log data in a better platform than in wincc,,,i...
Replies
1
Views
1,426
Back
Top Bottom