uart.c
来自「这是在Vxworks下调试通过的串口程序」· C语言 代码 · 共 44 行
C
44 行
#include <ioLib.h>
#include <stdio.h>
#include <taskLib.h>
#include <semLib.h>
char szBuf[8]={0};
int recid;
int tyRecv( int fd ) /*read has the function of waiting for data*/
{
FOREVER
{
if(read(fd,szBuf,1)!=NULL)
write(fd,szBuf,1);
}
}
int uart()
{
/* Open COM1*/
int fd = open("/tyCo/0",O_RDWR,0);
if (ERROR==fd)
{
printf("can not open device!\n");
return 0;
}
/*Set baudrate*/
if ( ERROR==ioctl(fd,FIOBAUDRATE,9600) )
{
printf("can not set BAUDRATE!\n");
return 0;
}
/*Start receiving task*/
recid=taskSpawn("trecv",60,VX_FP_TASK,
1024*40,(FUNCPTR)tyRecv,fd,
0,0,0,0,0,0,0,0,0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?