Linux,串口,非缓冲模式

我正在尝试在Linux中使用串口组织阻塞读写function。 这里是我有的代码: http : //pastebin.com/RSPw7HAi这一切工作正常,但它是缓冲。 这意味着,如果我通过控制台+ CR符号input串行,select检测新的input,否则,如果我通过简单的Python脚本input,它会caching所有的符号,并等待,直到我发送回车符号。 所以这个input(下面给出)它只是缓冲符号的地方。 我必须通过USB2Serial转换器连接PC

#!/usr/bin/env python3 import serial cmd1_state = b'\x3E\x01\x00\x01' #Selecting serial port for commands to be sent --> /dev/ttyUSB0 serial_0 = serial.Serial('/dev/ttyUSB2'); print("Using serial port ", serial_0.portstr); serial_0.write(cmd1_state) # closing serial port serial_0.close() 

那么,有人可以告诉我该怎么办? 我必须改变我的C文件中的端口打开或使用python脚本完成的东西吗? 我在后面使用flush()方法,但也没有帮助。 顺便说一句,我已经用F_NOCACHE arg来searchfcntl()函数。 但! 这一切都是关于BSD和Darwin操作系统的,在我看来,Linux中没有这样的东西(F_NOACHE arg to fcntl)。

UPD:看起来我发现了解决scheme。

  /* set input mode (non-canonical, no echo,...) */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */ tcflush(fd, TCIFLUSH); 

取自: http : //tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html

看起来我发现了解决方案。

 /* set input mode (non-canonical, no echo,...) */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */ tcflush(fd, TCIFLUSH); Taken from : http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html