嵌入式linux串口通信自發自收測試程序
睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接
/*串口自收自發程序主函數*/
#include"uart_api.h"
int main()
{
int fd;
char buff[BUFFER_SIZE];
char buff2[]="Hello NUAA2440!\n";
int nread,nwrite;
if((fd=open_port(TARGET_COM_PORT))<0)
{
perror("open serial error");
return 1;
}
printf("open ok!\n");
if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
{
perror("set_com_config error");
return 1;
}
printf(" set ok!\n");
/*將緩沖區buff2中的數據寫入到串口1中去*/
nwrite=write(fd,buff2,sizeof(buff2));
printf("nwrite=%d\n",nwrite); /*打印寫入的數據*/
/*接下來就是讀數據*/
while(1)
{
if((nread = read(fd,buff,1024))>0)
{
buff[nread] = '\0';
printf("\nrecv:%d\n",nread);
printf("%s",buff);
}
}
close(fd);
return 0;
} RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
#include"uart_api.h"
int main()
{
int fd;
char buff[BUFFER_SIZE];
char buff2[]="Hello NUAA2440!\n";
int nread,nwrite;
if((fd=open_port(TARGET_COM_PORT))<0)
{
perror("open serial error");
return 1;
}
printf("open ok!\n");
if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
{
perror("set_com_config error");
return 1;
}
printf(" set ok!\n");
/*將緩沖區buff2中的數據寫入到串口1中去*/
nwrite=write(fd,buff2,sizeof(buff2));
printf("nwrite=%d\n",nwrite); /*打印寫入的數據*/
/*接下來就是讀數據*/
while(1)
{
if((nread = read(fd,buff,1024))>0)
{
buff[nread] = '\0';
printf("\nrecv:%d\n",nread);
printf("%s",buff);
}
}
close(fd);
return 0;
} RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成