This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Read an string from serial port
- From: Francesc Teixido Navarro <ca06332 at salleURL dot edu>
- To: ecos-discuss at sources dot redhat dot com
- Date: Tue, 30 Dec 2003 09:31:11 +0100 (CET)
- Subject: [ECOS] Read an string from serial port
Hi all,
I'm trying to read an incomng string from serial port, it is
connected to a linux machine.
The string is sent via "echo" command (echo <string> > /dev/ttyS1)
but in the board I only read unrecognizable data. Can anyone helps me??
what error I do??
The idea is to read a binary file in the future.
Thanks
The code:
..................................
int i;
int length;
//unsigned char *data;
char data;
cyg_io_handle_t hport;
Cyg_ErrNo err;
cyg_serial_info_t info;
int len;
//int data_size = 0xF;
/*
data = (unsigned char *)malloc(sizeof(char) * data_size);
if (!data){
printf("There's no suficient memory\n");
}
*/
///////////////////////////////////
printf("Trying to open Serial Port ... ");
err = cyg_io_lookup ("/dev/ser3", &hport);
if (err != ENOERR){
printf("KO\n");
}
printf("OK\n");
printf("Get configuration ...");
len = sizeof(info);
err = cyg_io_get_config(hport, CYG_IO_GET_CONFIG_SERIAL_INFO,
&info, &len);
if (err != ENOERR){
printf("KO\n");
}
printf("OK\n");
printf("Set configuration ...");
info.baud=CYGNUM_SERIAL_BAUD_38400;
info.stop=CYGNUM_SERIAL_STOP_1;
info.word_length=CYGNUM_SERIAL_WORD_LENGTH_8;
err = cyg_io_set_config(hport,CYG_IO_SET_CONFIG_SERIAL_INFO,
&info, &len);
if (err != ENOERR) {
printf("KO\n");
return;
}
printf("OK\n");
printf("Trying to read Serial Port ...\n");
length = sizeof(data);
i = 0x0;
while (1){
printf("Linia: %d :\n", i);
err = cyg_io_read(hport, &data, &length);
printf("%c\n", data);
i++;
}
//free(data);
}
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss