当前位置: 首页 > news >正文

网站建设合理流程网站维护中是什么意思

网站建设合理流程,网站维护中是什么意思,泰州企业自助建站系统,大型网站都怎么做推广一、 串口API 在Linux系统中,操作设备的统一接口就是:open/ioctl/read/write。 对于UART,又在ioctl之上封装了很多函数,主要是用来设置行规程。 所以对于UART,编程的套路就是: open设置行规程,比如波特率、数据位、停止位、检验位、RAW模式、一有数据就返回read/write 怎么设置…

一、 串口API

在这里插入图片描述
在Linux系统中,操作设备的统一接口就是:open/ioctl/read/write。
对于UART,又在ioctl之上封装了很多函数,主要是用来设置行规程。
所以对于UART,编程的套路就是:

  • open
  • 设置行规程,比如波特率、数据位、停止位、检验位、RAW模式、一有数据就返回
  • read/write
    怎么设置行规程?行规程的参数用结构体termios来表示,可以参考Linux串口—struct termios结构体
typedef unsigned char 	cc_t;
typedef unsigned int 	speed_t;
typedef unsgined int 	tcflag_t;#define NCCS 19
struct termios {tcflag_t c_iflag;		/* input mode flags */tcflag_t c_oflag;		/* output mode flags */tcflag_t c_cflag;		/* control mode flags */tcflag_t c_lflag;		/* local mode flags */cc_t c_line;			/* line discipline */cc_t c_cc[NCCS];		/* control characters */
};

这些函数在名称上有一些惯例:

  • tc: terminal control
  • cf: control flag
函数名作用
tcgetattrget terminal attributes,获得终端的属性
tcsetattrset terminal attributes,修改终端参数
tcflush清空终端未完成的输入/输出请求及数据
cfsetispeedsets the input baud rate,设置输入波特率
cfsetospeedsets the output baud rate,设置输出波特率
cfsetspeed同时设置输入、输出波特率

函数不多,主要是需要设置好termios中的参数,这些参数很复杂,可以参考Linux串口—struct termios结构体。

二、编程

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>int set_opt(int fd, int nSpeed, int nBits, char nEvent, int nStop)
{struct termios newtio, oldtio;if(tcgetattr(fd, &oldtio) != 0) {perror("SetupSerial 1");return -1;}bzero(&newtio, sizeof(newtio));newtio.c_cflag |= CLOCAL|CREAD;newtio.c_cflag &= ~CSIZE;newtio.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG);newtio.c_oflag &= ~OPOST;switch(nBits) {case 7:newtio.c_cflag |= CS7;break;case 8:newtio.c_cflag |= CS8;break;}switch(nEvent) {case 0:newtio.c_cflag |= PARENB;newtio.c_cflag |= PARODD;newtio.c_iflag |= (INPCK | ISTRIP);break;case 'E':newtio.c_iflag |= (INPCK|ISTRIP);newtio.c_cflag |= PARENB;newtio.c_cflag &= ~PARODD;break;case 'N':newtio.c_cflag &= ~PARENB;break;}switch(nSpeed) {case 2400:cfsetispeed(&newtio, B2400);cfsetospeed(&newtio, B2400);break;case 4800:cfsetispeed(&newtio, B4800);cfsetospeed(&newtio, B4800);break;case 9600:cfsetispeed(&newtio, B9600);cfsetospeed(&newtio, B9600);break;case 115200:cfsetispeed(&newtio, B115200);cfsetospeed(&newtio, B115200);break;default:cfsetispeed(&newtio, B9600);cfsetospeed(&newtio, B9600);break;}if(nStop == 1)newtio.c_cflag &= ~CSTOPB;else if(nStop == 2)newtio.c_cflag |= CSTOPB;newtio.c_cc[VMIN] = 1;newtio.c_cc[VTIME] = 0;tcflush(fd, TCIFLUSH);if((tcsetattr(fd, TCSANOW, &newtio)) != 0) {perror("com set error");return -1;}return 0;
}int open_port(char *com)
{int fd;fd = open(com, O_RDWR|O_NOCTTY);if(-1 == fd) {return -1;}if(fcntl(fd, F_SETFL, 0) < 0) {printf("fcntl failed\n");return -1;}return fd;
}int main(int argc, char *argv[])
{int fd;int iRet;char c;if(argc != 2) {printf("Usage: \n");printf("%s </dev/ttySAC1 or other>\n", argv[0]);return -1;}fd = open_port(argv[1]);if(fd < 0) {printf("open %s err!\n", argv[1]);return -1;}iRet = set_opt(fd, 115200, 8, 'N', 1);if(iRet) {printf("set port err!\n");return -1;}printf("Enter a char: ");while(1) {scanf("%c", &c);iRet = write(fd, &c, 1);iRet = read(fd, &c, 1);if(iRet == 1) {printf("get: %02x %c\n", c, c);} else {printf("can not get data\n");}}return 0;
}

三、上机实验

短接串口的RX和TX

root@npi:~/test# ./a.out /dev/ttymxc2 
Enter a cahr: a
get: 61 a
get: 0a get: 0a get: 0a a 
get: 61 a
get: 0a 
http://www.dinnco.com/news/64788.html

相关文章:

  • 手机电脑同步网站开发网站seo诊断报告
  • 网站开发风险不限制内容的搜索引擎
  • eclipes 网站开发google app下载
  • 菜鸟学做网站的步骤百度小程序排名优化
  • 邯郸市商标设计品牌策划公司连云港seo
  • 做网站需要申请商标哪些类目建设网站制作
  • 网页分析从哪些方面浙江seo技术培训
  • 简历表格 个人简历手机版哈尔滨seo关键字优化
  • 好看的美食怎么做视频网站优化设计五年级下册语文答案
  • 昆明网站seo报价网络推广宣传方式
  • 大连 网站制作网页制作网站
  • 做资讯网站怎么挣钱宣传网站有哪些
  • 二手书网站开发设计seo定义
  • 网站维护费用明细网站优化排名推广
  • 东营网站设计多少钱云南网络推广seo代理公司
  • 西安手机网站建设国外浏览器搜索引擎入口
  • .ai域名注册网站成都seo达人
  • 女人网上量体做衣网站百度度小店申请入口
  • 做网站的注意点关键词排名点击软件
  • 江阴做网站优化高平网站优化公司
  • 人像摄影网站有哪些企业微信会话存档
  • 那个做图网站叫什么渠道推广平台
  • 福建建设注册管理中心网站如何网站推广
  • 手机怎么做销售网站互联网营销课程体系
  • 开网店卖什么最赚钱seo高手培训
  • 设计电子商务网站方式制作网站
  • dw做的网站怎么发布到网上我是seo关键词
  • 网站备案证书放到哪里信息流推广渠道有哪些
  • 做建网站的公司国内时事新闻
  • 搜索网站老是跳出别的网站要怎么做南昌seo服务