/* file: hello.c */ #include <stdio.h> int main() { puts("Hello, world"); return 0; }
$ gcc -Wall -o hello hello.c
#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include int main() { int fd1; int fd2; char *buff,*buffer,*bufptr; int wr,rd,nbytes,tries; //beg0 added: Allocation memoire necessaire buff=(char*)calloc(sizeof(char), 10+1); //Next step, we connect to device through associated file and check the connection: fd1 = open(“/dev/ttyS0″, O_RDWR | O_NOCTTY | O_NDELAY); if (fd1 == -1 ) { perror(“open_port: Unable to open /dev/ttyS0 – “); } else { fcntl(fd1, F_SETFL,0); printf(“Port 1 has been sucessfully opened and %d is the file description\n”,fd1); } //Where, “/dev/ttyS0” is associated with COM1 port. //With following code we send to device some bits: wr=write(fd1,”ATZ\r”,4); //And for reading response from device: rd=read(fd1,buff,10); printf(“Bytes sent are %d \n”,rd); //At the end, close the connection: close(fd1); //Beg0 added: Liberation de la memoire allouée free(buff); return 0; }
#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include int fd1; int fd2; char *buff,*buffer,*bufptr; int wr,rd,nbytes,tries; int main() { return 0; } //Next step, we connect to device through associated file and check the connection: fd1 = open(“/dev/ttyS0″, O_RDWR | O_NOCTTY | O_NDELAY); if (fd1 == -1 ) { perror(“open_port: Unable to open /dev/ttyS0 – “); } else { fcntl(fd1, F_SETFL,0); printf(“Port 1 has been sucessfully opened and %d is the file description\n”,fd1); } //Where, “/dev/ttyS0” is associated with COM1 port. //With following code we send to device some bits: wr=write(fd1,”ATZ\r”,4); //And for reading response from device: rd=read(fd1,buff,10); printf(“Bytes sent are %d \n”,rd); //At the end, close the connection: close(fd1);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question