扩展UNIX Ioctl命令
如下moxa扩展函数语法适用于svr4.x和非svr4.x unix操作系统,变量moxa fd是调用open()函数打开指定moxa串口的函数调用返回值。例如:

    int moxa_fd:

    moxa_fd=open(″/dev/ttyall″,0_rdwr);

    1.mibufed

    这个功能使用户可以读取接收缓冲区队列里有多少字节等待接收。

    sco unikix/enik的语法

    #define mibufed ox401

    int count;/*number ofbytes queued in the sbuffer*/

    ioctl(moxa_fd,mibufed,&count);

    unix svr4的语法

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    #define mmufed ox401

    struct strioctl ioc;

    int count;/*number ofbytes queued in the sbuffer*/

    ioc.ic_cmd=mibufed;

    ioc.ic_timout=0;

    ioc.ic_len=sizeof(int);

    ioc.ic_dp(char*)&count;

    ioctl(moxa_fd,i_str,&ioc);

    由streams驱动程序的特点决定,返回的字节数只反映当前在moxa多串口卡接收缓冲区中的待接收的字节数,不包括streams队列里的缓冲数据。在这个例子中,读取的字节数仅供用户参考。例如:返回字节数总是0,但是可能在streams队列里仍有数据。

    2.mobufed

    这个功能使用户可以读取发送缓冲区队列里有多少字节等待发送。

    scounix/xenik的语法

    #define mobuped 0x402

    int count;/*number of bytes queued in theoutput buffer*/ioctl(moxa_fd,mobufed,&count);

    unix svr4的语法

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    #define mobuped 0x402

    struct sbioctl ioc;

    int count;/*number of bytes queued in the output buffer*/

    ioc.ic_cmd=mobuped;

    ioc.ic_timout=0;

    ioc.ic_1en=sizeo耶nt);

    ioc.ic_dp=(char*)&count;

    ioctl(moxlf山lstr,aioc);

    参见mibufed获得有关streams驱动程序影响的信息。

    只有当硬件流控功能关闭时才有效(请参考mitwflow)。本功能用来设置或清除rts信号。

    sco unix/xenix i的语法

    #define mtcrts 0x403

    #define tumon 1

    #define turnoff 0

    ioctl(moxa_fd, mtcrts, turnon);

    ioctl(moxa_fd, mtcrts, turnoff);

    unix svr4 i的语法

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    #define mtcrts 0x403

    #define tumon 1

    #define turnoff 0

    stmct strioctl ioc;

    int setting;

    setting = tumon/* or turnoff */;

    ioc.ic_cmd = mtcrts;

    ioc.ic_timout = 0;

    ioc.ic_len = sizeoffint);

    ioc.ic_dp = (char *)&setting;

    ioctl(moxa_fd, i_str, &ioc);

    4.mtcdtr

    本函数当硬件流控功能关闭时(参见mhwflow)才有效,用于设置dtr信号或清除dtr信号。

    sco unix/xenix的语法

    #define mtcdtr 0x404

    #define tumon 1

    #define turnoff 0

    ioctl(moxa_fd, mtcdtr, tumon);

    ioctl(moxa_fd, mtcdtr, turnoff);

    unix svr4 的语法

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    #define mtcdtr 0x404

    #define tumon 1

    #define turnoff 0

    stmct strioctl ioc;

    iht setting;

    setting = tumon/* or turnoff */;

    ioc.ic_cmd = mtcdtr;

    ioc.ic_timout = 0;

    ioc.ic_len = sizeoffint);

    ioc.ic_dp = (char *)&setting;

    ioctl(moxa_fd, i_str, &ioc);

    5.mlowater

    一些应用程序软件在发送缓冲区满时不能将数据写入发送缓冲区,应用程序将不得不等待,直到发送缓冲区有足够空间为止。一个必须提供的重要功能是告诉应用程序发送缓冲区何时有足够的空间供用户写入数据。发送缓冲区字节数低限就是这样一个值,当发送缓冲区的数据减少到该数值时,发送缓冲区可以接收应用程序写来的发送数据。

    如果发送缓冲区字节数低限值设置的相对较小,用户将要在对发送缓冲区写入下一笔发送数据之前就已经全空了(在unix多任务共享cpu的情况下,这是常常会出现的情况)。这将会产生发送数据不连续的问题,对于一些有严格时间限制的应用(比如:传真),不连续的数据传输将会经常产生操作失败。

    缺省的发送缓冲区字节数低限为512字节。用户可以扩大这个值,但是最好不要超过发送缓冲区的一半,每个串口的发送缓冲区为32k字节。

    sco unix/openserver的语法

    #define mlowater 0x405

    int lowater;/* low water value of output buffer(default = 512 bytes) */

    ioctl(moxa_fd, mlowater, lowater);

    unix svr4.2的语法

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    #define mlowater 0x405

    struct strioctl ioc;

    int lowater;/* low water value of output buffer (default = 512 bytes) */

    ioc.ic_cmd = mlowater;

    ioc.ic_timout = 0;

    ioc.ic_len = sizeof(int);

    ioc.ic_dp = (char *)&lowater;

    ioctl(moxa_fd, i_str, &ioc);

    6. mstatus

    这个功能用来检测rs-232的信号(cts/dsr/dcd)状态。

    sco unix/xenix 的语法

    #define mstatus0x407

    iht status; /* status = rs-232 line status */

    /* bit0--cts (1 :on, 0:off) */

    /* bitl --dsr (l:on, 0:of0 */

    /* bit2--dcd (l:on, 0:of0 */

    ioctl(moxa_fd, m status, &status);

    unix svr4 的语法

    #define mstatus 0x407

    #include [sys/stropts.h]

    #include [sys/sysmacros.h]

    struct strioctl ioc;

    int status;/* status = rs-232 line status */

    /* bit0--cts (l:on, 0:off) */

    /* bitl --dsr (1 :on, 0:off) */

    /* bit2--dcd (l:on, 0:off) */

    ioc.ic_cmd = mstatus;

    ioc.ic_timout = 0;

    ioc.ic_len = sizeof(int);

    ioc.ic_dp = (char *)&status;

    ioctl(moxa_fd,i_str, &ioc);

    7. mhwflow

    这个功能用来设置使用/禁止硬件流控功能。第一次使用open()函数打开串口时的流控方式设置由mxadm中的[rts/ctshardwareflowcontr01]设置决定。然而用户可以按照自己的要求来设置或清除dtr和rts信号,如果需要通过

    mtcrts和mtcdtr来控制dtr和rts信号时,必须首先将rts流控位清除(hwflowcontroloff)。只有当rts流控位mhwflow被清除时,mtcrts和mtcdtr信号才能有效。

    scounix/xenik的语法

    #defismhwflow ox40e

    #defishwflowconlr010if ox00

    #defisctsflowcontromiton ox01

    #defisrtsflowcontromiton ox02

    #defishwflowconlrolon ox03

    ioctl(moxa_mhwflow,ctsflowcontromiton);

    ioctl(moxa_fd,mhwflow,rtsflowcontromiton);

    ioctl(moxla_fd,mhwflow,ctsflowcontr01bitonirtsflowcontromiton);

    uniksvr4的语法

    #include [sys/s订opts.h]

    #include [sys/sysmacros.h]

    #definemhwflow 0x40e

    #definehwflowcontr0l0ff ox00

    #definectsflowcontr0lbiton 0x01

    #definertsflowcontr0lbiton 0x02

    #definehwflowcontr010n 0x03

    struct strioctl ioc;

    int sening;

    sening=ctsflowcontr01biton:

    ioc.ic cmd=mhwflow:

    ioc.ic timout=0;

    ioc.ic 1en=sizeof(int):

    ioc.ic dp=(char*)&sening;

    ioctl(moxa_fd,i_str,&ioc);

   

   
MOXA C168HS 相关内容:报价 | 参数 | 图片 | 论坛 | 评测