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

公司网站维护都需要怎么做网站建设公司多少钱

公司网站维护都需要怎么做,网站建设公司多少钱,东戴河网站建设,大连连城传媒485通信1. 485通信1.1 termios结构1.2 头文件1.3 函数讲解1.3.1 tcgetattr1.3.2 tcsetattr1.4 示例工程1.5 参考文献1.5.1 stty命令1.5.2 命令格式1.5.2 microcom命令1.5.2.1介绍1.5.2.2指令1.5.3 echo命令1.5.3.1 语法1.5.3.2 选项列表1.5.3.3 使用示例1.5.3.4 e cho 输出… 485通信1. 485通信1.1 termios结构1.2 头文件1.3 函数讲解1.3.1 tcgetattr1.3.2 tcsetattr1.4 示例工程1.5 参考文献1.5.1 stty命令1.5.2 命令格式1.5.2 microcom命令1.5.2.1介绍1.5.2.2指令1.5.3 echo命令1.5.3.1 语法1.5.3.2 选项列表1.5.3.3 使用示例1.5.3.4 e cho 输出重定向1.5.3.5 echo 输出追加重定向1. 485通信 在进行代码撰写前先熟悉这个串口termios结构体 1.1 termios结构 termios结构定义于termios.h头文件中描述了提供的通用终端接口用于控制异步通信端口。该文件中还定义了一组函数调用通过该结构体和函数调用即可对终端进行一系列的设置。对于termios结构而言可以简单地将其理解为是一个用于描述一个终端属性的结构体。 struct termios 结构用来持有所有的当前线路设置, 给这个 tty 设备的一个特定端口. 这些线路设置控制当前波特率, 数据大小, 数据流控设置。 termios结构如下 #include termios.h struct termios {tcflag_t c_iflag;tcflag_t c_oflag;tcflag_t c_cflag;tcflag_t c_lflag;cc_t c_cc[NCCS]; }该结构的5个成员分别代表了 输入模式输出模式控制模式本地模式特殊控制字符关于函数调用这篇笔记中先描述两个 1.2 头文件 #include termios.h1.3 函数讲解 1.3.1 tcgetattr int tcgetattr(int fd, struct termios *termios_p);函数tcgetattr起初始化的作用它将一个终端与一个termios结构关联起来然后用termios_p指针指向这个termios结构。成功调用后termios_p所指向的结构中就保存着指定终端当前的属性。 1.3.2 tcsetattr int tcsetattr(int fd, int actions, const struct termios *termios_p);函数tcsetattr一般用于重新配置终端它会将指定的终端配置成第三个指针参数所指向的termios结构。至于第二个参数actions用于调整tcsetattr函数行为上的一些细节它有三个可选值 TCSANOW立刻进行修改。 TCSADRAIN等当前的输出完成后再进行修改 TCSAFLUSH等当前的输出完成后再进行修改但丢弃还未从read调用返回的当前可用的任何输入关于修改终端属性的代码一般有如下的结构 struct termios initset, newset; tcgetattr(fd , initset); newset initset ....... tcsetattr(int fd , actions , initset); exit(0);Linux 为我们提供了专门的设置修改参数的接口如下 NAMEtermios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed - get and set terminal attributes, line con‐trol, get and set baud rateSYNOPSIS#include termios.h#include unistd.hint tcgetattr(int fd, struct termios *termios_p);int tcsetattr(int fd, int optional_actions,const struct termios *termios_p);int tcsendbreak(int fd, int duration);int tcdrain(int fd);int tcflush(int fd, int queue_selector);int tcflow(int fd, int action);void cfmakeraw(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, speed_t speed);int cfsetospeed(struct termios *termios_p, speed_t speed);int cfsetspeed(struct termios *termios_p, speed_t speed);Feature Test Macro Requirements for glibc (see feature_test_macros(7)):cfsetspeed(), cfmakeraw(): _BSD_SOURCEtcsetattr 从termios_p引用的termios结构中设置与终端关联的参数除非需要不可用的基础硬件的支持。 optional_actions指定更改何时生效 TCSANOW更改立即发生。 TCSADRAIN在传输完所有写入fd的输出之后将发生更改。 更改影响输出的参数时应使用此功能。 TCSAFLUSH更改发生在所有写入fd引用的对象的输出已发送之后并且在进行更改之前已接收但未读取的所有输入将被丢弃。 原始模式 cfmakeraw将终端设置为类似于旧版本7终端驱动程序的“原始”模式逐字符可用输入禁用回显并且禁用终端输入和输出字符的所有特殊处理。 终端属性设置如下 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;Line controltcsendbreak() transmits a continuous stream of zero-valued bits for a specific duration, if the terminal is using asynchronous serial data transmission. If duration is zero, it transmitszero-valued bits for at least 0.25 seconds, and not more that 0.5 seconds. If duration is not zero, it sends zero-valued bits for some implementation-defined length of time.If the terminal is not using asynchronous serial data transmission, tcsendbreak() returns without taking any action.tcdrain() waits until all output written to the object referred to by fd has been transmitted.tcflush() discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of queue_selector:TCIFLUSHflushes data received but not read.TCOFLUSHflushes data written but not transmitted.TCIOFLUSHflushes both data received but not read, and data written but not transmitted.tcflow() suspends transmission or reception of data on the object referred to by fd, depending on the value of action:TCOOFF suspends output.TCOON restarts suspended output.TCIOFF transmits a STOP character, which stops the terminal device from transmitting data to the system.TCION transmits a START character, which starts the terminal device transmitting data to the system.The default on open of a terminal file is that neither its input nor its output is suspended.Line speedThe baud rate functions are provided for getting and setting the values of the input and output baud rates in the termios structure. The new values do not take effect until tcsetattr() issuccessfully called.Setting the speed to B0 instructs the modem to hang up. The actual bit rate corresponding to B38400 may be altered with setserial(8).The input and output baud rates are stored in the termios structure.cfgetospeed() returns the output baud rate stored in the termios structure pointed to by termios_p.cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed, which must be one of these constants:B0B50B75B110B134B150B200B300B600B1200B1800B2400B4800B9600B19200B38400B57600B115200B230400The zero baud rate, B0, is used to terminate the connection. If B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line. CBAUDEX is amask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, B57600 CBAUDEX is nonzero.cfgetispeed() returns the input baud rate stored in the termios structure.cfsetispeed() sets the input baud rate stored in the termios structure to speed, which must be specified as one of the Bnnn constants listed above for cfsetospeed(). If the input baud rateis set to zero, the input baud rate will be equal to the output baud rate.cfsetspeed() is a 4.4BSD extension. It takes the same arguments as cfsetispeed(), and sets both input and output speed.1.4 示例工程 dataType.h #ifndef DATE_TYPE_H #define DATE_TYPE_H#include stdio.htypedef unsigned char ubyte; typedef char BYTE; typedef unsigned short ushort; typedef unsigned int uint32;#endifrs485Service.h #ifndef __RS485_SERVER_H__ #define __RS485_SERVER_H__#include dataType.htypedef enum {OPEN_485_SUCCESS 0,OPEN_485_FAIL, }Open485State;class Rs485Service {private:Rs485Service();~Rs485Service();public:static Rs485Service Get();public:int Rs485Read(ubyte *buf, uint32 size);int Rs485Write(const ubyte *data, uint32 len);int InitRs485Dev(uint32 bound);void UninitRs485Dev();private:int m_devFd;int m_bound;int32_t m_485WriteState; //true 485处于写状态 };#endifrs485Service.cpp #include algorithm #include stdio.h #include stdlib.h #include string.h #include fcntl.h #include unistd.h #include termios.h #include netinet/in.h #include rs485Service.h#define RS485COM /dev/ttyS1Rs485Service::Rs485Service() {m_devFd -1; }Rs485Service::~Rs485Service() { }Rs485Service Rs485Service::Get() {static Rs485Service Rs485server;return Rs485server; }int Rs485Service::InitRs485Dev(uint32 bound) {system(/usr/local/bin/amba_debug -g 71 -d 1);m_devFd open(RS485COM, O_RDWR | O_NOCTTY); //加上O_NDELAY就变为了非阻塞if (m_devFd ! -1){struct termios cfg;memset(cfg, 0, sizeof(cfg));tcgetattr(0, cfg);switch(bound){case 19200:cfsetispeed(cfg, B19200);cfsetispeed(cfg, B19200);m_bound 19200;break;case 9600:cfsetispeed(cfg, B9600);cfsetispeed(cfg, B9600);m_bound 9600;break;default:cfsetispeed(cfg, B19200);cfsetispeed(cfg, B19200);m_bound 19200;break;}cfg.c_oflag ~(ONLCR);cfg.c_oflag (OCRNL);cfg.c_iflag (INLCR);cfg.c_cflag | CLOCAL | CREAD; //使能串口输入//cfg.c_lflag | ICANON; //标准模式cfg.c_lflag ~ICANON;//原始模式cfg.c_lflag ~(ICANON | ECHO | ECHOE | ISIG);//8bit数据cfg.c_cflag ~CSIZE;cfg.c_cflag | CS8;//1bit停止位cfg.c_cflag ~CSTOPB;//无校验cfg.c_cflag ~PARENB;//禁用硬件流控制cfg.c_cflag ~CRTSCTS;// cfg.c_cc[VTIME] 1; //设置超时时间如果采用非阻塞模式则不设置cfg.c_cc[VMIN] 1; //设置最小接收的数据长度//清楚输入输出缓冲区tcflush(m_devFd, TCIOFLUSH);tcsetattr(m_devFd, TCSANOW, cfg);return OPEN_485_SUCCESS;}else{printf(open dev err.\n);return OPEN_485_FAIL;} }void Rs485Service::UninitRs485Dev() {if (m_devFd ! -1){struct termios cfg;memset(cfg, 0, sizeof(cfg));tcgetattr(0, cfg);cfg.c_cc[VTIME] 1;tcflush(m_devFd, TCIOFLUSH);tcsetattr(m_devFd, TCSANOW, cfg);close(m_devFd);} }int Rs485Service::Rs485Read(ubyte* buf, uint32 size) {int rlen -1;if (m_devFd ! -1){rlen read(m_devFd, buf, size);tcflush(m_devFd, TCIOFLUSH);}return rlen; }int Rs485Service::Rs485Write(const ubyte* data, uint32 len) {int wlen -1;//485是半双工置为发送状态system(/usr/local/bin/amba_debug -g 71 -d 1);if (m_devFd ! -1){wlen write(m_devFd, data, len);}//等待数据输出完毕tcdrain(m_devFd);//清空输入输出缓冲区tcflush(m_devFd, TCIOFLUSH);//485是半双工置为接收状态system(/usr/local/bin/amba_debug -g 71 -d 0);return wlen; } main.cpp #include iostream #include string #include cstring #include thread #include chrono #include rs485Service.hint main() {auto ser Rs485Service::Get();ser.InitRs485Dev(9600);std::thread r([ser](){const int SIZE 1024;char buf[SIZE] {};while (true){std::this_thread::sleep_for(std::chrono::seconds(1));std::memset(buf, 0, SIZE);ser.Rs485Read((unsigned char *)buf, SIZE);std::cout read: buf std::endl;} });std::thread w([ser](){char buf[16] {};while (true){std::this_thread::sleep_for(std::chrono::seconds(1));buf[0];buf[15];ser.Rs485Write((unsigned char *)buf, 16);std::cout write: std::to_string(buf[0]) std::endl;} });r.join();w.join();return 0; }说明.txt # 示例编译 aarch64-linux-gnu-g main.cpp rs485Service.cpp -lpthread -o testcom# 库错误修正 rs485Service.cpp 中有两处需要修改 1. #define RS485COM /dev/ttyS1 旧的是海思版本的设备名2. InitRs485Dev 当前只支持了19200和9600 其他波特率需要增加case# Smart485相机及串口线测试相机终端1# 初始化 stty -F /dev/ttyS1 ispeed 115200 ospeed 115200 cs8 /usr/bin/microcom -s 115200 /dev/ttyS1相机终端2# 设为发送 /usr/local/bin/amba_debug -g 71 -d 1 echo abc /dev/ttyS1# 设为接收 /usr/local/bin/amba_debug -g 71 -d 0 1.5 参考文献 1.5.1 stty命令 1.5.2 命令格式 用法stty [-F 设备 | --file设备] [设置]…  或stty [-F 设备 | --file设备] [-a|–all]  或stty [-F 设备 | --file设备] [-g|–save] 输出或修改终端参数。 -a, --all 以可读性较好的方式输出全部当前设置 -g, --save 以stty 可读取的格式输出当前全部设置 -F, --file设备 打开并使用指定设备代替标准输入 –help 显示此帮助信息并退出 –version 显示版本信息并退出 可选- 在设置前的指示中* 标记出了非POSIX 标准的设置。以下系 统定义象征了哪些设置是有效的。 特殊字符 dsusp 字符 每当输入刷新时会发送一个用于终端阻塞信号的字符 eof 字符 表示文件末尾而发送的字符(用于终止输入) eol 字符 为表示行尾而发送的字符eol2 字符 为表示行尾而发送的另一个可选字符 erase 字符 擦除前一个输入文字的字符 intr 字符 用于发送中断信号的字符 kill 字符 用于擦除当前终端行的字符lnext 字符 用于输入下一个引用文字的字符 quit 字符 用于发送退出信号的字符rprnt 字符 用于重绘当前行的字符 start 字符 在停止后重新开启输出的字符 stop 字符 停止输出的字符 susp 字符 发送终端阻断信号的字符swtch 字符 在不同的shell 层次间切换的字符werase 字符 擦除前一个输入的单词的字符 特殊设置 N 设置输入输出速度为N 波特 cols N 统治内核终端上有N 栏columns N 等于cols N ispeed N 设置输入速度为N 波特line N 设置行约束规则为N min N 和 -icanon 配合使用设置每次一完整读入的最小字符数为 ospeed N 设置输出速度为N 波特rows N 向内核通告此终端有N 行size 根据内核信息输出当前终端的行数和列数 speed 输出终端速度(单位为波特) time N 和-icanon 配合使用设置读取超时为N 个十分之一秒 控制设置 [-]clocal 禁用调制解调器控制信号 [-]cread 允许接收输入 [-]crtscts 启用RTS/CTS 握手 csN 设置字符大小为N 位N 的范围为5 到8 [-]cstopb 每个字符使用2 位停止位 (要恢复成1 位配合-“即可) [-]hup 当最后一个进程关闭标准终端后发送挂起信号 [-]hupcl 等于[-]hup [-]parenb 对输出生成奇偶校验位并等待输入的奇偶校验位 [-]parodd 设置校验位为奇数 (配合”-则为偶数) 输入设置 [-]brkint 任务中断会触发中断信号 [-]icrnl 将回车转换为换行符 [-]ignbrk 忽略中断字符 [-]igncr 忽略回车 [-]ignpar 忽略含有奇偶不对称错误的字符 [-]imaxbel 发出终端响铃但不刷新字符的完整输入缓冲 [-]inlcr 将换行符转换为回车 [-]inpck 启用输入奇偶性校验 [-]istrip 剥除输入字符的高8 位比特[-]iutf8 假定输入字符都是UTF-8 编码[-]iuclc 将大写字母转换为小写[-]ixany 使得任何字符都会重启输出不仅仅是起始字符 [-]ixoff 启用开始/停止字符传送 [-]ixon 启用XON/XOFF 流控制 [-]parmrk 标记奇偶校验错误 (结合255-0 字符序列) [-]tandem 等于[-]ixoff 输出设置 bsN 退格延迟的风格N 的值为0 至1crN 回车延迟的风格N 的值为0 至3ffN 换页延迟的风格N 的值为0 至1nlN 换行延迟的风格N 的值为0 至1[-]ocrnl 将回车转换为换行符[-]ofdel 使用删除字符代替空字符作填充[-]ofill 延迟时使用字符填充代替定时器同步[-]olcuc 转换小写字母为大写[-]onlcr 将换行符转换为回车[-]onlret 使得换行符的行为表现和回车相同[-]onocr 不在第一列输出回车 [-]opost 后续进程输出tabN 水平制表符延迟的风格N 的值为0 至3tabs 等于tab0-tabs 等于tab3vtN 垂直制表符延迟的风格N 的值为0 至1 本地设置 [-]crterase 擦除字符回显为退格符 crtkill 依照echoprt 和echoe 的设置清除所有行-crtkill 依照echoctl 和echol 的设置清除所有行[-]ctlecho 在头字符中输出控制符号(“^c”) [-]echo 回显输入字符[-]echoctl 等于[-]ctlecho [-]echoe 等于[-]crterase [-]echok 在每清除一个字符后输出一次换行[-]echoke 等于[-]crtkill 意义相同 [-]echonl 即使没有回显任何其它字符也输出换行[-]echoprt 在“和”/之间向后显示擦除的字符 [-]icanon 启用erase、kill、werase 和rprnt 等特殊字符 [-]iexten 允许POSIX 标准以外的特殊字符 [-]isig 启用interrupt、quit和suspend 等特殊字符 [-]noflsh 在interrupt 和 quit 特殊字符后禁止刷新[-]prterase 等于[-]echoprt[-]tostop 中止尝试向终端写入数据的后台任务[-]xcase 和icanon 配合使用用转义符退出大写状态 综合设置 [-]LCASE 等于[-]lcase cbreak 等于-icanon -cbreak 等于icanon cooked 等于brkint ignpar istrip icrnl ixon opost isig icanon eof eol 等的默认值 -cooked 等于-raw crt 等于echoe echoctl echoke dec 等于echoe echoctl echoke -ixany intr ^c erase 0177 kill ^u[-]decctlq 等于[-]ixany ek 清除所有字符将它们回溯为默认值 evenp 等于parenb -parodd cs7 -evenp 等于-parenb cs8[-]lcase 等于xcase iuclc olcuc litout 等于-parenb -istrip -opost cs8 -litout 等于parenb istrip opost cs7 nl 等于-icrnl -onlcr -nl 等于icrnl -inlcr -igncr onlcr -ocrnl -onlret oddp 等于parenb parodd cs7 -oddp 等于-parenb cs8 [-]parity 等于[-]evenp pass8 等于-parenb -istrip cs8 -pass8 等于parenb istrip cs7 raw 等于-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon -xcase min 1 time 0 -raw 等于cooked sane 等于cread -ignbrk brkint -inlcr -igncr icrnl -iutf8 -ixoff -iuclc -ixany imaxbel 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所有特殊字符均 使用默认值 处理连接到标准输入的tty 终端行设置。当不附加参数时程序会输出波特率、行约束 规则以及与标准stty 设置间的偏差。在设置中字符会被逐字读取或是被编码为^c、 0x37、0177 或127 这样的字符其中有特殊值^- 或undef 被用于禁止特殊字符。 1.5.2 microcom命令 1.5.2.1介绍 microcom是一个串口调试指令经常用于串口调试相当于linux自带的串口调试助手 1.5.2.2指令 microcom [-d DELAY] [-t TIMEOUT] [-s SPEED] [-X] TTY参数如下 -d 表示延时时间一般我都不设置。 -t 表示超时时间超多少时间就自动退出。单位为ms -s 表示传输速度波特率的意思这个根据自己的情况而定。 -X 不加 最后指定你的串口设备。如 /dev/ttyO0 , 这是TI的串口设备节点 测试方式如下 将要测试串口与pc端连接在pc端开启串口调试工具波特率设定跟等下microcom设定一样。 使用示例 microcom -s 115200 /dev/ttyUSB21.5.3 echo命令 echo指令可以输出内容到标准输出以空白分割字符串并且后面增加换行。此命令的适用范围RedHat、RHEL、Ubuntu、CentOS、Fedora。 1.5.3.1 语法 echo [-neE] [arg ...]1.5.3.2 选项列表 Linux基础命令echo的使用Linux基础命令echo的使用 1.5.3.3 使用示例 使用“\f”换行 [rootlocalhost ~]# echo -e hello\fworld //必须使用-e选项\f换行之后光标还在结尾helloworld[rootlocalhost ~]# 使用“\n”换行 [rootlocalhost ~]# echo -e hello\nworld //必须使用-e选项\n换行之后光标在开头helloworld输出ascii字符 [rootlocalhost ~]# echo -e \x31 //十六进制的31换算成49代表的ascii字符就是111.5.3.4 e cho 输出重定向 用法echo abc 1.txt 这句话的意思即是输出abc字符串到一个位置如果1.txt存在我们即【清空其1.txt内容更新为abc】不存在创建之 这个过程echo没有像之前那样向终端打印参数为什么 原因是因为输出重定向把echo的参数输出到某个文件而不是输出到终端这就是输出重定向。 1.5.3.5 echo 输出追加重定向 操作符输出追加重定向和输出重定向功能类似。 相同的地方是如果重定向的文件不存在创建之 唯一不同的地方是【如果重定向的文件存在追加之符是清空后新增内容是在文件末尾追加字符串】
http://www.w-s-a.com/news/458534/

