下面的所有代码均可用。我的设备响应,C,7是重置。当我第二次运行它时,它不响应。如果我手动关闭设备,然后再次运行该脚本,它将起作用。但是,如果我按下按钮第二次运行脚本,则不会。C++串行端口仅在使用写入时才响应
RS232:57600,8,N,1
任何想法?有没有更多的信息需要解决这个问题?
*另外,当我得到这个工作,我将不得不使用read()函数来获取设备响应。有谁知道我需要使用正确的格式,基于下面的代码?对不起,我是C++的新手......我更像一个PHP家伙。
*我也不知道,如果1024是对的,但它似乎使工作呃...
#include <termios.h>
int fd;
struct termios options;
fd=open("/dev/tty.KeySerial1", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);
tcgetattr(fd,&options);
options.c_ispeed=57600;
options.c_ospeed=57600;
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_cflag &= ~CSTOPB;
options.c_lflag &= ~ECHO;
options.c_oflag &= ~ECHO;
options.c_oflag &= ~OPOST;
options.c_cflag |= CS8;
options.c_cflag |= CRTSCTS;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] =10;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&options);
write(fd, "C,7\r\n", 1024);
close(fd);
辉煌!这工作!这一小小的改变会让我整天(或更多)弄清楚。 非常感谢您! 有关我的read()函数格式的任何想法? :) – Pfeffer 2009-10-22 18:56:07