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

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

Post by optipl » Sun, 07 Apr 2002 04:16:56



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.
 
 
 

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

Post by Grant Edwar » Sun, 07 Apr 2002 04:50:35


The same article in at least 3 different newsgroups.  

Don't do that.

--
Grant Edwards                   grante             Yow!  When you get your
                                  at               PH.D. will you get able to
                               visi.com            work at BURGER KING?

 
 
 

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

Post by Eric P. McC » Sun, 07 Apr 2002 05:30:13



> I am currently writing a program under Linux which needs to
> communicate to the serial port.

Stop multiposting.  I answered you in cold.apps.

In case that's not bad enough, your question has nothing to do with
Linux system development.  Go away.

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj

 
 
 

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

Post by el.. » Sun, 07 Apr 2002 15:16:05




>  // Set the speed and other if req
>  system("stty 2400 </dev/ttyS0");

That's not how to program a serial port.  Have you looked
at the serial programming howto?

--
http://www.spinics.net/linux/

 
 
 

1. 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. executable stacks and buffer overflows?

3. problem w/ broadcom wireless card 4319 rev 2 ...

4. awk in vi on Redhat 5

5. Serial Hayes Accura v.92

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

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