Hi, I am using a Mini2440 board running Qtopia OS. I want to use with it a GPS receiver for navigation purposes. The GPS receiver comes with a serial interface, hence I have been trying to write a code to receive data from one of its serial ports. The code attached here is supposed to send some data from the tx of a port and read that data from the rx of the same port. I cross compile this code, run in my board and get this output - Attempting That's it. The serial port becomes unresponsive after this. Can anyone tell me what could be wrong with my code? Thank you.
Need help in serial port interfacing
To run thttpd with PHP and access the serial port using php_serial.class.php I have to place this in my /etc/profile.environment file: chmod 666 /dev/ttySAC1 Curious why you only get "Attempting" rather than "Attempting to open serial port"? HTH davef
@davef Did you try the code? Are you getting the proper output? Or at least the full string "Attempting to open serial port"?
Tarin, I haven't run your code. I would suggest a simple printf statement only containing the phrase "Attempting to open serial port" and see if that works. Perhaps, printf is falling over. Dave
1) which serial port are you using line 26: const char *device = "/dev/ttySAC2"; line 35: perror("open_port: Unable to open /dev/ttySAC1 - ") 2) Is this source really the base of your program? serial.c:15:6: warning: return type of 'main' is not 'int' serial.c: In function 'main': serial.c:18:2: warning: implicit declaration of function 'open_port' serial.c: In function 'open_port': serial.c:27:17: warning: unused variable 'out' serial.c:27:9: warning: unused variable 'sd' serial.c:84:1: warning: control reaches end of non-void function serial.c:78:10: warning: 'in' may be used uninitialized in this function 3) did you check if the serial port is not used by another program in your Qtopia environment 4) How did you connect your GPS receiver electrically to the serial ports (ttySAC1 or ttySAC2)?
@Dave I have tried running a code with only printf. And it works properly. The problem lies somewhere in the serial part of the code. @Juergen Beisert 1) which serial port are you using line 26: const char *device = "/dev/ttySAC2"; line 35: perror("open_port: Unable to open /dev/ttySAC1 - ") Line 35 doesn't matter. Its just a print statement. There are 3 port drivers in my board - ttySAC0,1,2. I tried all the three and none of them is working. Also, don't look at those warnings. I keep commenting/uncommenting various parts of my code while debugging, so those warnings are just due to that. 1 of the 3 ports is being used in connecting my board to my pc but the other 2 ports must be free. And I tried all the 3 ports in the code and none of them is working. I didn't connect my GPS receiver yet. As I have already mentioned in my first post, I was trying to send data from the tx of a port and receive data from the tx of the same. I was thinking planning on shorting their rx tx pins to check the output. But since the code is not running in the first place, I didn't do the shorting part.
Your program works as expected if I comment out the stdio manipulations. $ /usr/bin/serial Attempting to open serial port In open_port read = 34968 read = 34968 read = 34968 read = 34968 Your stdio manipulation is completely broken, even the strace command cannot help, because your manipulation forces a logout.
I just commenting out this block in your file (in open_port() ): [...] #if 0 memset(&stdio,0,sizeof(stdio)); stdio.c_iflag=0; stdio.c_oflag=0; stdio.c_cflag=0; stdio.c_lflag=0; stdio.c_cc[VMIN]=1; stdio.c_cc[VTIME]=0; tcsetattr(STDOUT_FILENO,TCSANOW,&stdio); tcsetattr(STDOUT_FILENO,TCSAFLUSH,&stdio); fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) #endif [...] This manipulation will confuse the system. On my Mini2440 is forces a logout.
Ohh but that fails my purpose of writing from the port. Now the code can only read. I referred to this http://en.wikibooks.org/wiki/Serial_Programming/termios#Example_terminal... while writing the code. And according to the wiki, it should work. What do you could be the reason that it's confusing the system and forcing it to logout or behave weird?
But you do a "read(fd,&input,1)" and "write(fd,&input,1);" on your serial port. You should extend your program using select() to wait for chars.