From: goza <mik...@na...> - 2012-05-09 15:51:22
|
I'm in serial port hell. I have been trying for days using various examples on the internet to open a serial port for read/write of binary data. I'm trying to connect to a device that wants 8bits, no parity, one stop bit. Very standard stuff. I'm running a Overo Fire and Tobi board. I've got pins 9 & 10 crossed with 21 & 22 to create a null modem. I'm using 2 simple programs. One writes bytes and the other reads and prints every byte that comes in. I'm using a .39 build of linux (if I remember correctly). I seem to be able to write bytes, but I can't read without putting a decimal 13 at the end of the bytes. It won't read without it, but that is only part of the time. I rarely get it to work at all. I am COMPLETELY BAFFLED! This should be easy. Please help me figure out what is wrong. Below is some code to show how I'm opening the file and such... int fdL = open(dev_name,O_RDWR | O_NOCTTY | O_NONBLOCK, 0); fcntl(fdL,F_SETFL,0); struct termios termL; cfmakeraw(&termL); termL.c_cflag |= (CLOCAL | CREAD); cfsetospeed(&termL,B115200); cfsetospeed(&termL,B115200); tcflush(fdL,TCIOFLUSH); tcsetattr(fdL,TCSANOW,&termL); I actually check for errors on each of the calls and I am getting none. I use the same code to open devices /dev/ttyS0 and /dev/ttyS2. I look for available bytes to read using ioctl(fdL,FIONREAD,&num_bytesL); I'm currently reading/writting one byte at a time. I also went into /etc/inittab and commented out the console line that used ttyS2 and set the respawn of ttyS0 and ttyS2 to use 115200 Any help would be greatly appreciated. Thanks, Mike -- View this message in context: http://gumstix.8.n6.nabble.com/Serial-Port-Hell-Please-help-tp4963373.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Paul N. <pa...@id...> - 2012-05-09 16:19:25
|
> I'm in serial port hell. Serial port programming on Linux does seem to be purposefully hellish. Comment out the reading part of your code and see if this prints your output as expected: stty -F /dev/ttyS2 115200 -echo raw cat /dev/ttyS2 & -- Paul Nolan, CEO Idruna Software Inc. |
From: goza <mik...@na...> - 2012-05-09 17:35:59
|
I can give that a try. I assume that is redirecting ttyS2 such that you can see what is being output to that port. Do you have to do anything special to get it back to normal? It's been a while since I did Linux so I'm a little rusty. Thanks, Mike -- View this message in context: http://gumstix.8.n6.nabble.com/Serial-Port-Hell-Please-help-tp4963373p4963654.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Miner, J. W (US SSA) <jon...@ba...> - 2012-05-09 16:28:06
|
> From: goza [mik...@na...] > Sent: Wednesday, May 09, 2012 11:32 > To: gum...@li... > Subject: [Gumstix-users] Serial Port Hell!!! Please help! > > I'm in serial port hell. I have been trying for days using various examples > on the internet to open a serial port for read/write of binary data. Mike - You might want to look at tinyserial as an example. http://www.brokestream.com/tinyserial.html I've used it in various situations when I need a simple serial interface. - Jon |
From: au4life07 <chr...@gm...> - 2012-05-09 17:12:03
|
I had some similar problems to what you described, and I used these two sites to get it working: http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html http://www.easysw.com/~mike/serial/serial.html http://www.easysw.com/~mike/serial/serial.html Unfortunately, I don't have my actual code here with me at work, or I would post that as well. However, if memory serves me right, and it may not, you need to do a "tcgetattr(fdL,&termL);" immediately after the "struct termios termL;". Chris -- View this message in context: http://gumstix.8.n6.nabble.com/Serial-Port-Hell-Please-help-tp4963373p4963588.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: goza <mik...@na...> - 2012-05-09 17:39:25
|
I think I just forgot to put the tcgetattr in the sample code. I had done that in a number of iterations and it didn't seem to help. Thanks for the links. I had tried the second one before, but had not seen the first one. I'll give it a try for non-canonical reading. I think I have tried that version as well, but I've done so many iterations I'm loosing track of what I have tried and not tried. Thanks, Mike -- View this message in context: http://gumstix.8.n6.nabble.com/Serial-Port-Hell-Please-help-tp4963373p4963665.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: goza <mik...@na...> - 2012-05-09 19:19:18
|
Thanks to everyone that helped. I finally found the root of the problem. I used the example code out of http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html for non canonical reading. I then checked the port with the stty function someone suggested which showed me that the stupid console was dumping messages to the screen and trying to log on using the data I was writting to the port even though I commented out the S:......getty ..... line in inittab More surfing and I found that any getty in inittab would cause those messages to write to the port so I commented them all out of inittab. That seemed to do the trick! Now I can read raw data without any problems after rebooting. Thanks again to everyone that pointed me in the right directions! Wish I had asked 3 days ago... MIke -- View this message in context: http://gumstix.8.n6.nabble.com/Serial-Port-Hell-Please-help-tp4963373p4963851.html Sent from the Gumstix mailing list archive at Nabble.com. |