1

Mac で IrDA を使用して Uwatec ダイブ コンピューターと通信するツールを作成しようとしています。私が使用している USB IrDA デバイスは、データの送受信に使用できるシリアル デバイス (/dev/cu.IrDA-IrCOMM0および) を提供します。/dev/tty.IrDA-IrCOMM0残念ながら、Mac は IrDA ソケット層を提供していません。

デバイス ドライバーに同梱されているコマンド ライン ツールを使用して、他のデバイスからの IrDA 通信をリッスンおよび受信できることを確認しました。ただし、コマンド ライン ツールでは 9600 ボーで通信していると表示されますが、残りの設定 (ビット、ストップ ビット、パリティ、フロー制御など) は表示されません。

データをリッスンする独自のプログラムを作成しようとしましたが、データを受信できません。その理由は、これらの設定が正しくないためだと思います。では、送信されている 9600 ボーの IrDA 検出パケットをリッスンしようとしているだけだとすると、他にどのような設定を使用する必要があるのでしょうか?

それが役立つ場合は、通信パラメーターを設定するために現在使用しているコードのスニペットを次に示します。これは機能しません。

#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;
}
4

1 に答える 1

0

以下は、Linux で EXAR XR17C15 に使用した IrDA 初期化コードです。さらに、この例では設定されていないため、ボーレートを設定する必要があります。これが役立つことを願っています。

//
// 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;
}
于 2012-10-01T12:55:18.927 に答える