/* Sendet ein Zeichen an die LPT1 (unter Linux). Compilieren: `gcc -O2 -o lptsendbyte lptsendbyte.c', Als root ausfuehren: `./lptsendbyte value'. Thomas.Belmer@asamnet.de Letzte Aenderung: 2000-30-07 */ #include #include #include #ifdef unix #include #include #else #include #endif #define BASEPORT 0x378 /* lp1 */ #define FALSE 0 #define TRUE 1 #define MAX_CHARS 11 #define PROG "lptsendbyte " #define VERSION PROG "ver. 1.01, built " __DATE__ " " __TIME__ int main(int argc, char *argv[], char *envp[]) { unsigned int uiOutbyte = 0; char chPara[MAX_CHARS]; size_t st_Len = 0; int i = 0; size_t st_Last = 0; unsigned int ibase = 1; printf ("%s\n", VERSION); if (argc!=2) { printf ("Thomas.Belmer@asamnet.de\n\n"); printf ("Parameter:\n\t./"PROG"8-bit-data\n"); printf ("Examples:\n\t./"PROG"11111111b (binary value)\n"); printf ("\t./"PROG"100 (decimal value)\n"); printf ("\t./"PROG"255d (decimal value)\n"); printf ("\t./"PROG"ffh (hex value)\n"); printf ("\t./"PROG"n1 (set bit number)\n"); return (1); } strncpy (chPara, argv[1], MAX_CHARS); chPara[MAX_CHARS-1] = '\0'; st_Len = strlen (chPara); st_Last = st_Len-1; for (i=0; i<(int)st_Len;i++) {chPara[i]=toupper(chPara[i]);} if ((chPara[0]=='0')&&(chPara[st_Last]=='D')) chPara[st_Last]='\0'; uiOutbyte = atoi(chPara); if (chPara[st_Last]=='B') { uiOutbyte=0; chPara[st_Last]='\0'; if (st_Last>0) { for (i=st_Last-1;i>=0;i--) { if (chPara[i]=='1') uiOutbyte+=ibase; ibase*=2; } } } if (chPara[st_Last]=='H') { chPara[st_Last]='\0'; sscanf( chPara, "%x", &uiOutbyte ); } if ((chPara[0]=='N')&&(st_Last)) { uiOutbyte = 1; uiOutbyte <<= atoi(&chPara[1]); } uiOutbyte = (uiOutbyte > 255) ? (uiOutbyte % 256) : uiOutbyte; #ifdef unix if (ioperm(BASEPORT, 1, TRUE)) {perror("ioperm"); return(1);} outb(uiOutbyte, BASEPORT); #endif printf("Octette %02.2Xh sent to port %Xh.\n", uiOutbyte, BASEPORT); #ifdef unix if (ioperm(BASEPORT, 1, FALSE)) {perror("ioperm"); return(1);} #endif return (0); /* unsigned char inb(unsigned short _port); */ }