相关文章:

  • 做非遗网站的原因wordpress ip 插件
  • 微信企业网站 源码下载wordpress 4.9.5 太卡
  • 湖北网站建设公司哪家好房地产最新政策调整
  • 重庆建设岗位培训网站今天重大新闻乌克兰
  • 流水线 东莞网站建设如何在网上销售产品
  • 哪些做图片赚钱的网站网站建设销售业绩任务
  • 建立网站 知乎如何做网站的图片滑动块
  • 国外做珠宝的网站有哪些滨湖区建设局官方网站
  • 关于中国幼教网站开发的经验中国建设银行晋中分行网站
  • 挪威网站后缀如何外贸网络推广
  • 外汇交易网站开发仟亿家设计软件好吗亿家
  • 专门教做甜品的网站郑州高新区建设环保局网站
  • 建站公司怎么获客网站建设全网营销
  • 黄石做网站的公司html免费网站模板
  • 做个商城网站怎么做便宜优酷视频网站源码
  • 网站侧边栏导航代码泰兴市住房和建设局网站
  • html网站登录界面模板确定建设电子商务网站目的
  • wordpress 多站点迁移三台网站seo
  • 工信部网站备案文件好网站建设公司地址
  • 怎么做app和网站购物网站单页面怎么做的
  • 西宁专业做网站教育网站建设策划书
  • 个人网站域名怎么起网站建设业务好跑吗
  • 网页设计的网网页设计的网站企业网站怎样做优化
  • 论文中小企业的网站建设域名网站空间
  • 宿迁网站建设联系电话现在出入邯郸最新规定
  • 男女做羞羞的事情网站30岁转行做网站编辑
  • 做企业网站的轻量级cmswordpress 越来越慢
  • 无锡中英文网站建设莱芜网络公司
  • ps软件下载官方网站相关搜索优化软件
  • 世界杯网站源码下载做网站推广代理