#include <stdio.h> #include <string.h> #include <fcntl.h> #include <termios.h> #include <stdlib.h> #include <unistd.h> #include <time.h> int main(){ FILE *fd; struct termios options; fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY); if(fd){ //fcntl(fd,F_SETFL,0); printf("port opening successful %d .file description is\n",fd); }else{ perror("Open port failded"); } //serial configure /*tcgetattr(fd,&options); cfsetispeed(&options,B9600); cfsetospeed(&options,B9600); options.c_cflag &= _CSIZE; options.c_cflag &= _CS8; options.c_cflag &= _PARENB; */ int rr,r,w; char buf[255]; printf("Writing\r\n"); w = write(fd,"AT\n",16); printf("unsleeping\r\n"); usleep(100000); printf("Reading\r\n"); r=read(fd,buf,6); printf("Read\r\n"); if(r>0){ printf("Data: %s \r\n",buf); } close(fd); printf("Hello world \n"); return 0; }</time.h></unistd.h></stdlib.h></termios.h></fcntl.h></string.h></stdio.h>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)