hi leute! ich habs jetzt hinbekommen...
Code:
/* A SIMPLE LED CONTROLER
* you are able to change the led
* state with a FERNBEDIEHNUNG
* (C) 2006 --linuxuser--
* e-mail: unix4ever@gmx.at
* Version 1.0
*/
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <ctype.h>
#include <assert.h>
#define OUTPUT "/dev/tty1"
#define INPUT "/dev/ttyS0"
#define ENDLOS 1
#define FAIL 0
#define SUCC 1
#define BAUDRATE B2400
/*lights*/
#define NOLIGHT 0x0
#define ALLLIGHT 0X7
#define RLIGHT 0X1
#define MLIGHT 0x4
#define LLIGHT 0x2
/*keys on the "FERNBEDIENUNG"*/
#define FBDK_OFF 0xFE06
#define FBDK_CD 0x4015FE33
int setLight(int output, const unsigned int state){
/*a very primitive method*/
if(ioctl(output, KDSETLED, state)){
fprintf(stderr, "KONNTE LICHT NICHT EINSCHALTEN!!!\n");
return FAIL;
}/*end if*/
return SUCC;
}/*end if*/
int main(void){
int states[5] = {NOLIGHT, ALLLIGHT, RLIGHT, MLIGHT, LLIGHT}; /*all implemented states*/
int recived_bytes; /*how many bytes have recived?*/
unsigned int inputByte = 0; /*the byte comes in from the COM1 port*/
unsigned int buffer = 0;
int output; /*the keyboard*/
int input; /*COM1*/
struct termios newtio; /*settings for the RS-232 "CONSOL"*/
int i = 0;
/*open the input*/
input = open(INPUT, O_RDWR | O_NOCTTY | O_NDELAY);
if(input == -1){
fprintf(stderr, "Fehler beim oeffnen der Seriellen schnittstelle: %s!\n", INPUT);
}/*end if*/
/*open the output*/
output = open(OUTPUT, O_WRONLY);
if(output == -1){
fprintf(stderr, "FEHLER bein oeffnen des outputS: %s!\n", OUTPUT);
return 0;
}/*end if*/
/*configure the RS-232 port*/
fcntl(input, F_SETFL, FNDELAY);
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD ;
newtio.c_iflag = IGNPAR | ICRNL ;
newtio.c_oflag = 0;
newtio.c_lflag &= ~(ICANON);
/*set configuration*/
tcflush(input, TCIOFLUSH);
tcsetattr(input, TCSANOW, &newtio);
/*start the main loop*/
while(ENDLOS){
system("clear");
/*read the input*/
recived_bytes = read(input, &inputByte, 4);
/*put the input out on the consol*/
printf("(c)Rainer Sickinger\nGelesenesBytes: 0x%x\n", inputByte);
if(buffer != inputByte){
setLight(output, states[i]);
i++;
if(i == 4) i = 0;
}/*end if*/
buffer = inputByte;
sleep(1);
}/*end while*/
/*close the file deskriptorz*/
close(input);
close(output);
return 0;
}/*end main*/
DANKE nochmal!
Lesezeichen