Results 1 to 2 of 2
I am trying to make a program that sends "1" through /dev/ttyUSB0 port and then 10 seconds later sends "q" through /dev/ttyUSB0.
The program works, however it only runs if ...
- 12-01-2009 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 2
How to configure tty port in C?
I am trying to make a program that sends "1" through /dev/ttyUSB0 port and then 10 seconds later sends "q" through /dev/ttyUSB0.
The program works, however it only runs if I have a putty terminal open with the correct baud rate.
I am assuming that putty somehow opens and sets the baud rate for the port correctly. I am also assuming that I somehow need to make my program do the same, the problem is I have no idea how to do this.
Here is what I have so far:
Code:#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <unistd.h> int fd1; int fd2; char tempchar = '1'; const void* buf = &tempchar; char tempcharq = 'q'; const void* bufq = &tempcharq; char *buff,*buffer,*bufptr; int wr,rd,nbytes,tries; int main() { fd1=open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd1 == -1 ) { perror("open_port: Unable to open /dev/ttyUSB1 – "); } else { fcntl(fd1, F_SETFL,0); printf("Port has been sucessfully opened and %d is the file description\n",fd1); } wr=write(fd1, buf, 1); sleep(10); wr=write(fd1, bufq, 1); //wr=write(fd1, "ATZ\r",4); //rd=read(fd1,buff,1); //printf("bytes sent are %d \n", rd); close(fd1); return 0; }
- 12-02-2009 #2


Reply With Quote