首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏python3

    python 监控键盘输入

    /usr/bin/env python # -*- coding: utf-8 -*- import os import sys import tty, termios import time "" i j k l m""" print 'press Q to quit' while True: fd=sys.stdin.fileno() old_settings=termios.tcgetattr (fd) #old_settings[3]= old_settings[3] & ~termios.ICANON & ~termios.ECHO try: tty.setraw(fd) ch=sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) #print

    2K20发布于 2020-01-07
  • 来自专栏刘晓杰

    18(终端IO)和19(伪终端)

    输入字符不组成行 1 获得和设置终端属性 使用函数tcgetattr和tcsetattr可以获得或设置termios结构。 这样也可以检测和修改各种终端选择标志和特殊字符,以使终端按照我们所希望的方式进行操作 #include <termios.h> int tcgetattr(int filedes, struct termios 0 if OK, 1 on error Termios结构返回或者设置当前终端的属性。 */ pid_t pty_fork(int *ptrfdm, char *slave_name, int slave_namesz, const struct termios *slave_termios 如果指针slave_termios非空,那么系统使用这个引用的结构来初始化slave的终端行规程。如果这个指针为空,那么系统设置slave的termios结构为系统定义的初始状态。

    1.3K30发布于 2019-02-21
  • 来自专栏Linux知识

    Linux串口编程示例

    termios termios是用于终端I/O的较新(现在已经有几十年历史)Unix API。 通过close关闭设备 termios 的必要声明和常量可以在头文件 <termios.h> 中找到。 如果没有特殊处理,默认的模式是规范模式 termios.h 串口所有的配置都是通过使用在 termios.h 标头中定义的 struct termios 数据结构完成的。 *termios_p);/*返回将终端设置为原始模式的配置*/ speed_t cfgetispeed(const struct termios *termios_p);/*获取输入速度*/ speed_t cfgetospeed(const struct termios *termios_p);/*获取输出速度*/ int cfsetispeed(struct termios *termios_p,

    2.9K10编辑于 2025-02-19
  • 来自专栏嵌入式随笔

    LINUX的串口非标准波特率更改

    图4 修改函数speed_t tty_termios_baud_rate(struct ktermios *termios),图5 图5 其中圈起来的地方是新加的,这就是根据刚才新加的部分进行波特率修改 第三步,应用端的配置,应用端通常使用tcsetattr这个函数进行配置,在使能之前,对齐c_cflag进行赋值就可 struct termios , termios_new; termios_new.c_cflag |= 0020001; (其余配置省略) tcsetattr(fdcom, TCSANOW, &termios_new); 这样串口波特率即更改为100k,如需其他波特率在头文件处增加,应用端赋值对应数值即可

    4.8K30编辑于 2022-12-05
  • 来自专栏python前行者

    Python实现控制台密码星号输入

    /usr/bin/python # -*- coding=utf-8 -*- import sys, tty, termios #for python 2.x def getch(): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno ()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings ()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr

    4.7K30发布于 2019-03-25
  • 来自专栏全栈程序员必看

    CubieBoard2串口

    locate symbol “tcgetattr” referenced by libserialport.so 解决方法: 将api 19 的 termios.h 拷贝到 jni 目录下 termios.h _ #define _TERMIOS_H_ #include <sys/cdefs.h> #include <sys/ioctl.h> #include <sys/types.h> *s) { return (speed_t)(s->c_cflag & CBAUD); } static __inline__ int cfsetospeed(struct termios *s) { return (speed_t)(s->c_cflag & CBAUD); } static __inline__ int cfsetispeed(struct termios _ */ 然后在c文件中,将#include <termios.h>改为#include "termios.h"。

    78120编辑于 2022-09-16
  • 来自专栏coderhuo

    串口通信中ICRNL惹的祸

    顺便说下,如果串口用于数据传输,可以设置成Raw mode,关闭回显、行控制、转义等功能: termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); termios_p->c_oflag &= ~OPOST; termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); termios_p->c_cflag &= ~(CSIZE | PARENB); termios_p->c_cflag |= CS8; 参考文档 : https://linux.die.net/man/3/termios

    2.7K21发布于 2018-08-29
  • 来自专栏格物致知

    linux系统kbhit的几种实现

    一,用select #include <stdio.h> #include <termios.h> #include <unistd.h> #include <sys/types.h> printf("\nGot %c\n", ch); changemode(0); return 0; } void changemode(int dir) { static struct termios NULL, NULL, &tv); return FD_ISSET(STDIN_FILENO, &rdfs); } 二,用非阻塞io #include <stdio.h> #include <termios.h > #include <unistd.h> #include <fcntl.h> int kbhit(void) { struct termios oldt, newt; int ch;

    1.1K30编辑于 2022-08-19
  • 来自专栏玩转编程

    Python 系列文章 —— paramiko 详解

    catout.read().decode('utf-8')) ssh.close()import paramiko import select import sys import tty import termios trans.open_session() # 获取一个终端 channel.get_pty() # 激活终端 channel.invoke_shell() # 获取Linux操作终端的属性 oldtty = termios.tcgetattr sys.stdout.write(result.decode()) sys.stdout.flush() finally: # 还原Linux终端属性 termios.tcsetattr (sys.stdin, termios.TCSADRAIN, oldtty) channel.close() trans.close()import paramiko try: client

    1.1K20编辑于 2022-01-13
  • 来自专栏嵌入式与Linux那些事

    【驱动】串口驱动分析(三)-serial driver

    = tty_std_termios; normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; normal->init_termios.c_ispeed the tty termios setting. */ if (port->tty && termios.c_cflag == 0) termios = port->tty->termios ; /*如果启用了控制台挂起,则函数使用uart_change_pm将电源管理状态更改为打开状态,使用uport->ops->set_termios设置termios,并使用console_start * @termios: desired termios settings. hung_up) tty_termios_encode_baud_rate(termios, baud, baud); old = NULL; continue;

    2.5K10编辑于 2024-05-11
  • 来自专栏个人路线

    Whois 工具在 鸿蒙 PC 上的交叉编译实践

    defined(getpass) #include <termios.h> #include <signal.h> staticchar *getpass_buffer = NULL; static old_termios, new_termios; FILE *tty; int c; size_t len = 0; size_t size = 128; ) == 0) { new_termios = old_termios; new_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tcsetattr(fileno(tty), TCSAFLUSH, &new_termios); } /* Set up signal handler ) == 0) { tcsetattr(fileno(tty), TCSAFLUSH, &old_termios); } /* Restore signal handler

    21810编辑于 2025-11-29
  • 来自专栏Rice嵌入式

    linux uart应用开发(ttyS*设备)《Rice linux 学习开发》

    115200: cfsetispeed(&opts, B115200); cfsetospeed(&opts,B115200); 3.串口属性配置: 串口的属性定义在结构体struct termios ,其头文件#include<asm/termbits.h>,结构体定义如下: #define NCCS 19 struct termios { tcflag_t c_iflag; / 结构的指针 ②tcgetsttr(int fd, termios *ptr),返回值:成功返回0,失败返回-1。 fd:待操作的文件描述符 *ptr:指向termios结构的指针 4.属性描述: ①:c_iflag: IGNBRK:忽略输入中的 BREAK 状态。 (POSIX 规定波特率存储在 termios 结构中,并未精确指定它的位置,而是提供了函数 cfgetispeed() 和 cfsetispeed() 来存取它。

    4.5K10编辑于 2022-05-09
  • 来自专栏全栈程序员必看

    RK平台 USB转RS485

    POSIX规范API 标准接口: #include <termios.h> speed_t cfgetispeed(const struct termios *); speed_t cfgetospeed (const struct termios *); int cfsetispeed(struct termios *, speed_t speed); int cfseospeed(struct termios *, speed_t speed); 这些API 作用于termios结构。 需要先调用tcgetattr()获得termios结构,再调用以上函数设置终端速度,最后调用tcsetattr()使设置生效。 其他API #include <termios.h> int tcdrain(int fd);让调用程序一直等待,直到所有排队的输出都发送完毕 int tcflow(int, int flowtype)

    1.6K10编辑于 2022-08-15
  • 来自专栏python3

    python模块paramiko与ssh

    模块直接用ssh协议登陆到远程服务器的操作代码,这里先定义一个interactive模块,代码如下: import socket import sys # windows does not have termios ... try:     import termios     import tty     has_termios = True except ImportError:     has_termios  = False def interactive_shell(chan):     if has_termios:         posix_shell(chan)     else:          windows_shell(chan) def posix_shell(chan):     import select     oldtty = termios.tcgetattr(sys.stdin (sys.stdin, termios.TCSADRAIN, oldtty) # thanks to Mike Looijmans for this code def windows_shell(chan

    1.9K10发布于 2020-01-15
  • 来自专栏涛的程序人生

    Linux C语言实现输入密码显示星号-手动实现getch()

    手动实现getch() 废话不多说直接上代码 github传送门 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h password); printf("%s\n", password); return 0; } int getch(void) { int ch; struct termios

    3.6K20编辑于 2021-12-24
  • 来自专栏零域Blog

    Unix-Linux编程实践教程-chapter06-signal

    , 1 => no, 2=> timeout * better: reset terminal mode on Interrupt */ #include <stdio.h> #include <termios.h ) /* * purpose: put file descriptior 0 into chr-by-chr mode and noecho mode * method: use bits in termios */ { struct termios ttystate; tcgetattr(0, &ttystate); // read curr. setting ttystate.c_lflag install 'em } // how == 0 => save currentmode // how == 1 => restore mode // this version handles termios and fcntl flags tty_mode(int how) { static struct termios original_mode; static int original_flags

    1.4K10编辑于 2022-03-02
  • 来自专栏蓝天

    代码中创建新终端

    signo)); } int main() { int amaster = 0;     char name[100];     struct termios termp; // termios.h (bits/termios.h)     struct winsize winp; // term.h(bits/ioctl-types.h)

    1.2K20发布于 2018-08-10
  • 来自专栏猿人谷

    apue.h头文件

    /* some systems still require this */ 7 #include <sys/stat.h> 8 #include <sys/termios.h void tty_atexit(void); /* Figure 18.20 */ 56 #ifdef ECHO /* only if <termios.h > has been included */ 57 struct termios *tty_termios(void); /* Figure 18.20 */ 19.10 */ 80 #ifdef TIOCGWINSZ 81 pid_t pty_fork(int *, char *, int, const struct termios

    2.5K60发布于 2018-01-17
  • 来自专栏Pulsar-V

    C++随笔(五)三种实现串口通信的方式

    一般形式 #include <stdio.h> #include <errno.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h include <unistd.h> int set_serial(int fd,int nSpeed,int nBits,char nEvent,int nStop) { struct termios unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<sys/signal.h> #include<fcntl.h> #include<termios.h 4800, 2400, 1200, 300,}; void set_speed(int fd, int speed) { int i; int status; struct termios unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<sys/signal.h> #include<fcntl.h> #include<termios.h

    8K20发布于 2019-08-08
  • 来自专栏零域Blog

    Unix-Linux编程实践教程-chapter05-stty

    flagset &= ~MASK code /* showtty.c * display some current tty settings */ #include <stdio.h> #include <termios.h > main() { struct termios ttyinfo; if (tcgetattr(0, &ttyinfo) == -1) { perror("cannot as BS-SPACE-BS", ECHOK, "Echo KILL by starting new line", 0, NULL }; show_some_flags(struct termios

    75210编辑于 2022-03-02
领券