Hi Leute!
Ich habe zum öffnen des seriellen Ports folgendes Programm verwendet:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int open_serial(void)
{
/*
* Oeffnet seriellen Port
* Gibt das Filehandle zurueck oder -1 bei Fehler
*
* RS232-Parameter:
* 4800 bps, 8 Datenbits, 1 Stoppbit, no parity, no handshake
*/
int fd; /* Filedeskriptor */
struct termios options; /* Schnittstellenoptionen */
/* Port oeffnen - read/write, kein "controlling tty", Status von DCD ignorieren */
fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd >= 0)
{
/* get the current options */
fcntl(fd, F_SETFL, 0);
if (tcgetattr(fd, &options) != 0) return(-1);
memset(&options, 0, sizeof(options)); /* Structur loeschen, ggf. vorher sichern
und bei Programmende wieder restaurieren */
/* Baudrate setzen */
cfsetispeed(&options, B4800);
cfsetospeed(&options, B4800);
/* setze Optionen */
options.c_cflag &= ~PARENB; /* kein Paritybit */
options.c_cflag &= ~CSTOPB; /* 1 Stoppbit */
options.c_cflag &= ~CSIZE; /* 8 Datenbits */
options.c_cflag |= CS8;
/* 4800 bps, 8 Datenbits, CD-Signal ignorieren, Lesen erlauben */
options.c_cflag |= (CLOCAL | CREAD);
/* Kein Echo, keine Steuerzeichen, keine Interrupts */
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag = IGNPAR; /* Parity-Fehler ignorieren */
options.c_oflag &= ~OPOST; /* setze "raw" Input */
options.c_cc[VMIN] = 0; /* warten auf min. 0 Zeichen */
options.c_cc[VTIME] = 10; /* Timeout 1 Sekunde */
tcflush(fd,TCIOFLUSH); /* Puffer leeren */
if (tcsetattr(fd, TCSAFLUSH, &options) != 0) return(-1);
}
return(fd);
}
Alles anzeigen
Dabei kommt folgende Fehlermeldung beim kompilieren:
ZitatAlles anzeigen
pi@raspberrypi ~ $ gcc /home/pi/Desktop/serial1.c /home/pi/Desktop/serial1.c
/tmp/ccWkyl3j.o: In function `open_serial':
serial1.c:(.text+0x0): multiple definition of `open_serial'
/tmp/ccfVgd3J.o:serial1.c:(.text+0x0): first defined here
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: ld returned 1 exit status
Mit der Fehlermeldung kann ich nichts anfangen..
Hat jmd. eine Lösung/ Idee für das Problem?
Oder eine andere variante zur Konfiguration der Schnittstelle..
Danke im vorraus!
Sorry wegen der Smileys.. Hier nochmal die Fehlermeldung:
ZitatAlles anzeigen
pi@raspberrypi ~ $ gcc /home/pi/Desktop/serial1.c /home/pi/Desktop/serial1.c
/tmp/ccWkyl3j.o: In function `open_serial':
serial1.c:(.text+0x0): multiple definition of `open_serial'
/tmp/ccfVgd3J.o:serial1.c:(.text+0x0): first defined here
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: ld returned 1 exit status
okay die smileys sind einfach nur "Doppelpunkt" && "Klammer auf"
Okay Grundsätzlicher Fehler war, dass es kein ausführbares Programm. >> Die main Funktion hat schlicht und einfach gefehlt.
Habe diese jetzt hinzugefügt und kann das Programm ausführen...
Jetzt kommt aber die Meldung:
Zitat
-------------------------
(program exited with code. 0)
Press return to continue