From: James L. <ja...@ti...> - 2012-05-09 23:51:10
|
On 10/05/2012, at 1:12 AM, gum...@li... wrote: > 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. Check the settings that you have got by: stty -a </dev/ttyWHATEVER I must say VT to output looks strange. I set everything in the termios structure not with ioctls but everything seems to work ok. Mail me and I'll drop you some code that works for me. OH BTW I do not think the serial is bizare or hard (purposefully hellish) James |