Serial port prgramming in 8.2

Hi all

Please let me know if there is a better place to ask this.

I am porting some propietary software to FreeBSD 8.2. This program communcates via serial port to an external board. It was working fine with 6.2 and 7.2. Now, in 8.2, it stops receiving data after 16 writes. I have a simple test program which writes a 0x80 to the board, and the board ACKs back a 0x2A. Confirmed working with 7.2, 6.2, and Windows. Confirmed not working in 8.2 with two different motherboards. The only thing I changed to update to 8.2 was using cuau0 instead of cuad0.

Did something else change to explain this behavior?

Code and results posted below:

Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>

//#define SERIALPORT "/dev/cuad0"
#define SERIALPORT "/dev/cuau0"

int serial;
struct termios serialConfig;

int main(void)
{
	unsigned char wbuf[32];
	unsigned char rbuf[32];
	int bytes;
	int i;

	serial = open(SERIALPORT,O_RDWR | O_NOCTTY); 
	if (serial < 0)
	{
		printf("Could not open serial port %d",serial);
		return 0;
	}
	memset(&serialConfig,0,sizeof(serialConfig));
	cfmakeraw(&serialConfig);

	serialConfig.c_cflag = B9600;		// 9600 baud
	serialConfig.c_cflag |= CS8;		// 8n1 (8bit,no parity,1 stopbit)
	serialConfig.c_cflag |= CLOCAL;	//local connection, no modem contol
	serialConfig.c_cflag |= CREAD;	// enable receiving characters

	serialConfig.c_iflag = IGNPAR;	// ignore bytes with parity errors
	serialConfig.c_cc[VMIN] = 0;
	serialConfig.c_cc[VTIME] = 10; // in deciseconds

	tcflush(serial,TCIOFLUSH);
	tcsetattr(serial,TCSANOW,&serialConfig);


	wbuf[0] = 0x80; // check board, looking for ACK 0x2A
	for(i=0;i<20;i++)
	{
		printf("i = %d\n",i);

		bytes = write(serial,wbuf,1);
		printf("write 0x%02X\n",wbuf[0]);
		usleep(1000000);

		bytes = read(serial,rbuf,1);
		if(bytes == -1)
			printf("read error %d\n",errno);
		else if (bytes != 1)
			printf("read error %d bytes\n",bytes);
		else
			printf("read 0x%02X\n",rbuf[0]);
	}


	close(serial);
}

Code:
i = 0
write 0x80
read 0x2A
i = 1
write 0x80
read 0x2A
i = 2
write 0x80
read 0x2A
i = 3
write 0x80
read 0x2A
i = 4
write 0x80
read 0x2A
i = 5
write 0x80
read 0x2A
i = 6
write 0x80
read 0x2A
i = 7
write 0x80
read 0x2A
i = 8
write 0x80
read 0x2A
i = 9
write 0x80
read 0x2A
i = 10
write 0x80
read 0x2A
i = 11
write 0x80
read 0x2A
i = 12
write 0x80
read 0x2A
i = 13
write 0x80
read 0x2A
i = 14
write 0x80
read 0x2A
i = 15
write 0x80
read error 0 bytes
i = 16
write 0x80
read error 0 bytes
i = 17
write 0x80
read error 0 bytes
i = 18
write 0x80
read error 0 bytes
i = 19
write 0x80
read error 0 bytes
 
Back
Top