首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IrDA发现的默认设置(波特、位、停止、奇偶校验、流控制等)

IrDA发现的默认设置(波特、位、停止、奇偶校验、流控制等)
EN

Stack Overflow用户
提问于 2012-07-05 21:16:12
回答 1查看 462关注 0票数 1

我正在尝试写一个工具,使用IrDA与Uwatec dive computers...on a Mac进行通信。我正在使用的USB设备提供了一个可用于发送和接收数据的串行设备(/dev/cu.IrDA-IrCOMM0/dev/tty.IrDA-IrCOMM0)。不幸的是,Mac没有提供IrDA套接字层。

我已经使用设备驱动程序附带的命令行工具确认它可以侦听和接收来自其他设备的IrDA通信。然而,虽然命令行工具告诉我它正在以9600波特率通信,但其余的设置(位、停止位、奇偶校验、流量控制等)并没有返回给我。

我尝试编写自己的程序来监听数据,但它无法接收任何数据,我相信原因是因为这些设置不正确。因此,假设我正在尝试侦听正在发送的9600波特的IrDA发现数据包,我还需要使用哪些其他设置?

如果有帮助,下面是我当前用来设置通信参数的代码片段--它不起作用:

代码语言:javascript
复制
#define DEVICE "/dev/cu.IrDA-IrCOMM0"

int main(void) {
    FILE *device;
    struct termios ttystate;

    device = fopen(DEVICE, "rw");

    //get the terminal state
    tcgetattr(fileno(device), &ttystate);
    //turn off canonical mode and echo
    ttystate.c_lflag &= ~(ICANON | ECHO);
    //minimum of number input read.
    ttystate.c_cc[VMIN] = 1;

    cfsetspeed(&ttystate, B9600); // Set 9600 baud····
    ttystate.c_cflag |= (CS8 | // Use 8 bit words
                         PARENB   | // parity enable
                         PARODD   | // odd parity
                         CCTS_OFLOW | // CTS flow control of output
                         CRTS_IFLOW);// RTS flow control of input

    //set the terminal attributes.
    tcsetattr(fileno(device), TCSANOW, &ttystate);
    return EXIT_SUCCESS;
}
EN

回答 1

Stack Overflow用户

发布于 2012-10-01 20:55:19

下面是我在Linux上用于EXAR XR17C15的IrDA初始化代码。此外,在本例中,您必须将波特率设置为未设置。我希望这能帮到你。

代码语言:javascript
复制
//
// Set up IrDA hardware interface through UART

bool CeIrDA::SetupIrDA()
{
    struct termios termios;
    tcgetattr(hComPort, &termios);
    cfmakeraw(&termios);

    termios.c_iflag = IGNPAR;
    termios.c_oflag = 0;
    termios.c_cc[VTIME] = 1;    // timeout in 0.1s between 2 characters
    termios.c_cc[VMIN] = 1;     // min # of characters

    tcsetattr(hComPort, TCSANOW, &termios);

    xrioctl_rw_reg input;
    struct timespec delay = {0, 500};
    struct timespec delayrem;
    //EFR: Allowing Enhanced Functions and RTS/DTR flow control
    input.reg=0x09;
    input.regvalue=0x50;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //MCR: Flow control RTS enabled
    input.reg=0x04;
    input.regvalue=0x40;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //MCR: RTS pin high
    input.reg=0x04;
    input.regvalue=0x00;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //MCR: RTS pin low
    input.reg=0x04;
    input.regvalue=0x02;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //MCR: Infrared Mode
    input.reg=0x04;
    input.regvalue=0x42;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //EFR: Allowing Enhanced Functions and RTS/DTR flow control
    input.reg=0x09;
    input.regvalue=0x40;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //LCR: Allowing changes of DLL and DLM
    input.reg=0x03;
    input.regvalue=0x80;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //DLL: Speed configuration
    input.reg=0x00;
    input.regvalue=0x02;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //DLM: Speed configuration
    input.reg=0x01;
    input.regvalue=0x00;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);

    //LCR: configuration for parity, word length....
    input.reg=0x03;
    input.regvalue=0x03;
    ioctl(hComPort,WRITE,&input);

    nanosleep(&delay, &delayrem);
    return true;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11345135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档