Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在linux中检查串口是否正常工作 我将在我的C++程序Linux Ubuntu 10.4中使用串口,这是我的开放端口函数: int Recorder::OpenPort() { int intFd ; struct termios options; intFd=open("/dev/ttyS0", O_RDWR | O_NOCTTY| O_NDELAY); if (intFd==-1){ perror("open_port: Unable to open /dev/ttyS0 - "); } fcntl(intFd, F_SETFL, FNDELAY); /*configuration the port*/ tcgetattr(intFd, &options); //set baud rates at 115200 cfsetispeed(&options, B115200 ); cfsetospeed(&options, B115200); //mask the character size to 8 bit data & no parity.CHARACTER SIZE SETTING options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; //setting hardware flow control options.c_cflag |= CRTSCTS; //Enable the receiver and set local mode .should always be enabled (enable receiver and dont change owner of port) options.c_cflag |= (CLOCAL | CREAD); //flush output buffer options.c_lflag |= FLUSHO; //choosing raw data disable echoing options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //not setting software flow control options.c_iflag &= ~(IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; // //output changes :for mapping NL to CR-NL. // options.c_oflag |= (OPOST | ONLCR ); // // options.c_oflag |= (NL1 | CR1 | FFDLY); tcsetattr(intFd, TCSANOW, &options); return intFd; }_C++_Linux_Serialization_Ubuntu 10.04 - Fatal编程技术网

如何在linux中检查串口是否正常工作 我将在我的C++程序Linux Ubuntu 10.4中使用串口,这是我的开放端口函数: int Recorder::OpenPort() { int intFd ; struct termios options; intFd=open("/dev/ttyS0", O_RDWR | O_NOCTTY| O_NDELAY); if (intFd==-1){ perror("open_port: Unable to open /dev/ttyS0 - "); } fcntl(intFd, F_SETFL, FNDELAY); /*configuration the port*/ tcgetattr(intFd, &options); //set baud rates at 115200 cfsetispeed(&options, B115200 ); cfsetospeed(&options, B115200); //mask the character size to 8 bit data & no parity.CHARACTER SIZE SETTING options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; //setting hardware flow control options.c_cflag |= CRTSCTS; //Enable the receiver and set local mode .should always be enabled (enable receiver and dont change owner of port) options.c_cflag |= (CLOCAL | CREAD); //flush output buffer options.c_lflag |= FLUSHO; //choosing raw data disable echoing options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //not setting software flow control options.c_iflag &= ~(IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; // //output changes :for mapping NL to CR-NL. // options.c_oflag |= (OPOST | ONLCR ); // // options.c_oflag |= (NL1 | CR1 | FFDLY); tcsetattr(intFd, TCSANOW, &options); return intFd; }

如何在linux中检查串口是否正常工作 我将在我的C++程序Linux Ubuntu 10.4中使用串口,这是我的开放端口函数: int Recorder::OpenPort() { int intFd ; struct termios options; intFd=open("/dev/ttyS0", O_RDWR | O_NOCTTY| O_NDELAY); if (intFd==-1){ perror("open_port: Unable to open /dev/ttyS0 - "); } fcntl(intFd, F_SETFL, FNDELAY); /*configuration the port*/ tcgetattr(intFd, &options); //set baud rates at 115200 cfsetispeed(&options, B115200 ); cfsetospeed(&options, B115200); //mask the character size to 8 bit data & no parity.CHARACTER SIZE SETTING options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; //setting hardware flow control options.c_cflag |= CRTSCTS; //Enable the receiver and set local mode .should always be enabled (enable receiver and dont change owner of port) options.c_cflag |= (CLOCAL | CREAD); //flush output buffer options.c_lflag |= FLUSHO; //choosing raw data disable echoing options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //not setting software flow control options.c_iflag &= ~(IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; // //output changes :for mapping NL to CR-NL. // options.c_oflag |= (OPOST | ONLCR ); // // options.c_oflag |= (NL1 | CR1 | FFDLY); tcsetattr(intFd, TCSANOW, &options); return intFd; },c++,linux,serialization,ubuntu-10.04,C++,Linux,Serialization,Ubuntu 10.04,这是我检查序列号的示例: int serial=0; ioctl(intFd, TIOCMGET, &serial); //for ubuntu 7.04 and 10.04 if(serial==16390 || serial==16422 || serial==16454 || serial==16486){//no connection with serial port 我检查了我的程序很多次,串行是16486每次,这意味着我没有与串行端口连接,

这是我检查序列号的示例:

int  serial=0;
    ioctl(intFd, TIOCMGET, &serial);
    //for ubuntu 7.04 and 10.04
        if(serial==16390 || serial==16422 || serial==16454 || serial==16486){//no connection with serial port

我检查了我的程序很多次,串行是16486每次,这意味着我没有与串行端口连接,我检查了我的串行电缆,它是好的?那么我该如何解决我的问题呢?

仅供参考,来自
TIOCMGET
IOCTL的结果是一个位字段,所以不要检查值,检查位。您启用了RTS/CTS。你也有支持它的物理线路吗?你的确切意思是什么?我使用带有9针的串行端口,因此我有RTS/CTS,哪些位应在串行中检查?是否有任何参考信息向我提供此信息@Joachim Pileborg通常,串行仅使用3根导线:RX、TX和GND。如果您想使用RTS/CTS,还需要将这些连接起来。我不知道是哪一个PIN,但在网上很容易找到。此外,您正在与之通信的设备应支持它。