serial port programming

ppartikian_at_yahoo.com
Date: 01/31/05


Date: 31 Jan 2005 10:22:35 -0800


All,

I wrote a program doing serial communication via RS422 port /dev/tty4d2
off an Octane2 SGI.
I receive data fine. But, when I am sending data, for some reason what
I send is not always what is received.
I print out the cmd before sending and it always seems correct, but it
does not reach correctly.
Here are snippets of the code I have written with my configuration. Am
I setting the output configuration correctly?
Any help would be greatly appreciated.

_newSettings.c_iflag &= ~(IXON | IXANY | IXOFF);
_newSettings.c_iflag &= ~(BRKINT | IGNPAR | ICRNL | IUCLC);
_newSettings.c_iflag &= ~ISTRIP;

_newSettings.c_oflag &= ~OPOST;
_newSettings.c_oflag |= 0;
_newSettings.c_oflag &= ~(ONLCR | TAB3);

_newSettings.c_cflag |= CREAD;
_newSettings.c_cflag |= CLOCAL;
_newSettings.c_cflag |= CS8;
_newSettings.c_cflag &= ~CSTOPB;
_newSettings.c_cflag |= (PARENB | PARODD); //odd parity

_newSettings.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOE);

_newSettings.c_ospeed = 38400;
_newSettings.c_ispeed = 38400;

_newSettings.c_cc[VMIN] = 0;
_newSettings.c_cc[VTIME] = 0;

if (tcsetattr(_portFd, TCSANOW, &_newSettings) == -1)
{
cout << "we have problem";
cout << endl;
}

struct strioctl str;
int arg = 0;
arg = RS422_ON;
str.ic_timout = 0;
str.ic_len = 4;
str.ic_dp = (char *)&arg;
str.ic_cmd = SIOC_RS422;

if (ioctl(_port, I_STR, &str) < 0)
{
cout << "we have problem setting to rs422" << endl;
}

if (tcflush(_port, TCIFLUSH) == -1)
{
cout << "error flushing old data" << endl;
}

//now we do other stuff

Thanks in advance,
Patrick