Serial port communication - Need help!!!

Serial port communication - Need help!!!

Post by optipl » Sun, 07 Apr 2002 04:22:47



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);

Quote:}

Any help would be appreciated. Thank you.
 
 
 

1. Linux serial port communication - Need help!!!!!!!!!

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.

2. How to monitor online status?

3. Serial port communication - Need help!!!

4. Getting Linux to recognize >64 MB of memory

5. Kernel crash : no driver for PCI SIS 5107

6. NIS server on Solaris 2.1?

7. How to set up serial port when programming serial communication

8. Help with Serial port Communications on DSR/DTR lines