Redirect VxWorks Serial Input

醉酒当歌 提交于 2019-12-12 05:06:51

问题


I am trying to redirect all serial data to a process in VxWorks. Using the following code

fd = open("/tyCo/0", O_RDWR,0);
ioctl(fd, FIOSETOPTIONS, OPT_TERMINAL & ~OPT_7_BIT);
read(fd, line, 100);

gives the correct input, except the first character entered is not populated, but is printed to the terminal. So if I enter "Hello", "H" is printed out and line="ello". If I don't enter anything and hit the return key, I get a prompt from the VxWorks Shell.

I think that the VxWorks Shell is intercepting the first letter of the data. My guess is that I have to redirect STDIO to the new process only, but all the documentation I've found on that says to use ioGlobalStdSet() which is unavailable in VxWorks 6.4 RTP. How can I either redirect STDIO or kill the VxWorks Shell from my process?


回答1:


If you want to redirect all task's outputs to the current login shell, what I think answer is:

static int shellResourceReleaseHookAdd_once = 0;

void revert_out()
{
    ioGlobalStdSet( 1, consoleFd ); /* redirect all output to the consoleFd */
    ioGlobalStdSet( 2, consoleFd ); /* redirect all error to the consoleFd */
}

void redirect_out()
{
    ioGlobalStdSet( 1, ioTaskStdGet(0,1) ); /* redirect all output to the current shell */
    ioGlobalStdSet( 2, ioTaskStdGet(0,1) ); /* redirect all error to the current shell */

    if (shellResourceReleaseHookAdd_once == 0) {
        shellResourceReleaseHookAdd(revert_out); /* call revert_out() when current shell closes. */
        shellResourceReleaseHookAdd_once = 1;
    }
}



回答2:


One work-around is to use ioGlobalStdSet to redirect the IO to a pipe. Then, in the RTP, open the pipe in read mode.

Off the top of my head - In the Kernel:

dev = pipeDevCreate("/pipe/input", 10, 100);
kernFd = open("/pipe/input", O_RD, 0)
ioGlobalStdSet(1, kernFd)

In the RTP:

rtpFd = open("/pipe/input", O_RD, 0); read(rtpFd, line, 100);




回答3:


Disabling the shell during VxWorks configuration and compilation removed the problem permanently. It is also possible to enter exit at the shell to temporarily disable it.



来源:https://stackoverflow.com/questions/10305526/redirect-vxworks-serial-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!