WinCC Continuous CSV read

SYED.ABIDI

Member
Join Date
Mar 2013
Location
SINGAPORE
Posts
7
Dear All,

I need urgent help on the following issue about WinCC:

I have button which once clicked will run the following script to read contents of a CSV file. However I want to make this process continuous so that I don't have to click the button again to read the updated contents of CSV. Please suggest asap.

Code:
#define MaxLineLength 80
   FILE *fpFile;
   char *strTag, *strValue, *pTmp;
   char buffer[MaxLineLength];
   double  dVal;
   fpFile = fopen(GetTagChar("Filename"), "r" ); //open file to read
   printf ("C-Script: read file: %s\r\n", GetTagChar("Filename"));
   if (fpFile !=NULL)
   {
       while (fgets (buffer, MaxLineLength , fpFile))
       {
           strTag = buffer;
           // Split String and cut  carriage return
           pTmp = strchr(buffer, (int)',');
           *pTmp = '\0';
           strValue = ++pTmp;
           strValue[strlen(strValue)-1] = '\0';

           // Search for ',' and replace with '.'
           pTmp  = strchr(strValue, (int)',');
           if (pTmp != NULL){
               *pTmp = '.';
           }

           // Convert Value-String to double and write to WinCC
           sscanf (strValue , "%lf", &dVal);            
           SetTagDouble(strTag,dVal);
           printf("%s  Value: %lf\r\n", strTag, dVal);

       }
       fclose(fpFile); //close file
   } else {
       printf ("Error: File not found!\n");
   }
 
I'm pretty sure you can't open a file for reading until the other process that is writing to it has closed it. So, you'll need some kind of semaphore or flag from the other process to replace your push button.
 
Wincc - Read out of an Excel file

Hi,

Thanks for the reply,

I tried putting the above code in an infinite while loop and it does read the file data being updated conitnuously and it was chenging in wincc also. However the issue is if I cahnge to some other screen in WinCC runtime this process stops šŸ™ƒ

For the CSV file, I am creating and deleting a file continuously to update it and that is then read by the WinCC using above mentioned code.

Thanks

Khyzer
 
Not knowing WinCC yet, isn't there a script that can be executed when the display is opened? I seem to remember doing something like you're doing with ProTool Pro.
 
Hi
I dont have WinCC at the moment but as far as I remember You can use Scheudler and trigger this script in period time. The problem is that minimum setting for time is 1 minute. If 1 minute is ok for you then use this, if not then create in PLC memory bit and make a rectangle generator (eg. 1 second on, 1 second off). When you have it then create in WinCC variable for this memory bit and attach one of the event called ON VALUE CHANGE (I guess it was like that).
Cheers
 
I'm pretty sure you can't open a file for reading until the other process that is writing to it has closed it. So, you'll need some kind of semaphore or flag from the other process to replace your push button.


Not sure if the c-script in WinCC can do it, but you could use streaming.
This is what we do to archive data from .csv files that are kept 'open and in use' by our OP270 logging system.



Not knowing WinCC yet, isn't there a script that can be executed when the display is opened? I seem to remember doing something like you're doing with ProTool Pro.


Both in WinCC and WinCC Flex can this be done using the Open picture event.
But in both cases I would not recommend using a single event to trigger a continuous script.


Hi
I dont have WinCC at the moment but as far as I remember You can use Scheudler and trigger this script in period time. The problem is that minimum setting for time is 1 minute. If 1 minute is ok for you then use this, if not then create in PLC memory bit and make a rectangle generator (eg. 1 second on, 1 second off). When you have it then create in WinCC variable for this memory bit and attach one of the event called ON VALUE CHANGE (I guess it was like that).
Cheers


And this is where we notice a crucial piece of information is missing.
It was never specified that WinCC or WinCC Flex is being used.
Some people, like Rafal, are inclined to think it's WinCC flex you are talking about.
While others recognise the language being used and know it's not possible in WinCC Flex, therefor it must be WinCC.
It would be nice to exclude the one not being referenced.


As I said, you might want to look into Global scripts.
These will run at a specified interval, without regard to the current active picture.
Any script linked to/triggered by (an object in) a picture will stop running when you change pictures.
There is a recent thread around here that can help you in configuring said Global scripts.
 
Dear All,

Thanks for your replies. I am using WinCC not WinCC Flexible. I tried to run the script under global scipts but seems like it doesnt work :( could any one help me in pointing out if any changes required to run this script under Global script?

Code:
{

#define Tag_1 "SetBit"

while (Tag_1==1)
{
   #define MaxLineLength 80

   FILE *fpFile;
   char *strTag, *strValue, *pTmp;
   char buffer[MaxLineLength];
   double  dVal;
   fpFile = fopen(GetTagChar("Filename"), "r" ); //open file to read
   printf ("C-Script: read file: %s\r\n", GetTagChar("Filename"));
   if (fpFile !=NULL)
   {
       while (fgets (buffer, MaxLineLength , fpFile))
       {
           strTag = buffer;
           // Split String and cut  carriage return
           pTmp = strchr(buffer, (int)','); // Changed ";" to "," 
           *pTmp = '\0';
           strValue = ++pTmp;
           strValue[strlen(strValue)-1] = '\0';

           // Search for ',' and replace with '.'
           pTmp  = strchr(strValue, (int)',');
           if (pTmp != NULL){
               *pTmp = '.';
           }
          
           // Convert Value-String to double and write to WinCC
           sscanf (strValue , "%lf", &dVal);            
           SetTagDouble(strTag,dVal);
           printf("%s  Value: %lf\r\n", strTag, dVal);
       }
       fclose(fpFile); //close file
   } else {
       printf ("Error: File not found!\n");
   }
}
 
To further explain this, I am not using PLC at all, so I would have to use any trigger within WinCC.
Can anyone elaborate on how to run this script as a global script.

One more issue is infinite while loop, when I use it I can't exit out of WinCC run-time and if don't use this loop I can't read the values continuously from the csv file and I have to click the read button every time to read the updated value from CSV.
 

Similar Topics

Dear Experts and Friends, I am trying to read sensor's readings from a CSV file on the same PC which is running WinCC. That CSV file is...
Replies
0
Views
2,758
In our production plant we have multiple different networks (subnets). IT dept have setup routing between them so different subnets can...
Replies
0
Views
49
Is it possible to connect a PC with running WinCC Advanced or Unified to a siemens PLC such as S7-1200 across different subnets? The computers can...
Replies
0
Views
53
We are using wincc scada WinCC system software V7.5 SP2 , connected to few plc . Past 3 weeks we getting this alarm continously when we checked...
Replies
0
Views
64
Hello, I have a quick question. I have been using scripts to change the color of buttons. The reason, I am usually using multiple hmiruntime.tags...
Replies
1
Views
81
Back
Top Bottom