ho un problema alla lettura della seriale, uso questo codice:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
int fd, retval, n;
char lett;
//char apriporta[5]={0x00,0x3E,0x64,0xE7,0x89};
//char rispondi_chiudi[5]={0x00,0xCC,0x64,0xE7,0x17};
//char occhio[5]={0x00,0x4F,0x64,0xE7,0x9A};
////////////////////////////////////////////////////////////////////////////////////////////
// Configurazione seriale
fd = open("/dev/ttyAMA0", O_RDWR);
if (fd < 0)
{
printf ("Non posso aprire la porta seriale: /dev/ttyAMA0\n");
}
struct termios options;
tcgetattr(fd, &options);
options.c_cflag |= CREAD; //abilito ricezione
options.c_cflag |= CSIZE + CS8; //8 caratteri
cfsetispeed(&options, B1200); //boudrate 1200
//options.c_lflag &= ~(ICANON | ECHO | ISIG); // disabilito terminatore
tcsetattr(fd, TCSANOW, &options);
tcflush(fd, TCIOFLUSH);
char buf[256];
while(1)
{
n = read(fd, (void*)buf, 255);
if (n < 0) {
printf("\nRead failed");
return -1;
} else if (n == 0) printf("\nNo data on port");
else {
buf[n] = '\0';
printf("\n%i bytes read : %s", n, buf);
}
}
close(fd);
printf ("\n") ;
return 0 ;
}//fine maininvio ricevuto
A niente
A niente
A niente
A niente
A niente
....
A A
B A
C B
D C
ecc.
qualcuno sa come posso risolvere?