漆黑之幻影奇袭 漆黑之幻影奇袭
关注数: 81 粉丝数: 101 发帖数: 3,508 关注贴吧数: 79
树莓派用php syetem()调用串口发出信息失败 使用apache2绝对路径调用,所调用c程序: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <errno.h> #include <string.h> #define TRUE 0 #define FALSE -1 int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300, }; int name_arr[] = {38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300, }; void set_speed(int fd, int speed){ int i; int status; struct termios Opt; tcgetattr(fd, &Opt); for( i= 0; i < sizeof(speed_arr) / sizeof(int); i++){ if(speed == name_arr[i]){ tcflush(fd, TCIOFLUSH); cfsetispeed(&Opt, speed_arr[i]); cfsetospeed(&Opt, speed_arr[i]); status = tcsetattr(fd, TCSANOW, &Opt); if (status != 0) perror("tcsetattr fd1"); return; } tcflush(fd,TCIOFLUSH); } } /** *@brief 设置串口数据位,停止位和效验位 *@param fd 类型 int 打开的串口文件句柄* *@param databits 类型 int 数据位 取值 为 7 或者8* *@param stopbits 类型 int 停止位 取值为 1 或者2* *@param parity 类型 int 效验类型 取值为N,E,O,,S */ int set_Parity(int fd,int databits,int stopbits,int parity){ struct termios options; if( tcgetattr( fd,&options) != 0){ perror("SetupSerial 1"); return FALSE; } options.c_cflag &= ~CSIZE; switch (databits){ /*设置数据位数*/ case 7: options.c_cflag |= CS7;break; case 8:options.c_cflag |= CS8;break; default:fprintf(stderr,"Unsupported data sizen");return FALSE; } switch (parity){ case 'n': case 'N': options.c_cflag &= ~PARENB; /* Clear parity enable */ options.c_iflag &= ~INPCK; /* Enable parity checking */ break; case 'o': case 'O': options.c_cflag |= (PARODD | PARENB); /* 设置为奇效验*/ options.c_iflag |= INPCK; /* Disnable parity checking */ break; case 'e': case 'E': options.c_cflag |= PARENB; /* Enable parity */ options.c_cflag &= ~PARODD; /* 转换为偶效验*/ options.c_iflag |= INPCK; /* Disnable parity checking */ break; case 'S': case 's': /*as no parity*/ options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; break; default: fprintf(stderr,"Unsupported parityn"); return (FALSE); } /* 设置停止位*/ switch (stopbits){ case 1: options.c_cflag &= ~CSTOPB; break; case 2: options.c_cflag |= CSTOPB; break; default: fprintf(stderr,"Unsupported stop bitsn"); return FALSE; } /* Set input parity option */ if (parity != 'n') options.c_iflag |= INPCK; options.c_cc[VTIME] = 150; // 15 seconds options.c_cc[VMIN] = 0; tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */ if(tcsetattr(fd,TCSANOW,&options) != 0){ perror("SetupSerial 3"); return FALSE; } return TRUE; } int OpenPort(char *Dev){ intfd = open( Dev, O_RDWR ); //| O_NOCTTY | O_NDELAY if (-1 == fd){ /*设置数据位数*/ perror("Can't Open Serial Port20"); return -1; }else{ return fd; } } int main(int argc, char **argv){ int fd; int nread; char buff[512]; char *dev = "/dev/ttyAMA0"; fd = OpenPort(dev); if(fd>0){ set_speed(fd,9600); }else{ printf("Can't Open Serial Port!10n"); exit(0); } if(set_Parity(fd,8,1,'N')== FALSE){ printf("Set Parity Errorn"); exit(1); } strcpy(buff,"20001"); int length = strlen(buff); write(fd,buff,length); memset(buff,0,512); close(fd); exit(0); }
[转]不就差一点吗 觉得上班走路有点累,想去买辆自行车,结果去了一看,要2500块。旁边的人说,2500都掏了不如加点钱买辆电动。遂问电动车价格,3500,决定买。却被告知不如加点钱买小踏板摩托划算。于是看摩托车,4000,决定买。又被告知说小踏板不安全,不如买大摩托。于是再看。大摩托要6000,决定买。挑来挑去,发现看上眼的居然靠近1w。不料听说1w可以买个二手车。于是改作买车。挑来挑去,二手捷达要将近3w,决定买。可是隔壁奇瑞的说3w可以买他们的新车了。遂改买奇瑞。上去一坐,有点挤,不要紧。加钱换A3,觉得车子矮。又去看瑞虎。下来一算10w多。不如不买奇瑞买合资的。看上polo。被告知简配。去订高尔夫。人说加价。一咬牙,决定买CRV。反正和高尔夫价格差不多。结果听说途观好像也是那个价格左右。遂去看途观。不料看中了新passat。决定买。一算价格,似乎可以买奥迪,于是又反悔去看奥迪a4。结果路过宝马4s店看到了3系,遂改选3系。前前后后看完决定买时一算,要30w左右。不禁又想买suv车型。于是到了隔壁雪佛兰去看科帕奇,看完觉得牛逼想买。门口却开过一辆jeep指南者。一问价格差不多。改!去jeep店,快订车时碰到熟人。看熟人开着福特锐界,眼红要买。去了一问,40w,ok!准备掏钱。又一想,妈的都40w花了。不如加点钱一步到位买路虎?于是去看极光。对外形满意,决定买。咨询单位司机,被告知越野性能不如普拉多,价格只差9w。好!买普拉多!去丰田。看了普拉多觉得丑,妈的咬牙买兰德酷路泽,最后100多w。我靠,不买suv了。买宝马7!………一番折腾。最终买了辆劳斯莱斯。提车,开心的不得了!上去一坐才想起来,驾照没学!妈的,我是来买自行车的
吃货们都进来吧,黯然神伤 回锅肉一直被认为是川菜之首,但昨日网络上的一则消息,却让广大“吃货”黯然神伤:最适合做回锅肉的猪种成华猪,已经濒临灭绝。 昨日,华西都市报记者从成都市农委获悉,由于生长周期长、养殖期耗料高等原因,目前市面上的成华猪几乎绝迹,“数量比熊猫还少”。为此,成都将投资2000余万元建成华猪保种场,通过各种办法保护、推广成华猪。成华猪濒临灭绝,这绝对不只伤吃货的心-,在众多川菜大师眼里,做出最正宗的回锅肉须选用四川土猪成华猪。对于诸位吃货来说、眼睁睁看着最爱的回锅肉面临濒临灭绝的处境,绝对令人伤心欲绝。可一向心宽体胖、生育能力超强的猪怎么也会和大熊猫一样,面临灭绝的命运? 网友热议:   商隐俊:连繁殖率超高的猪都要灭绝了。是吃货太多,还是蠢货太多?   chenleizzray:这么威猛的猪都要灭绝了。   hgfgf:繁殖能力那么强也会灭绝?   张艳大使:原来连猪都可以灭绝~原来猪在中国也活得不容易啊。   elina小么:濒临灭绝也没有成国家保护动物?   长会网站:我们再也吃不到回锅肉了吗?   桂树榕树:文化侵略不算,现在连种猪也要侵略了吗?为了吃货国的回锅肉,坚决保护中国种猪,抵御外来猪!二师兄,是你站出来的时候了!大师兄,八戒家的事,这回你管是不管?
1 下一页