/*com_writer.c*/
#include "uart_api.h"
int main (void)
{
int FD;
Char Buff[buffer_size];
if ((Fd=open_port (Host_com_port)) <0)/* Open serial port */
{
Perror ("Open serial error");
return 1;
}
if (Set_com_config (fd,115200,8, ' N ', 1) <0)/* Configure serial Port */
{
Perror ("Set_com_config error");
return 1;
}
Do
{
printf ("Input Some words (enter ' quit ' to exit):");
memset (buff,0,buffer_size);
if (fgets (Buff,buffer_size,stdin) ==null)
{
Perror ("fgets");
Break
}
Write (Fd,buff,strlen (buff));
}while (strncmp (Buff, "quit", 4));
Close (FD);
return 0;
}
/*com_reader.c*/
#include "uart_api.h"
#define Com_type gnr_com
int main (void)
{
int FD;
Char Buff[buffer_size];
if ((Fd=open_port (Target_com_port)) <0)
{
Perror ("Open serial error");
return 1;
}
if (Set_com_config (fd,115200,8, ' N ', 1) <0)/* Configure serial Port */
{
Perror ("Set_com_config error");
return 1;
}
Do
{
memset (buff,0,buffer_size);
if (read (fd,buff,buffer_size) >0)
{
printf ("The Receive words are:%s", buff);
}
}while (strncmp (Buff, "quit", 4));
Close (FD);
return 0;
}
/*uart_api.h*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#define HOST_COM_PORT 1
#define BUFFER_SIZE 4096
#define MAX_COM_NUM 5
#define TARGET_COM_PORT 1
extern int open_port (int com_port);
extern int set_com_config (int fd,int baud_rate, int data_bits,char parity,int stop_bits);
Embedded Linux serial Programming (II.)