ttytest-main.c
int main(int argc, char **argv) //主函数入口
{
……
fd = OpenDev(dev); /*打开串口 */
if (fd>0)
set_speed(fd,115200); //设置波特率
else {
printf("Can't Open Serial Port!\n");
exit(0); }
if (set_Parity(fd,8,1,'N')== FALSE){ //设置传递参数
printf("Set Parity Error\n");
exit(1); }
printf("\nWelcome to TTYtest\n\n");
memset(buffer,0,sizeof(buffer));
char test[100]="forlinx am335x uart test......";
write(fd, test, strlen(test));
printf("Send test data------%s\n",test);
……
while(1) { //应用层测试
nread = read(fd,&buffer[n],1);
printf("read char is %c\n",buffer[n]);
if (strlen(buffer)==strlen(test)) {
printf("Read Test Data finished,Read Test Data is----%s\n",buffer);
memset(buffer,0,sizeof(buffer));
printf("Send test data again------%s\n",test);
write(fd, test, strlen(test));
n=0;
sleep(1);
continue;}
n++; }
}
ttytst-编译运行
[root@Cyb-Bot ttytest]# ./ttytest /dev/tty
Welcome to TTYtest
forlinx am335x uart test......Send test data------forlinx am335x uart test......
hello jiang^M^Jread char is h
read char is e
read char is l
read char is j
read char is I