Hey, hier Robert. ich habe ein USB Game Controller und wollte mit dem ein einfaches selbst geschriebenes Spiel steuern. Das Spiel Existiert noch nicht, da ich erst mit dem unbekannten anfangen wollte. Meine erste Ungewissheit ist: wo ist der Gamecontroller eingehängt? ich habe gelesen, dass alle USB Geräte unter Linux als Serielle Schnittstellen unter dev/ttySX (wobei X hier eine Nummer darstellt) eingebunden werden und das man über die entsprechende Datei mit den den Geräten Kommunizieren kann. Aber welches von den vielen ttySX Daten gehört zu meinen Controller? Ich habe mir dieses Programm genommen(http://stackoverflow.com/questions/10242648/programming-linux-serial-port-ttys0) und es ausprobiert aber ich bekomm die Datei nicht auf. müssen dort andere rechte vergeben werden?
hier nochmal der benutzte code:
#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <unistd.h> int main() { printf("hello world\n"); // int n; int fd; char c; int bytes; char buffer[10]; char *bufptr; // int nbytes; // int tries; int x; struct termios options; fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY); if(fd == -1) { perror("open_port: Unable to open:"); } else { fcntl(fd, F_SETFL, 0); printf("hi again\n"); } tcgetattr(fd, &options); cfsetispeed(&options, B115200); cfsetospeed(&options, B115200); options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; // options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag &= ~( ICANON | ECHO | ECHOE |ISIG ); options.c_iflag &= ~(IXON | IXOFF | IXANY ); options.c_oflag &= ~OPOST; tcsetattr(fd, TCSANOW, &options); write(fd, "ATZ\r",4); printf(" wrote\n"); bufptr = buffer; fcntl(fd, F_SETFL, FNDELAY); bytes = read(fd, bufptr, sizeof(buffer)); printf("number of bytes read is %d\n", bytes); perror ("read error:"); for (x = 0; x < 10 ; x++) { c = buffer[x]; printf("%d ",c); } close(fd); //puts(buffer[0]); printf("\nshould of put something out \n"); return (0); }
ich stelle mich anscheinend generell ungeschickt an, zu diesem Thema brauchbare Informationen zu suchen. Kann mir jemand ein paar Seiten empfehlen, die es nützlich wäre durchzulesen, bevor ich anfange zu Programmieren?