• Viernes 17 de Mayo de 2024, 07:29

Autor Tema:  Recepcion Datos Puerto Serie  (Leído 1320 veces)

bratis

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Recepcion Datos Puerto Serie
« en: Lunes 23 de Febrero de 2004, 17:40 »
0
Hola,
estoy intentando leer un caracter por el puerto serie de una placa EB40A que tiene un sistema operativo basado en linux( eCos).El problema que tengo es que solo recibo los numeros 0 y 128.No se si sera un problema de sincronizacion pero en principio estan tanto el transmisor como el receptor a 8N1 4800. Estoy utilizando las funciones POSIX. El codigo es el siguiente:

/**********************************************************************/

Ok thanks again

I have changed the VTIME to "0" and VMIN to "1" to read only one character from the /dev/ser1 but i can only read 128 or 0, something wrong?The option O_NONBLOCKING is on eCos not supported?

The code:
/***************************************************************************
include<termios.h> /*POSIX terminal control definitions*/
#include<stdio.h> /*standard input/output definitions*/
#include<stdlib.h>
#include<unistd.h> /*UNIX standard functions definitions*/
#include<fcntl.h> /*File control definitions*/
#include<errno.h> /*error numbre definitions*/
#include<string.h> /*string functions definitions*/
#include<sys/signal.h> /*available signals definitions*/
#include<sys/types.h>


#define BAUDRATE B4800
#define MODEMDEVICE "/dev/ser1"
#define ENDMINITERM 2 /* ctrl-b to quit miniterm */

#define _POSIX_SOURCE 1 /* POSIX compliant source */

#define FALSE 0
#define TRUE 1

volatile int STOP=FALSE;

int main(void)
{
int fd,nummer;
int c;
struct termios oldtio,newtio;

fd = open(MODEMDEVICE, O_RDWR);
if (fd <0) {perror(MODEMDEVICE); exit(-1); }

tcgetattr(fd,&oldtio); /* save current modem settings */

newtio.c_cflag = BAUDRATE | CLOCAL | CREAD;
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;

newtio.c_iflag = IGNPAR;

newtio.c_lflag = 0;
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
cfsetispeed(&newtio, B4800);

tcsetattr(fd,TCSANOW,&newtio);

while(1)
{
nummer= read(fd,&c,1);
printf("data = %d\n", c);
if(c == 'z')
{
tcsetattr(fd, TCSANOW, &oldtio);
return 0;
}
}

Alguna idea?
Gracias

Ruben3d

  • Miembro HIPER activo
  • ****
  • Mensajes: 710
  • Nacionalidad: es
    • Ver Perfil
    • Web personal
Re: Recepcion Datos Puerto Serie
« Respuesta #1 en: Lunes 23 de Febrero de 2004, 20:06 »
0
Hola.

Prueba a cambiar el tipo de la variable c a unsigned char. Tambien podrías probar a cambiar printf("data = %d\n", c); por printf("data = %u\n", c);.

Creo que el problema está en que c es de tipo int, ocupando 4 bytes y no estando inicializado. Sin embargo, cuando lees el valor sólo lees un byte, por lo que se quedan sin modificar los otros 3, y a saber qué había en ellos. Además, con printf estás escribiendo un entero con signo, cuando deberías escribir uno sin signo.

un saludo.

Ruben3d