当前位置: 技术问答>linux和unix
各位仁兄有没有ttytest.c的源程序阿
来源: 互联网 发布时间:2016-01-07
本文导语: 各位仁兄有没有ttytest.c的源程序阿? 能不能发我一份 谢谢了 tiplinky2002@yahoo.com.cn | /**************ttytest.c*******************/ #include #include #include #include "rs232.h" main(int argc, char *argv[]) { int ret,...
各位仁兄有没有ttytest.c的源程序阿?
能不能发我一份
谢谢了
tiplinky2002@yahoo.com.cn
能不能发我一份
谢谢了
tiplinky2002@yahoo.com.cn
|
/**************ttytest.c*******************/
#include
#include
#include
#include "rs232.h"
main(int argc, char *argv[])
{
int ret,portno,nWritten,nRead;
char buf[256];
portno=0;
while(1)
{
ret=OpenCom(portno,"/dev/ttyS1",115200);
if(ret==-1)
{
perror("The /dev/ttyS1 open error.");
exit(1);
}
nWritten=ComWrt(portno,"abc",3);
printf("n/dev/ttyS1 has send %d chars!n",nWritten);
printf("nRecieving data!***n");
fflush(stdout);
nRead=ComRd(0,buf,256,3000);
if(nRead>0)
{
printf("*****OKn");
}
else
printf("Timeoutn");
if((ret=CloseCom(portno)==-1))
{
perror("Close com");
exit(1);
}
printf("nn");
}
printf("Exit now.n");
return;
}
/******************************rs232********************************/
int ComRd(int portNo, char buf[], int maxCnt,int Timeout)
{
int actualRead = 0;
fd_set rfds;
struct timeval tv;
int retval;
if (!ports[portNo].busy)
{
assert(0);
}
/* camp on the port until data appears or 5 seconds have passed */
FD_ZERO(&rfds);
FD_SET(ports[portNo].handle, &rfds);
tv.tv_sec = Timeout/1000;
tv.tv_usec = (Timeout%1000)*1000;
retval = select(16, &rfds, NULL, NULL, &tv);
if (retval)
{
actualRead = read(ports[portNo].handle, buf, maxCnt);
}
#include
#include
#include
#include "rs232.h"
main(int argc, char *argv[])
{
int ret,portno,nWritten,nRead;
char buf[256];
portno=0;
while(1)
{
ret=OpenCom(portno,"/dev/ttyS1",115200);
if(ret==-1)
{
perror("The /dev/ttyS1 open error.");
exit(1);
}
nWritten=ComWrt(portno,"abc",3);
printf("n/dev/ttyS1 has send %d chars!n",nWritten);
printf("nRecieving data!***n");
fflush(stdout);
nRead=ComRd(0,buf,256,3000);
if(nRead>0)
{
printf("*****OKn");
}
else
printf("Timeoutn");
if((ret=CloseCom(portno)==-1))
{
perror("Close com");
exit(1);
}
printf("nn");
}
printf("Exit now.n");
return;
}
/******************************rs232********************************/
int ComRd(int portNo, char buf[], int maxCnt,int Timeout)
{
int actualRead = 0;
fd_set rfds;
struct timeval tv;
int retval;
if (!ports[portNo].busy)
{
assert(0);
}
/* camp on the port until data appears or 5 seconds have passed */
FD_ZERO(&rfds);
FD_SET(ports[portNo].handle, &rfds);
tv.tv_sec = Timeout/1000;
tv.tv_usec = (Timeout%1000)*1000;
retval = select(16, &rfds, NULL, NULL, &tv);
if (retval)
{
actualRead = read(ports[portNo].handle, buf, maxCnt);
}