tty linux 打开和设置范例
http://bbs.csdn.net/topics/340184140
/************************************************************************************ * tty_open_port() open the tty port ************************************************************************************/int tty_open_port(const char *dev_name){ int fd; /* File descriptor for the port */ fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY); if (-1 == fd) { perror("open_port: Unable to open tty " ); exit(1); } else { if(DEBUG) printf("The %s is opened \n",dev_name); }/* if( (val=fcntl(fd, F_SETFL, 0))< 0) perror("fcntl failed");*/ if ( isatty(fd) == 0 ) perror("This is not a tty device "); return (fd);}/************************************************************************************ * tty_set_port() set the attributes of the tty ************************************************************************************/ int tty_set_port (int fd , int nSpeed , int nBits , char nEvent , int nStop ){ struct termios new_ios,old_ios; if ( tcgetattr ( fd , &new_ios ) !=0 ) perror("Save the terminal error"); bzero( &old_ios , sizeof( struct termios )); old_ios=new_ios; tcflush(fd,TCIOFLUSH) ; new_ios.c_cflag |= CLOCAL |CREAD ; new_ios.c_cflag &= ~CSIZE ; switch (nBits) { case 5: new_ios.c_cflag |=CS5 ; break ; case 6: new_ios.c_cflag |=CS6 ; break ; case 7: new_ios.c_cflag |=CS7 ; break ; case 8: new_ios.c_cflag |=CS8 ; break ; default: perror("Wrong nBits"); break ; } switch (nSpeed ) { case 2400: cfsetispeed(&new_ios , B2400); cfsetospeed(&new_ios , B2400); break; case 4800: cfsetispeed(&new_ios , B4800); cfsetospeed(&new_ios , B4800); break; case 9600: cfsetispeed(&new_ios , B9600); cfsetospeed(&new_ios , B9600); break; case 19200: cfsetispeed(&new_ios , B19200); cfsetospeed(&new_ios , B19200); break; case 115200: cfsetispeed(&new_ios , B115200); cfsetospeed(&new_ios , B115200); break; case 460800: cfsetispeed(&new_ios , B460800); cfsetospeed(&new_ios , B460800); break; default: perror("Wrong nSpeed"); break; } switch (nEvent ) { case 'o': case 'O': new_ios.c_cflag |= PARENB ; new_ios.c_cflag |= PARODD ; new_ios.c_iflag |= (INPCK | ISTRIP); break ; case 'e': case 'E': new_ios.c_iflag |= (INPCK | ISTRIP); new_ios.c_cflag |= PARENB ; new_ios.c_cflag &= ~PARODD ; break ; case 'n': case 'N': new_ios.c_cflag &= ~PARENB ; new_ios.c_iflag &= ~INPCK ; break ; default: perror("Wrong nEvent"); break ; } if ( nStop == 1 ) new_ios.c_cflag &= ~CSTOPB ; else if ( nStop == 2 ) new_ios.c_cflag |= CSTOPB ; /*No hardware control*/ new_ios.c_cflag &= ~CRTSCTS; /*No software control*/ new_ios.c_iflag &= ~(IXON | IXOFF | IXANY); /*delay time set */ new_ios.c_cc[VTIME] = 0 ; new_ios.c_cc[VMIN] = 0 ; /*raw model*/ new_ios.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); new_ios.c_oflag &= ~OPOST; new_ios.c_iflag &= ~(INLCR|IGNCR|ICRNL); new_ios.c_iflag &= ~(ONLCR|OCRNL); new_ios.c_oflag &= ~(INLCR|IGNCR|ICRNL); new_ios.c_oflag &= ~(ONLCR|OCRNL); tcflush(fd,TCIOFLUSH) ; if (tcsetattr(fd,TCSANOW,&new_ios) != 0 ) { perror("Set the terminal error"); tcsetattr(fd,TCSANOW,&old_ios); return -1 ; } return 0;}tty linux 打开和设置范例的更多相关文章
- Linux打开文件设置
在某些情况下会要求增加Linux的文件打开数,以增加服务器到处理效率,在Linux下查看最多能打开的文件数量为: cat /proc/sys/fs/file-max 然后设置ulimit -n 文件数 ...
- Linux环境变量设置
修改环境变量PATH 最近为root添加一个环境变量发现sudo su进去没有变化所以总结了一下所有设置环境变量的方法: 查看PATH:echo $PATH 直接在命令行修改,就可以使用,但是只有在当 ...
- 教你如何在Kali Linux 环境下设置蜜罐?
导读 Pentbox是一个包含了许多可以使渗透测试工作变得简单流程化的工具的安全套件.它是用Ruby编写并且面向GNU/Linux,同时也支持Windows.MacOS和其它任何安装有Ruby的系统. ...
- linux打开80端口及80端口占用解决办法
linux打开80端口天客户那边有台服务器同一个局域网中都无法访问,排除lamp环境问题,发现时服务器中的防火墙没有开启80端口. 代码如下 复制代码vi /etc/sysconfig/iptable ...
- linux中怎样设置dhcpd
linux中怎样设置DHCP 在 linux 以下设置 DHCP一点也不复杂﹐您全部要做的仅仅有一个文件﹕/etc/dhcpd.conf . 以下﹐我用我自己的设置文件来说说怎么改动这个文件﹕ d ...
- Linux 打开句柄限制的调整
Linux 打开句柄限制的调整 参考文章: Linux---进程句柄限制总结(http://blog.csdn.net/jhcsdb/article/details/32338953) !! 本文内容 ...
- linux linux系统常用设置
linux linux系统常用设置 一.设置开机时开启数字键 修改rc.local文件 命令:vi /etc/rc.local rc.local文件中增加如下代码: INITTY=/dev/tty ...
- Linux打开防火墙telnet端口
检查端口情况:netstat -an | grep 22 关闭端口号:iptables -A INPUT -p tcp --drop 端口号-j DROP ipt ...
- linux core文件设置
http://blog.csdn.net/ctthuangcheng/article/details/8963551 linux core文件设置 分类: Linux OS Debugging Te ...
随机推荐
- servletConfig的使用案例
servletConfig参数的使用案例 首先,建立Dynamic Web Project ,同样命名FirstServlet,然后建立Servlet:Login.java,包名为cc.openhom ...
- 边框(border)宽度样式颜色 和基本属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- canal 常用配置
https://github.com/alibaba/canal/wiki/AdminGuide canal.instance.filter.regex 监控哪些表的正则配置 如下: mysql 数据 ...
- UI5-文档-4.3-Controls
现在是时候构建我们的第一个小UI了,将HTML主体中的“Hello World”文本替换为SAPUI5控件sap.m.Text.首先,我们将使用JavaScript控件接口来设置UI,然后将控件实例放 ...
- 认识serviceLoader
最近在研究系统设计方面的东西,发现有很多通用的解决方案,包括spring配置扩展以及serviceLoader的应用,这里简单记录下serviceLoader的简单应用,网上例子很多,大同小异,本人觉 ...
- 协变(covariance),逆变(contravariance)与不变(invariance)
协变,逆变与不变 能在使用父类型的场景中改用子类型的被称为协变. 能在使用子类型的场景中改用父类型的被称为逆变. 不能做到以上两点的被称为不变. 以上的场景通常包括数组,继承和泛型. 协变逆变与泛型( ...
- Eclipse 安装JavaEE插件
Oxygen版Eclipse 导入项目会自动安装你项目需要的一些插件,但是有时候会安装失败,需要手动安装: 这里以Dynamic Web Project项目为例 打开Eclipse,依次选择Help ...
- vps hiformance 设置备忘
ssr一键安装脚本 wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ ...
- python -m
影响sys.path python xxx.py python -m xxx.py 这是两种加载py文件的方式:1叫做直接运行2把模块当作脚本来启动 直接启动是把脚本所在的目录放到了sys.path属 ...
- triton,docker,mesos
triton user: jill /root/.sdc/docker/jill 下 root@1f6af9d8-8ed9-e940-9c6c-d9505ca25896:~/.sdc/docker/j ...