port LPT sterowany ze strony www

Loading thread data ...

Był sob, 06. sierpień 2005 13:41 gdy "Nikon" snipped-for-privacy@o2.pl napisał(a):

Wystarczy prosty program w C(lub czymkolwiek innym) który pobiera jako parametr stan portów i tak je ustawia. W zależności od trybu uzyskiwania dostępu do portu, w bezpiecznych systemach operacyjnych może być konieczne ustawienie bitu SUID dla tego programu.

Do tego frontend w php który oferuje klikalny interfejs i po zmianie na stronie www uruchamia program z odpowiednimi parametrami.

Reply to
Tomek Głuch

a mozna gdzies znalesc jakiego gotowca lub dokladny opis ??

Nikon

Reply to
Nikon

Witam

Było kiedyś opisane w CHIP'ie, i sprzet i program, ale nie pamiętam kiedy.

Jarek

Reply to
Jarek

Nikon napisał(a):

google i kierunki poszukiwań:

1) CGI 2) Apache 3) inpout32

  • śjakiś kompilator dowolnego(1) języka programowania.

1: No... bez przesady ale wielu.
Reply to
Sebastian Biały

Był sob, 06. sierpień 2005 14:22 gdy "Nikon" snipped-for-privacy@o2.pl napisał(a):

w php może dany program uruchomić na przykład w następujący sposób:

system("sudo /sciezka $zmienna1 $zmiennakolejnan" ,$retval);

a tu szkielet programu w C: #include <stdio.h>

#include <unistd.h>

#include <asm/io.h>

#define BASEPORT 0x378 //adres rejestrow portu rownoleglego int main(int argc, char *argv[]) { int status; ioperm(BASEPORT,3,1); // printf("ioperm for LPT....OK\n"); int i=0; //ustawia zero na liniach DATA0..7 outb(i,BASEPORT);

status=inb(BASEPORT+1); //pobiera stan bitow stanu printf("Stan portu: %d \n",status);

ioperm(BASEPORT,3,0); printf("disabled ioperm for LPT....OK\n"); return(0); }

da się to oprogramować lepiej ale to jest najprostsze rozwiązanie, cały port rownoległy zajmuje trzy kolejne bajty od BASEPORT

Reply to
Tomek Głuch

tego uzywam do resetu wieszajacego sie AccessPointa WiFI via przekaznik podpiety do LPT.

#include <stdio.h>

#include <unistd.h>

#include <asm/io.h>

#include <string.h>

#define BASEPORT 0x378 /* lp1 */

void help(char *msg) { fprintf (stderr,"

*** lptout ***************************************************************

ERROR: %s

usage: lpt_out [port] [param] bits params: port port number ex. 1 b all bits ex. 10-00101 (- means do not change) n number ex. 133 example: lpt_out 1 b 01101100\n\n",msg); };

char dupa[25];

int main(int argc, char **argv) { int x=0, y; unsigned char z; int last, output, length; char bits; // czy bity, czy liczba int port_number; if (argc!=4) { help("To few parameters"); return 2; };

// sprawdza poprawnosc parametrow we/wy if (!(sscanf(argv[1],"%d",&port_number))) { fprintf(stderr,"invalid port number\n\n"); return 2; }; if (port_number>2) { help("Port number must be 1 or 2"); return 2; }; // sprawdza poprawnosc parametru if (strlen(argv[2])!=1) { help("Bad parameter"); return 2; }; switch(argv[2][0]) { case 'b': bits=1; break; case 'n': bits=0; break; default: help("Bad parameter"); return 2; };

/* Get access to the ports */ if (ioperm(BASEPORT, 5, 1)) {perror("ioperm"); exit(1);}

if (!bits) {// jesli cyfra length=strlen(argv[3]); for (x=0;x<length;x++) { if (argv[3][x]>57 || argv[3][x]<48) { help("bad output value"); return 2; }; }; if (!(sscanf(argv[3],"%d",&output))) { help("Bad output value"); return 2; }; if (output>255 || output<0) { help("output number must be beetween 0 and 255"); return 2; }; // jak tutaj doszedl to w output jest wartosc ktora wyslac do portu }; // if !bits

if (bits) { length=strlen(argv[3]); if (length!=8) { help("bad output value length (must be 8)"); return 2; }; for (x=0;x<length;x++) { if (!(argv[3][x]=='1' || argv[3][x]=='0' || argv[3][x]=='-' )) { help("bad output value"); return 2; }; }; // for

last= inb(BASEPORT + 3);

output=0; z=0; for (x=0;x<length;x++) { y=1; y=y<<x; if (argv[3][x]=='1') output+=y; if (argv[3][x]=='-') { z=last>>x; z=z<<7;z=z>>7-x; output+=z; }; }; }; // if bits

outb(output,BASEPORT);

printf("current port status: %d\n", inb(BASEPORT + 3));

/* We don't need the ports anymore */ if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}

exit(0); }

Reply to
Marcin Szczepaniak

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.