Skip to main content
replaced http://abyz.co.uk/ with http://abyz.me.uk/
Source Link

How do I need to modify the C example from http://abyz.co.uk/rpi/pigpio/examples.htmlhttp://abyz.me.uk/rpi/pigpio/examples.html for continious monitoring of Wiegand readers?

I need to run it as background process.

For now I have a code:

#include <stdio.h>
#include <pigpio.h>
#include "wiegand.h"


void callback1(int bits, uint32_t value)
{

    FILE *saved = stdout;
    stdout = fopen("log_readers.txt", "a");
    printf("Reader_1: bits=%d value=%u\n", bits, value);
    fclose(stdout);
    stdout = saved;
}

void callback2(int bits, uint32_t value)
{
   FILE *saved = stdout;
   stdout = fopen("log_readers.txt", "a");   
   printf("Reader_2: bits=%d value=%u\n", bits, value);
   fclose(stdout);
   stdout = saved;
}

int main(int argc, char *argv[])
{
   Pi_Wieg_t * w1;
   Pi_Wieg_t * w2;
   if (gpioInitialise() < 0) return 1;
   w1 = Pi_Wieg(14, 15, callback1, 5);
   w2 = Pi_Wieg(23, 24, callback2, 5);
   sleep(300);
   Pi_Wieg_cancel(w1);
   Pi_Wieg_cancel(w2);
   gpioTerminate();
}

After 5 minutes of execution it's terminated, I suppose cause of sleep(300). If I wrap it by infinite loop like this:

int main(int argc, char *argv[])
    {
    while(0) {
      Pi_Wieg_t * w1;
      ...
    }
}

it's terminated immediately after running.

How do I need to modify the C example from http://abyz.co.uk/rpi/pigpio/examples.html for continious monitoring of Wiegand readers?

I need to run it as background process.

For now I have a code:

#include <stdio.h>
#include <pigpio.h>
#include "wiegand.h"


void callback1(int bits, uint32_t value)
{

    FILE *saved = stdout;
    stdout = fopen("log_readers.txt", "a");
    printf("Reader_1: bits=%d value=%u\n", bits, value);
    fclose(stdout);
    stdout = saved;
}

void callback2(int bits, uint32_t value)
{
   FILE *saved = stdout;
   stdout = fopen("log_readers.txt", "a");   
   printf("Reader_2: bits=%d value=%u\n", bits, value);
   fclose(stdout);
   stdout = saved;
}

int main(int argc, char *argv[])
{
   Pi_Wieg_t * w1;
   Pi_Wieg_t * w2;
   if (gpioInitialise() < 0) return 1;
   w1 = Pi_Wieg(14, 15, callback1, 5);
   w2 = Pi_Wieg(23, 24, callback2, 5);
   sleep(300);
   Pi_Wieg_cancel(w1);
   Pi_Wieg_cancel(w2);
   gpioTerminate();
}

After 5 minutes of execution it's terminated, I suppose cause of sleep(300). If I wrap it by infinite loop like this:

int main(int argc, char *argv[])
    {
    while(0) {
      Pi_Wieg_t * w1;
      ...
    }
}

it's terminated immediately after running.

How do I need to modify the C example from http://abyz.me.uk/rpi/pigpio/examples.html for continious monitoring of Wiegand readers?

I need to run it as background process.

For now I have a code:

#include <stdio.h>
#include <pigpio.h>
#include "wiegand.h"


void callback1(int bits, uint32_t value)
{

    FILE *saved = stdout;
    stdout = fopen("log_readers.txt", "a");
    printf("Reader_1: bits=%d value=%u\n", bits, value);
    fclose(stdout);
    stdout = saved;
}

void callback2(int bits, uint32_t value)
{
   FILE *saved = stdout;
   stdout = fopen("log_readers.txt", "a");   
   printf("Reader_2: bits=%d value=%u\n", bits, value);
   fclose(stdout);
   stdout = saved;
}

int main(int argc, char *argv[])
{
   Pi_Wieg_t * w1;
   Pi_Wieg_t * w2;
   if (gpioInitialise() < 0) return 1;
   w1 = Pi_Wieg(14, 15, callback1, 5);
   w2 = Pi_Wieg(23, 24, callback2, 5);
   sleep(300);
   Pi_Wieg_cancel(w1);
   Pi_Wieg_cancel(w2);
   gpioTerminate();
}

After 5 minutes of execution it's terminated, I suppose cause of sleep(300). If I wrap it by infinite loop like this:

int main(int argc, char *argv[])
    {
    while(0) {
      Pi_Wieg_t * w1;
      ...
    }
}

it's terminated immediately after running.

Source Link
Paul Serikov
  • 133
  • 1
  • 1
  • 4

How to continiously monitor Wiegand readers using pigpio library?

How do I need to modify the C example from http://abyz.co.uk/rpi/pigpio/examples.html for continious monitoring of Wiegand readers?

I need to run it as background process.

For now I have a code:

#include <stdio.h>
#include <pigpio.h>
#include "wiegand.h"


void callback1(int bits, uint32_t value)
{

    FILE *saved = stdout;
    stdout = fopen("log_readers.txt", "a");
    printf("Reader_1: bits=%d value=%u\n", bits, value);
    fclose(stdout);
    stdout = saved;
}

void callback2(int bits, uint32_t value)
{
   FILE *saved = stdout;
   stdout = fopen("log_readers.txt", "a");   
   printf("Reader_2: bits=%d value=%u\n", bits, value);
   fclose(stdout);
   stdout = saved;
}

int main(int argc, char *argv[])
{
   Pi_Wieg_t * w1;
   Pi_Wieg_t * w2;
   if (gpioInitialise() < 0) return 1;
   w1 = Pi_Wieg(14, 15, callback1, 5);
   w2 = Pi_Wieg(23, 24, callback2, 5);
   sleep(300);
   Pi_Wieg_cancel(w1);
   Pi_Wieg_cancel(w2);
   gpioTerminate();
}

After 5 minutes of execution it's terminated, I suppose cause of sleep(300). If I wrap it by infinite loop like this:

int main(int argc, char *argv[])
    {
    while(0) {
      Pi_Wieg_t * w1;
      ...
    }
}

it's terminated immediately after running.