Я прочитал буфер с последовательного устройства. Он возвращает мне эти результаты (по 2 строки каждый раз)удалить символы из EOL
Hello World.
My name is John.
Hello World.^M^JMy name
is Mike.
Hello World.^M^JMy name
is ^M^JERROR Peter.
Эти результаты приведены в командной строке Linux.^M^J - EOL и означает \ r \ n в Windows. Первый результат в порядке, но два других ужасных. Есть ли способ проверить символы^M^J и удалить их? Потому что я хочу, чтобы эти результаты:
Hello World.
My name is John.
Hello World.
My name is Mike.
Hello World.
My name is Peter.
С помощью этого кода я прочитал буфер
char buff[150];
memset(buff, 0, sizeof(buff));
for (;;)
{
n=read(fd,buff,sizeof(buff));
printf("%s", buff);
}
UPDATE
открыть и настроить свое устройство таким образом
int open_port(void)
{
int fd; // file description for the serial port
fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1) // if open is unsucessful
{
//perror("open_port: Unable to open /dev/ttyAMA0 - ");
printf("open_port: Unable to open /dev/ttyAMA0. \n");
}
else
{
fcntl(fd, F_SETFL, 0);
printf("port is open.\n");
}
return(fd);
} //open_port
И настройте порт
int configure_port(int fd) // configure the port
{
struct termios port_settings; // structure to store the port settings in
cfsetispeed(&port_settings, B9600); // set baud rates
cfsetospeed(&port_settings, B9600);
port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;
tcsetattr(fd, TCSANOW, &port_settings); // apply the settings to the port
return(fd);
} //configure_port
Я думаю, что вы должны проверить полукокс по полукоксу для значения ASCii http://en.wikipedia.org/wiki/ASCII#ASCII_control_code_chart – tikend
Что происходит в окнах после вас 'read()' EOF? читает стоп? –
Я не знаю, что происходит в Windows. Я использую Linux, и у меня есть эти символы – dali1985