L
laclac01
I need help, i can't figure out why this code doesnt work. I am using
linux.
All i want to be able to do is write some text to an LCD attached to my
serial port on a linux machine. The LCD is serial and I know it works,
baud is 2400 1N8. Attached to com 2.
can someone tell me whats up with this code??
linux.
All i want to be able to do is write some text to an LCD attached to my
serial port on a linux machine. The LCD is serial and I know it works,
baud is 2400 1N8. Attached to com 2.
can someone tell me whats up with this code??
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 */
/* insert the brackets for each include */
int fd;
int open_port()
{
struct termios options;
fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY
);
if (fd == -1)
{
fprintf(stderr, "open_port: Unable to open /dev/ttyS1
- %s\n",
strerror(errno));
}
else
{
fcntl(fd, F_SETFL, FNDELAY );
if ( tcgetattr(fd, &options ) )
{
fputs("fehler\n", stderr); exit (-1);
}
cfsetispeed(&options, B2400);
cfsetospeed(&options, B2400);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_lflag |= (ICANON | ECHO | ECHOE);
//options.c_cflag |= (CLOCAL | CREAD);
//options.c_cflag |= PARENB; /* no parity */
//options.c_cflag |= 0;
//options.c_cflag |= ~CSTOPB;
//options.c_cflag |= CS8; /* 7 data bits */
//options.c_cflag |= CRTSCTS;
/* Enable data to be processed as raw input */
//options.c_lflag &= ~(ICANON | ECHO | ISIG);
/* Set the new options for the port */
if ( tcsetattr( fd, TCSANOW, &options ) )
{
fputs("fehler\n", stderr); exit (-1);
}
}
return (fd);
}
int main()
{
int n=0;
open_port();
n = write( fd, "out_sp_00 25\n", 13 );
if (n < 0)
fputs("Error\n", stderr);
/* Close the serial port */
close(fd);
return 1;
}