We are trying to interface one of our devices with our machines by having the device send a file over the serial port. The code for the external device is written in C. However, we have not been able to successfully compile any of our code to do this. This is one of the code snippets we used to try to open the serial port and send data:
Code:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
/*
* 'open_port()' - Open serial port 1.
*
* Returns the file descriptor on success or -1 on error.
*/
int
open_port(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);
return (fd);
}
Source: Serial Programming Guide for POSIX Operating Systems - Michael R Sweet
However, when we try to compile this code, we get an error that O_NDELAY is an undeclared variable. We think it has something to do with termios.h, but we have not been able to fix this. We also tried using FileOutputStream.h (Source: fileoutputstream.c File Reference) but we got a file not found error. Can someone point us in the right direction here?
Thanks.