Problem accessing serial port (9600 7-E-1)
Posted on 2006-05-20
I am writing a simple program which is intended to send short strings to a device i have attached to the serial port of my target machine. The simple program i have written seems to achieve this however the external device requires specific settings as follows.
9600 Baud, 7-bit data, 1 start bit, 1 stop bit, even parity.
After reading a number of samples off the web i decided on this code to set the relevant flags...
termio.c_cflag = B9600 | CS7 | PARENB | CLOCAL | CREAD;
tcsetattr(ttys0_fd, TCSANOW, &termio);
I have tried every combination of c_flag settings that made sense from what i read but every time tcsetattr() is called with the specific settings the serial port seems to stop working all together and next time the program runs it cant even access the port.
When i let the program run with whatever default settings exist, i can send and receive strings no problem. What am i doing wrong? This has taken far longer than i had anticipated :(
Thanks in advance. Ill post the entire code if necessary.