Nextra wrote:

Sajna azt sem tudom hgy kezdjek neki. Annak idején foglalkoztam a basic-cel, később a dos-os batch-okat is kipróbáltam, de ezeknek már vagy 10 éve.

Osszedobtam neked egy kis programot, ebbol kiindulhatsz. Ha nem megy, keress meg maganban.

Mukodes: 1 masodpercenkent ranez a megadott parhuzamos portra, es ha valamelyik bit megvaltozik, akkor elinditja a megadott programot. Kulon megadhatod, hogy mi tortenjen 0->1 eseten, es kulon 1->0 eseten. A shell-el hajtatja vegre, tehat akarmit megadhatsz neki.

Leforditani:

gcc -Wall -O2 -o parport parport.c

-------- cut here ---------

#include <sys/io.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>

typedef unsigned char byte;
typedef unsigned short int word;
typedef unsigned int dword;
typedef bool boolean;

#define ParallelPort    0x378

struct {
  byte Mask;
  const char * ExecIfGoesOn;
  const char * ExecIfGoesOff;
} ActionDesc[]={
  { 0x01, "echo \"bit 0: 0->1\"", "echo \"bit 0: 1->0\"" },
  { 0x02, "echo \"bit 1: 0->1\"", "echo \"bit 1: 1->0\"" },
  { 0x04, "echo \"bit 2: 0->1\"", "echo \"bit 2: 1->0\"" },
  { 0x08, "echo \"bit 3: 0->1\"", "echo \"bit 3: 1->0\"" },
  { 0x00, NULL, NULL }
};

byte OldValue=0x00;
byte CurrentValue;

int main(void) {
  byte XorValue;
  int i;
  if (ioperm(ParallelPort,1,1)!=0) {
    perror("ioperm");
    return (1);
  }
  while (true) {
    const char * ExecStr;
    CurrentValue=inb(ParallelPort);
    XorValue=CurrentValue^OldValue;
    i=0;
    while (XorValue!=0x00 && ActionDesc[i].Mask!=0x00) {
      if ((XorValue & ActionDesc[i].Mask)!=0) {
        if ((CurrentValue & ActionDesc[i].Mask)!=0)
          ExecStr=ActionDesc[i].ExecIfGoesOn;
        else
          ExecStr=ActionDesc[i].ExecIfGoesOff;
        system(ExecStr);
      }
      i++;
    }
    OldValue=CurrentValue;
    sleep(1);
  }
}

-------- cut here ---------

Sziasztok: Zsolt

_________________________________________________
linux lista      -      [email protected]
http://mlf2.linux.rulez.org/mailman/listinfo/linux

válasz