WinCC text file logging

Doug_Adam

Member
Join Date
Sep 2002
Location
Perth
Posts
948
This is a problem that has been dogging me for a month.
I am trying to set up a method of logging the current values of some variables (or tags) in WinCC to a text file.
.txt or .csv doesn't matter.
WinCC seems to have many methods for getting information into it, but it greedyly holds this infomation and does not let it go.

The main method I have been trying is to use the C script fprintf function.

Example of a test piece:

File *Fp;

Fp = fopen ("c:\\test.txt", "a");

fprintf(Fp, "Testing Testing 123 \n");

fclose(Fp):

After compiling and debugging, I get no errors, but no file is created and nothing is logged. I haven't tried an actual variable yet, since if this doesn't work, a variable would not work either.

Anyone have any ideas, tips or pointers?

Thanks,

Doug
 
Doug_Adam said:
After compiling and debugging, I get no errors, but no file is created and nothing is logged. I haven't tried an actual variable yet, since if this doesn't work, a variable would not work either.

So the problem is the creation of the log file and not so much capturing the tag values. You could add printf statements to your script to send debug data to the output window of the APDIAG tool (or to such a window in your *.PDL). This allows you to monitor your script. Any programming errors will also show up in this window.

How is the script triggered? If this is not going to be triggered by a manual (mouse) action then you could use an acyclic event triggered by a tag change. Depending on your project setup, you should either include global scripting in the startup properties of your computer or on the server.

Also be sure to properly declare any character variables; WinCC's ANSI C is an unforgiving environment.
 
small detail

Doug_Adam,

I'm not sure but I think your problem could be that you forgot the + after the "a". This is a piece of my code:
fich = fopen("c:\\log.txt","a+");
fprintf(fich,"%24.24s;%f\n",cadena,f);
fclose(fich);
If I'm correct:
"a" means append.
"a+" means append if the file exists, if it doesn't exist create.

Best Regards,
Kelkoon
 
Thanks to Stplanken and Kelkoon.
I have to laugh when I finally worked out the problem......

I actually didn't use the double slash when when I setup the code.
Instead of Fp = fopen ("c:\\test.txt", "a");
I wrote Fp = fopen ("c:\test.txt", "a");

I got it right in my original notes, but wrong when I typed it in.
How I missed it, I don't know...

I also changed the a to and a+, I think I will change it back and see what happens.

Thanks again,

Doug
 
Doug_Adam said:
I also changed the a to and a+, I think I will change it back and see what happens.

Good you got it working. I checked and I never used the "a+" in my old scripts, just "a" (is "a+" also part of ANSI C?). I changed all scripts to VBS as soon as v6 came out (personal preference).
 

Similar Topics

On my HMI (KTP1200), I've got this button "Generate Report", which generates a report (CSV) when it's pressed. (see pic) While it's being...
Replies
1
Views
543
Just a quick query to all, On site we use WinCC 2008 for HMI screens, some of the code has been written by other engineers and to determine the...
Replies
2
Views
1,371
Hi Everyone, One of the projects we have has a very large number of scripts that require translating. It would be great if we could export the...
Replies
3
Views
1,857
Hello, Does anyone know of a method to make text in faceplate configurable in interface of faceplate? I tried to use wstring tag and that tag in...
Replies
2
Views
5,255
Back
Top Bottom