linux系统不断将端口的波特率改为默认(9600)。有没有更好的方法来永久更改端口的波特率?

Vis*_*nha 2 linux serial-port

我使用命令 # stty -F/dev/ttyUSB0 115200 将我的 linux USB 端口的波特率从 9600 更改为 115200,因为我正在使用的 FPGA 被编程为 115200 的波特率。

我使用 # stty -F/dev/ttyUSB0 -a 交叉验证了新的波特率。这给了我以下结果:

速度 115200 波特;第 0 行;第 0 列;线 = 0; 内部= ^ C; 退出 = ^\; 擦除 = ^?; 杀 = ^U; eof = ^ D; eol = ; eol2 = ; 开关 = ; 开始 = ^Q; 停止 = ^ S; 暂停 = ^ Z; rpnt = ^R; wase = ^W;lnext = ^V; 丢弃 = ^O; 分钟 = 1; 时间 = 0; -parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8opost -olcuc -ocrnlocr onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

但是,当我运行我的程序时,波特率变回 9600:python new.py 正在搜索接口... ['/dev/ttyUSB0']

ser:串行(端口='/dev/ttyUSB0',波特率=9600,字节大小=8,奇偶校验='N',停止位=1,超时=无,xonxoff=假,rtscts=假,dsrdtr=假)。

我该怎么办?

小智 5

如果您没有使用 pyserial 明确提及波特率,它将使用9600作为默认值。所以之前的波特率设置是没有用的。在使用 stty 命令和接收器设置为 115200 波特率后尝试 echo hello > /dev/ttyUSB0。