I am currently writing a program under Linux which needs to
communicate to
the serial port. All the program needs to do is send a string of 0's
and
1's. I'd like for these values to represent a low and a high when
being
outputted to the serial port, instead of the ascii integer value of
'0'
and '1'. It appears that my simple program outputs the ascii integer
value of the string being passed out, but that is not what I want it
to
do. All I want it to do is pass out a high when it sees a 1, and a low
it sees
a 0.
I was hoping someone has had experience with this in the past and will
be willing to help me out on this.
My simple program is below:
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
int main()
{
int fd;
// Open the port
fd = open("/dev/ttyS0", O_WRONLY);
// Set the speed and other if req
system("stty 2400 </dev/ttyS0");
// There is a better way than this
if(fd == -1)
{
perror("open");
exit(1);
}
// Send a message
if(write(fd, "0", 10) == 10)
{
perror("write");
exit(1);
}
close(fd);
Any help would be appreciated. Thank you.Quote:}