[ECOS] Read an string from serial port
Michael Anburaj
embeddedeng@hotmail.com
Tue Dec 30 18:30:00 GMT 2003
This may be due to difference in BAUD rate.
I don't know how you set the BAUD rate when using Âecho command (May be it
defaults to a known value, which may be different from what eCOS uses
(38400)).
Use 'minicom' on linux, where you can specify the serial port parameters
(like BAUD) & match things on both ends.
Cheers,
-Mike.
>From: Francesc Teixido Navarro <ca06332@salleURL.edu>
>To: ecos-discuss@sources.redhat.com
>Subject: [ECOS] Read an string from serial port
>Date: Tue, 30 Dec 2003 09:31:11 +0100 (CET)
>
>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
>
_________________________________________________________________
Tired of slow downloads? Compare online deals from your local high-speed
providers now. https://broadband.msn.com
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss
More information about the Ecos-discuss
mailing list