如何用pySerial在python中配置tty?

2024-10-01 11:20:37 发布

您现在位置:Python中文网/ 问答频道 /正文

模块pySerial提供与串行设备通信的接口。但是,查看串行设备的配置,例如/dev/ttyS1,有许多事情需要配置:

stty -F /dev/ttyS1 -a
speed 1200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
parenb -parodd cs7 -hupcl cstopb cread clocal -crtscts
-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke

我对参数-parodd cs7特别感兴趣。有没有一种方法可以在python中配置这个参数,或者我必须调用一个外部命令来完成这个操作(比如stty -F /dev/ttyS1 ...)?在


Tags: 模块columnsdev参数line事情sttyrows
1条回答
网友
1楼 · 发布于 2024-10-01 11:20:37

是的,您甚至可以在声明后进行配置

ser = serial.Serial('/dev/ttyS1', 19200, timeout=1, parity=serial.PARITY_ODD)

ser.parity = serial.PARITY_EVEN

ser.bytesize = serial.SEVENBITS

相关问题 更多 >