I need to implement a specific protocol over a serial device. I have already done the message contructor and have a list of bytes ready to be send. The issue that I am having is that I am not able to verify if I am correctly sending the bytes into the /dev/ttyS2
interface. My serial messages follow the structure PATTERN + MESSAGE
I am able to read from the serial device and filter some received known messages by doing:
cat /dev/ttyS2 | grep PATTERN
In my program (code below), if I send my message I amb not able to see my frames using the previous command:
static FILE * file_stream = NULL;
static int file_des = 0;
static void printSampleMessage(void) {
struct termios SerialPortSettings; /* Create the structure */
/* Open linux device */
file_des = open("/dev/ttyS2", O_RDWR | O_NOCTTY);
/*---------- Setting the Attributes of the serial port using termios structure --------- */
tcgetattr(file_des, &SerialPortSettings); /* Get the current attributes of the Serial port */
/* Setting the Baud rate */
cfsetispeed(&SerialPortSettings,B38400); /* Set Read Speed as 38400 */
cfsetospeed(&SerialPortSettings,B38400); /* Set Write Speed as 38400 */
/* 8N1 Mode */
SerialPortSettings.c_cflag &= ~PARENB; /* Disables the Parity Enable bit(PARENB),So No Parity */
SerialPortSettings.c_cflag &= ~CSTOPB; /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the mask for setting the data size */
SerialPortSettings.c_cflag |= CS8; /* Set the data bits = 8 */
SerialPortSettings.c_cflag &= ~CRTSCTS; /* No Hardware flow Control */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines */
SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY); /* Disable XON/XOFF flow control both i/p and o/p */
SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Non Cannonical mode */
SerialPortSettings.c_oflag &= ~OPOST; /*No Output Processing RAW mode*/
if((tcsetattr(file_des,TCSANOW,&SerialPortSettings)) != 0) {/* Set the attributes to the termios structure*/
} else {
}
/* Obtain file stream descriptor */
file_stream = fdopen(file_des, "r+");
fputs ( "PATTERN+MESSAGE", file_stream);
}
However, I am not able to see my own message when using the cat /dev/ttyS2 | grep PATTERN
command. How can I check if I am actually sending my PATTERN+ message in the serial device?
I am quite limited in terms of program options. My setup is an embedded linux communicating with another microcontroller within a board (no test point to connect a physical sniffer) and no minicom available as the linux distribution I am using is very basic, I can not just apt-get install XX