RS232 Settings

I am migrating one of my Win 32 apps to a Kubuntu server. The Windows app uses the following comm port settings:

DTREnable = TRUE
EOFEnable = TRUE
Handshaking = XONXOFF
InBufferSize = 4800
InputLength = 1
NullDiscard = TRUE
OutBufferSize = 80
ParityReplace = "?"
RThreshold = 1
RTSEnable = TRUE
BAUD = 1200
Parity = N
Data Bits = 8
Stop Bits = 2
SThreshold = 1

I am having a difficult time getting data from my RS232 device using C++. I am new to C++, so I am not sure what I am missing. Here is my code so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

int main()
{
//CONFIGURE COMM PORT
int CommPort;
struct termios oldtio, newtio;
char TheBuffer[4800];
char *TheCharacter;
int nbytes;

CommPort = open(MODEMDEVICE, O_RDONLY | O_NOCTTY | O_NDELAY);

if (CommPort <0) {perror(MODEMDEVICE); exit(-1); }

tcgetattr(CommPort,&oldtio); /* save current serial port settings */

//set baud rate
cfsetispeed(&newtio, B1200);
cfsetospeed(&newtio, B1200);

//8N2
newtio.c_cflag &= ~PARENB;
newtio.c_cflag |= CSTOPB;
newtio.c_cflag &= ~CSIZE; /* Mask the character size bits */
newtio.c_cflag |= CS8;    /* Select 8 data bits */
//enable flow control when using 8N2
newtio.c_cflag |= CRTSCTS;
//
newtio.c_iflag |= (IXON | IXOFF | IXANY);
//processed output
newtio.c_oflag |= OPOST;
newtio.c_oflag |= ONLCR;

newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character arrives */
newtio.c_cc[VSTART]   = 17;     /* Ctrl-q XON*/
newtio.c_cc[VSTOP]    = 19;     /* Ctrl-s XOFF*/

tcsetattr(CommPort,TCSANOW,&newtio);
/*The FNDELAY option causes the read function to return 0 if no characters are available on the port.*/
fcntl(CommPort, F_SETFL, FNDELAY);
ioctl (CommPort, FIONREAD, &nbytes); //get size of buffer waiting to be read
cout << "Buffer Size: " << nbytes << endl;
TheCharacter = TheBuffer;
while ((nbytes = read(CommPort, TheCharacter, TheBuffer + sizeof(TheBuffer) - TheCharacter - 1)) > 0)
  {
    TheCharacter += nbytes;
  }
cout << "\nTheCharacter: " << TheCharacter << endl;
close(CommPort);
return (CommPort);
}


My output is:

Buffer Size: 0

TheCharacter:

In case it helps or matters, the RS232 device is the SMDR port of an AVAYA Partner ACS. My USB to RS232 adapter appears to have installed correctly in Kubuntu - no error for /dev/ttyUSB0. My cabling and adapter is the same as that used by my VB app in windows.

What am I missing?
Topic archived. No new replies allowed.