我正在尝试写一个工具,使用IrDA与Uwatec dive computers...on a Mac进行通信。我正在使用的USB设备提供了一个可用于发送和接收数据的串行设备(/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;
}发布于 2012-10-01 20:55:19
下面是我在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;
}https://stackoverflow.com/questions/11345135
复制相似问题