serielle-Schnittstelle

Post Reply
Message
Author
Otti

serielle-Schnittstelle

#1 Post by Otti »

Moin Moin

Habe ein (hoffentlich) kleines Problem.
Und zwar will ich über die serielle-Schnittstelle ein Zeichen versenden.
Empfangen geht schon wunderbar nur mit dem senden komme ich nicht weiter.
Hier mein Quelltextauszug . . .

=======================================================================


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <math.h>
#include <string.h>


#define BAUDRATE B9600 //Baudrate (9600 Bps)
#define _POSIX_SOURCE 1

int main (int argc, char *argv[]){

int fd;
struct termios newtio;
char buffer[255];
char pingpong<font size="1">;
int buffersize;

fd=open(device, O_RDWR|O_NOCTTY); //com1 oeffnen


if (fd < 0)
{
perror(device);
return 2;
}

bzero(& newtio, sizeof(newtio));
newtio.c_cflag=BAUDRATE|CS8|CLOCAL|CREAD;


newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag |= OPOST; //output-flag | hier liegt evtl. der fehler ???
newtio.c_lflag = ICANON;
newtio.c_cc[VINTR] = 0;
newtio.c_cc[VQUIT] = 0;
newtio.c_cc[VERASE] = 0;
newtio.c_cc[VKILL] = 0;
newtio.c_cc[VEOF] = 4;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VSWTC] = 0;
newtio.c_cc[VSTART] = 0;
newtio.c_cc[VSTOP] = 0;
newtio.c_cc[VSUSP] = 0;
newtio.c_cc[VEOL] = 0;
newtio.c_cc[VREPRINT] = 0;
newtio.c_cc[VDISCARD] = 0;
newtio.c_cc[VWERASE] = 0;
newtio.c_cc[VLNEXT] = 0;
newtio.c_cc[VEOL2] = 0;

tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);



//SENDEN------(funzt nicht)---------------------------------------------------------

pingpong<font size="1"> = 50; //Der char pingpong<font size="1"> soll gesendet werden (50)
buffersize = write(fd, pingpong, 1);


//Empfangen (funzt) ------------------------------------------------------

while (true) //forever is a long time... *g*
{

buffersize = read(fd,buffer,255);
buffer[buffersize]=0;
printf("%s",buffer);

}

}

==================================================================

evtl. hat ja jemand von euch einen Tipp für mich.

MFG
Otti

otti

Re: serielle-Schnittstelle

#2 Post by otti »

OK
hat sich schon erledigt.
Der fehler war auf der anderen seite des Kabels *g*
MFG
Otti

Post Reply