📄 test.c
字号:
#include <vxWorks.h>
#include <ioLib.h>
volatile int STOPRe=FALSE;
volatile int STOPSn =FALSE;
int s_receive()
{
int fd, c, res, buf_len;
/** struct termios oldtio,newtio;*/
char buf[255];
/* speed_t temp_speed;*/
/*
Open modem device for reading and writing and not as controlling tty
because we don't want to get killed if linenoise sends CTRL-C.
*/
STOPRe = FALSE ;
fd = open("/tyCo/4", O_RDONLY ,0 );
printf("receive fd : %x \n", fd );
if (fd == ERROR)
{
printf("open tyco4 is error\n");
return ERROR;
}else
{
printf("open tyco4 is ok\n");
}
/*
terminal settings done, now handle input
In this example, inputting a 'z' at the beginning of a line will
exit the program.
*/
while (STOPRe==FALSE) { /* loop until we have a terminating condition */
int i;
/* read blocks program execution until a line terminating character is
input, even if more than 255 chars are input. If the number
of characters read is smaller than the number of chars available,
subsequent reads will return the remaining chars. res will be set
to the actual number of characters actually read */
printf("receive is entry!!");
res = read(fd,buf,255);
printf("receive is ok");
buf[res] = 0;
printf(" receive buf=[%s] len:%d\n", buf, res );
putchar('\n');
if (buf[0]=='z') STOPRe=TRUE;
}
close( fd );
}
int s_send()
{
int fd, c, res, buf_len;
/* struct termios oldtio, newtio;*/
char buf[255];
/*
Open modem device for reading and writing and not as controlling tty
because we don't want to get killed if linenoise sends CTRL-C.
*/
printf("send entry!\n");
fd = open("/tyCo/6", O_WRONLY,0 );
STOPSn = FALSE;
fd = open("/tyCo/6", O_WRONLY,0 );
if (fd == ERROR)
{
printf("tyco6open is error \n");
return ERROR;
}
printf("send open ty6\tfd=%d\tSTOPSn=%d\n",fd,STOPSn);
/*
now handle input
In this example, inputting a 'z' at the beginning of a line will
exit the program.
*/
while (STOPSn==FALSE) {
printf("ok\n");
/* loop until we have a terminating condition */
gets(buf);
printf("buf::%s\n",buf);
buf_len = strlen( buf );
printf(" key-in string lenght:%d\n", buf_len );
if( buf[buf_len-1] != 0x0a ){
buf[buf_len] = 0x0a;
buf[buf_len+1]= 0x00;
buf_len++;
}else
buf[buf_len]= 0x00;
printf(" output string :%s", buf );
res = write( fd, buf, buf_len );
printf(" ok return from write :%d\n", res );
if (buf[0]=='z') STOPSn=TRUE;
}
#if 0
write(fd,"12345",5);
taskDelay(1);
#endif
close( fd );
}
void testtask()
{
printf("task is ok!\n");
}
void Test(void)
{
CreateP3544();
FOREVER
{
s_send();
taskDelay(30);
s_receive();
taskDelay(120);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -