Hi,
I have a serial device that communicates data at 100000 baud, 2 stop bits and an even parity. When I connect the device to my laptop running windows and configure a data serial port monitor (Docklite) to see the data, I can see a correct data reading (trames of 25 bytes beginning by 0x0F and ending by 0x00)
see SBUS_receiver.png attached picture
When I connect the device to a CPU running QNX6.4.1 and configure the port by a C driver in this way:
[code]int Init_serial_port(int * fd)
{
struct termios termios_p;
// Open the serial port
*fd = open(config.ser_device, O_RDWR | O_NOCTTY | O_NDELAY);
//If the port was successfully opened, configure it
if (*fd != -1)
{
// Get the current port attributes
if(tcgetattr(*fd, &termios_p))
{
printf("Error get\n");
close(*fd);
perr(APL_ERR_IO_ERROR);
return(APL_ERR_IO_ERROR);
}
termios_p.c_cflag |= (CLOCAL | CREAD);
termios_p.c_cflag |= (CSTOPB | PARENB);//set 2 stopbits and paritycheck
termios_p.c_iflag |= INPCK; //set input paritycheck
// Set input and output baud rates
cfsetispeed(&termios_p, config.baudrate);
cfsetospeed(&termios_p, config.baudrate);
// Apply the serial port modifications now
if(tcsetattr(*fd, TCSANOW, &termios_p))
{
printf("Error set\n");
close(*fd);
perr(APL_ERR_IO_ERROR);
return(APL_ERR_IO_ERROR);
}
//flush the serial port
if(tcflush(*fd, TCIOFLUSH))
{
printf("Error flush\n");
close(*fd);
perr(APL_ERR_IO_ERROR);
return(APL_ERR_IO_ERROR);
}
// Get the attributes of the serial port
if(tcgetattr(*fd, &termios_p))
{
printf("Error get\n");
close(*fd);
perr(APL_ERR_IO_ERROR);
return(APL_ERR_IO_ERROR);
}
else
{
printf("c_cflag: %x\n",termios_p.c_cflag);
printf("c_iflag: %x\n",termios_p.c_iflag);
printf("c_ispeed: %i\n",termios_p.c_ispeed);
printf("c_ospeed: %i\n",termios_p.c_ospeed);
printf("**********************************\n");
}
}
printf("Serial port opened correctly\n");
return(0);
}[/code]
Next in my driver, I read the data by those instructions:
while(1)
{
result = read(fd, buffer, 1);
printf("%x ", buffer[0]);
}
When I launch my driver, the reading of the data is wrong as you can see in the console.png picture
when I execute the stty command line on the serial port of the target, I have the following result:
>stty < /dev/ser5
Name: /dev/ser5
Type: serial
Opens: 1
+raw +clocal +imaxbel +onlcr
intr=^C quit=^\ erase=^? kill=^U eof=^D start=^Q stop=^S susp=^Z
lnext=^V min=01 time=00 pr1=^[ pr2=5B left=44 right=43 up=41
down=42 ins=40 del=50 home=48 end=59
par=even bits=8 stopb=2 baud=100000 rows=0,0
GC /uav>
It seems to me that the serial port is correctly configured, isn’t it?