Wincc internal Stopwatch

Ghourab

Member
Join Date
Jan 2016
Location
South Africa
Posts
30
Dear respected engineers

I want to make a production downtime stopwatch without using step7
only by using Wincc.

I have a signal of failure equal true during failure.

I need an output Number on the wincc screen showing the time during stopping
 
I guess you could do this with VB script, have you looked at that?
 
its appreciated for any help in this issue as I didn't find via internet any wincc internal stopwatch I only got an individual c# code but it didn't work with wincc.
 
I want to make a production downtime stopwatch without using step7
only by using Wincc.

I have a signal of failure equal true during failure.

I need an output Number on the wincc screen showing the time during stopping
 
There is more than one way you can do it.

If you want to keep the history of the events, I'd use the WinCC alarm logging functionality. Set an alarm when the event comes, and set it back when it goes. You can use also internal tags for alarm trigger, or just create an event message manually via script function. In the alarm control you can see when the event came in, and the duration of the event. You can append additional values (or text messages) to the event.

Another solution could be, to use two interval variables to save the current time as unix-timestamp (signed 32 bit). When event comes, use standard time() function from time.h, and save the starting-time to internal-timestamp1. The time (duration) the event is on, is the difference from the current result of time() to the start-time you've saved before..
When the event goes, save the timestamp to internal-timestamp2, and you can show the user how long the last event was on, by subtracting the two values.
If you want, you can recalculate the localtime from the timestamps you've stored, so the user would see the date/time and not the seconds from the unixtime.
 
thanx for interst Mr Thomas :

if it possible for you to send me a way for showing the second method that you send with c# code or visual basic and detailed steps it will be a pleasure for me as I'm a wincc beginner
 
Example of a stopwatch on internal variables, start and stop is done by a button

Internal variables:
- StopwatchRunning: bool
- StopwatchStarttime: signed 32-Bit integer
- StopwatchStoptime: signed 32-Bit integer

Place a button which starts / stops the stopwatch:
Code:
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
  BOOL running;
  time_t t1;
  time(&t1);

  running = GetTagBit("StopwatchRunning");
  if (running) {
    SetTagBit("StopwatchRunning", 0);
    SetTagSDWord("StopwatchStoptime" ,(int)t1);
  } else {
    SetTagBit("StopwatchRunning", 1);
    SetTagSDWord("StopwatchStarttime" ,(int)t1);
  }
}
Place two IO-Fields which display the start and the stoptime. Use data format "String".
Add on Attribute "Outputvalue" a C-Script, triggered by StopwatchStarttime / StopwatchStoptime:
Code:
char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
  long int t1;
  time_t t2;
  char *s;
  struct tm *timeinfo;

  t1 = GetTagSDWord("StopwatchStarttime");
  t2 = (time_t)t1;
  timeinfo = localtime(&t2);
  s = SysMalloc(100);
  sprintf(s, "%s", asctime(timeinfo));
  return s;
}
If you need a different display format for the datetime, you can use your own format function instead of using asctime. You'll find lots of information about datetime formatting in C, as this is nothing special for WinCC.

If you need the actual runtime in seconds, add another IO-field with data format "Decimal" and the following C-script:
Code:
double _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
  BOOL running;

  long int t1;
  long int tt2;
  time_t t2;

  running = GetTagBit("StopwatchRunning");
  t1 = GetTagSDWord("StopwatchStarttime");
  if (running) {
    time(&t2);
    return (double) ((long int)t2 - t1);
  } else {
    tt2 = GetTagSDWord("StopwatchStoptime");
    return (double) tt2 - t1;
  }
}
 

Similar Topics

Hi everyone, Can someone tell me if it is possible to use an internal tag in WinCC 7.2 to trigger a bit in a DB. My setup is as follows; S7...
Replies
1
Views
2,646
Hi, I have an existing winCC flexible project that connects to a CPU315-2dp. There is an I/O field on the HMI screen that writes to an internal...
Replies
0
Views
3,016
I am a little confused by a program that I am looking at. So If I got this correct multiplexing is using indirect addressing (Which points to an...
Replies
4
Views
3,864
In Flex sp2 in faceplate editor, I want to make a button visible when a external tag from plc (mw100) has value 4. In the designer, I can only...
Replies
5
Views
5,231
is it possible in winCC flexible 2008 to go onLine with recipe's variables in the panel memory? (MP277) I've written a script that should save...
Replies
2
Views
1,687
Back
Top Bottom